A2v10 Platform documentation
UK


Controller

The controller is responsible for the interaction between the model and the view. Any data object has a $ctrl property that returns a reference to the current controller. The controller is a regular JavaScript object that implements the following interface:


Controller methods

$invoke(command: string, arg: object, path?: string, opts?: { catchError: boolean }): Promise

Calls a server command.

Arguments:

  • command - the name of the server command (from the commands section of the model.json) file.
  • arg - an arbitrary argument object. The Properties of this object will be the arguments to the command.
  • path? - optional. URL for the endpoint. If not specified, will be executed at the current endpoint.
  • opts - options object. In the current version, it contains a single property, catchError. If it is set, then when errors occur, the promise will be canceled and the error can be caught in the code using the catch method (or in the try... catch statement for async ... await) of the promise). By default, the system just displays an error message and does not execute the promise.

Returns:

  • Promise.
$reload(array?:object[]): Promise<void>

Updates a model or its part.

Arguments:

If an argument is specified, then the data of the lazy array is updated, otherwise, the data of the entire model is updated. Some Properties of a model can be "protected" from being updated using the bindOnce template option.

$msg(msg:string, title?:string, style?:string): Promise<object>

The method displays a message in a modal window.

Arguments:

  • msg - the message text. May include html markup.
  • title - the title of the message box. By default: the "Сообщение" string (in the current localization).
  • {Enum:['info', 'alert', 'confirm']} style - style. By default: 'info'.

Returns:

  • Promise<any> which will be executed after the window is closed.

The buttons that will be placed in the window depend on the message style.

$asyncValid(command: string, arg: object): any | Promise

Performs an asynchronous check. To do this, it calls a command on the server, passing it the specified arguments. The command is always executed at the current endpoint.

Please note that the results of this command can be cached to prevent unnecessary server calls.

Arguments:

  • command - the name of the server command (from the commands section of the model.json file.
  • arg - an arbitrary argument object. The Properties of this object will be the arguments to the command.

Returns:

$saveModified(message?:string, title?:string):boolean

Checks if the model has changed and displays a message indicating that the model needs to be saved.

Arguments:

  • message - message. If not specified (undefined), the default message "Item has been changed. Save changes?" (in the current localization).
  • title - the title of the message box. If not specified (undefined), the standard "Close Confirmation" header (in the current localization) will be used.

Returns:

  • true - if the object has not been modified ($isDirty = false), false otherwise.

Description:

If the data model has not changed, then the method simply returns true, if it has changed, it displays a close confirmation dialog with three buttons "Save", "Do not save" and "Cancel" (in the current localization) and returns false.

After the user makes a selection, the controller will perform the desired action (for example, save the model) and close the current window.

The most common use of this method is in the CanCloseDelegate delegate of the Dialog object.

$setFilter(target:object, prop:string, value:any): void

Description

Because filters interact very closely with markup and system behavior, you cannot simply set the filter value from code. To do this, you need to use the $setFilter method. After setting the value, the system will perform all the necessary actions, update the interface, execute server requests, etc.

Arguments:

  • target - the object for which it is necessary to set the filter.
  • prop - the name of the filter item property.
  • value - the new value.
$inlineOpen(id:string): void

Opens an inline dialog (InlineDialog).

Arguments:

  • id - dialog ID.

The built-in dialog has full access to the current model. Behavior management falls entirely upon the programmer.

$inlineClose(id:string, result: any): void

Closes an inline dialog (InlineDialog).

Arguments:

  • id - dialog ID.
  • result - reserved. Not used in the current version.
$focus(htmlid: string): void

Sets the cursor to an element with the given htmlid.

Arguments:

  • htmlid - item ID (can be set using the HtmlId property of the UIElementBase object).