Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The new modern Akioma Swat Client Logic API (CLACLAPI).

The CLA CLAPI includes the following features among others -

  • ObjectStrong object-Oriented oriented design.
  • Compile-time checking.
  • Intellisense and documentation.
  • Simplified design over previous versions.

TypeScript

The CLA CLAPI is written in TypeScript which allows for compile-time checking and intellisense, among others.

TypeScript is a superset of JavaScript which mainly adds optional typing. JavaScript code is also valid TypeScript code (although it depends on the compiler settings).

TypeScript compiles (or transpiles) to plain JavaScript. The compiled JavaScript code looks almost exactly the same as the TypeScript source code without the typings (when compiling to ES6 and beyond).

...

https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html

Visual Studio Code

In the following examples we will be using Visual Studio Code.

...

To install a portable version follow the link below (if you are having permissions issues installing VS Code) -

https://code.visualstudio.com/docs/?dv=winzip

...

https://code.visualstudio.com/docs/getstarted/introvideos

Migrating to the

...

CLAPI

In the following example we will migrate a function to the CLACLAPI. The function gets the foreign keys (or initial field values) when launching a window to create a new record.

In the Sports Sample Application, open the Customers desktop window. Click the New Order button in the Customer Grid Floating Action Button (FAB) (see picture below).

Calling

...

CLAPI Functions

You can pass several system objects to a function call written in the Layout Designer or the Smart Component Library (SCL) Maintenance (starting with "$") -

  • self - The repository object called dynObject for the event.
  • oSelf - The widget object called controller for the event.
  • eventSource - The CLA CLAPI object for the event.

The CLA CLAPI replaces the dynObject and controller objects with a single eventSource object for the Object Type. Use the eventSource object for CLA CLAPI function calls.

All the Object Types in Swat, in the SCL Maintenance have equivalent CLA TypeScript CLAPI classes (except for a few exceptions).

Open the SCL Maintenance for the Sports Sample Application. Open the "New Customer Order" Menu Function in the Menu Function Maintenance. Replace "self" with "eventSource" in the Action Options field and save (see picture below).

Writing

...

CLAPI Functions

Open the /sports-webui/ClientLogic/ folder in VS Code. Open Order/getOrderForeignKeys.js from the Explorer view (see picture below).

...

  1. Replace 

    if (akioma.samples)
    akioma.samples = {};
    akioma.samples.getOrderForeignKeys = function(self) {

    With

    namespace akioma.samples {
        export function getOrderForeignKeys(self) { 

    Use namespaces to avoid naming conflicts. Note that functions must be exported to be used outside the namespace (namespaces are compiled into closures).

  2. Replace self with eventSource: akioma.swat.SwatObject.

    Note that the function parameter name does not have to be eventSource. For example: eventGrid eventForm, eventRibbon etc. Although self might be confusing with the JavaScript dynObject.

    Note that the function parameter type does not have to be the generic base SwatObject as in this case. Use the correct Object Type class to avoid casting.

  3. Replace getObject("CustomerDetailsForm") with getForm("CustomerDetailsForm")getObject("CustomerGrid") with getGrid("CustomerGrid") and container with window.

    The CLA CLAPI supports generic traversing functions like getObject(), getLink() etc. which return the generic base SwatObject class object.

    The CLA CLAPI also supports type specific function like getForm(), getGrid(), getRibbon() etc. to avoid casting.

    Alternatively you can use TypeScript casting. For example: (eventSource.getObject("MyObjectMyForm") as akioma.swat.Form).

  4. Replace getValue with getDataValue.

    The Form and Grid classes have both a getScreenValue() and getDataValue() functions for getting the field screen value or record value respectively.

    Save (Ctrl-S) and rename (F2) the file as Order/getOrderForeignKeys.ts using the .ts TypeScript file extension (see picture below).

Documentation

In addition to the intellisense of the class methods, properties and their explanations

...

https://<your environment domain>/docs2

Calling JavaScript functions from TypeScript

There are cases where you might need to call JavaScript functions and objects you have created or global framework functions and objects that have not yet been migrated to TypeScript in the CLAfrom CLAPI functions.

The problem is that JavaScript functions and objects have no type declaration so they cannot be called from TypeScript.

For cases like these where the type is unknown TypeScript has provides the type any to opt-out of type checking and pass through bypass compile-time checkschecking.

To call global functions and objects, the CLA added .akioma, .app and .dhtmlx, .$ etc. properties with type any to the global Window type declaration.

For example, the JavaScript code: akioma.sports.myFunction() is equivalent to the CLA CLAPI TypeScript code: window.akioma.sports.myFunction() (note the window global object in the beginning).

To call dynObject and controller functions and properties, the CLA CLAPI added .dynObject and .controller properties also with type any to the base SwatObject.

For example: The JavaScript code: self.myProperty is equivalent to the CLA CLAPI TypeScript code: eventSource.dynObject.myProperty.

Compiling Client Logic API Functions

Open the swat-webui/akioma/sass/ directory in the command line interface. Type npm run sports and press Enter (see picture below).

...

Note that for the changes to take effect you will need to do a hard refresh on the web page (Ctrl-F5).

If you still cannot see the changes after doing a hard refresh, try opening a new incognito window.

Note that other environments may have their own custom build and watch scripts that watch for file changes and launch the build scripts automatically.

Debugging Client Logic API Functions

You can view and debug your TypeScript source code using source maps.

...