Class: AuWidgetAjax

A non-visual widget that is used to send requests to the server and receive responses, which can be used in other widgets.

For details, see the Ajax widget topic.

The following example illustrates how you can populate a gallery with images obtained through an HTTP request.

{
  "widgets": [
   {
     "name": "bg-request",
     "type": "ajax",
     "params": {
       "lock": "gallery",
       "url": "{{vars.apiUrl + '/api/images?subfolder=backgrounds'}}",
       "method": "GET",
       "responseType": "json"
     }
   },
   {
     "name": "gallery",
     "title": "Gallery",
     "type": "gallery",
     "params": {
       "prompt": "Set a background",
       "showTitle": false,
       "forceSelection": true,
       "items": "{{ $['bg-request'].response.items }}"
     }
   }
 ]
}

Hierarchy

  • AuBaseInvisibleWidget

    AuWidgetAjax

Implements

Index

Properties

Accessors

Methods

Properties

enabled

enabled: boolean = true

If false, the request will not be executed. The default value is true.


error

error: any = null


headers

headers: any

A dictionary of HTTP headers sent along with the request (an object with the keys used as a header name and a value used as a header value).


method

method: string = "POST"

An HTTP method like POST, GET, etc. The default value is POST.


params

params: IAuWidgetAjaxConfig

Overrides AuBaseWidget.params

Parameters of the Ajax widget.


paramsRaw

paramsRaw: any

Inherited from AuBaseWidget.paramsRaw

Uncompiled widget configuration.


request

request: any

A request body. Typically, you put a JSON here that consists of references to other widgets.


requestPromise

requestPromise: Promise‹any› = Promise.resolve()


requests

requests: Array‹any›


response

response: any

A server response, interpreted based on the responseType param. If [[autoCompile]] is true, it is automatically updated every time the widget gets a server response.


responseHeaders

responseHeaders: Headers = null


responseType

responseType: ResponseType = "json"

Defines how to interpret the response received from the server.


responses

responses: any = []


statusCode

statusCode: number = null


url

url: string

A URL that is used to accept requests.

Accessors

Static template

get template(): HTMLTemplateElement

Inherited from void

Returns:HTMLTemplateElement

Methods

addCustomStyles

addCustomStyles(params: any): void

Inherited from AuBaseWidget.addCustomStyles

Applies new styles to a widget.

Parameters:

Name Type
params any

Returns:void


compile

compile(additionalParam: any): Promise‹any›

Inherited from AuBaseWidget.compile

Compiles the widget config.

"steps": [{
  "name": "card-size",
  "title": "Step 1. Card Options",
  "description": "Choose a card size.",
  "toolPanel": {
    "name": "options"
  },
  "onActivate": [
    "{{#function $['logo'].compile() }}"
  ]
},
...

Parameters:

Name Type Default Description
additionalParam any Parameters for widget config compilation.

Returns:Promise‹any›

The compiled widget configuration.


emitChange

emitChange(data: any, forceRecompile: boolean): void

Inherited from AuBaseWidget.emitChange

Sends a message about the widget state changes.

"steps": [{
  "name": "card-size",
  "title": "Step 1. Card Options",
  "description": "Choose a card size.",
  "toolPanel": {
    "name": "options"
  },
  "onActivate": [
    "{{#function $['options'].emitChange()}}"
  ]
},
...

Parameters:

Name Type Default Description
data any Data for updating the widget.
forceRecompile boolean false If true, runs widget recompilation to apply the updated parameters.

Returns:void


exportWidgetData

exportWidgetData(force: boolean): Promise‹AjaxWidgetData›

Implementation of IRestorableWidget

Parameters:

Name Type
force boolean

Returns:Promise‹AjaxWidgetData›


restoreWidgetFromData

restoreWidgetFromData(widgetData: AjaxWidgetData, force: boolean): Promise‹void›

Parameters:

Name Type
widgetData AjaxWidgetData
force boolean

Returns:Promise‹void›


showPreloader

showPreloader(isShow: boolean): void

Overrides AuBaseWidget.showPreloader

Shows a preloader.

Parameters:

Name Type Description
isShow boolean If true, enables the preloader.

Returns:void


showToast

showToast(data?: string, duration?: number): void

Inherited from AuBaseWidget.showToast

Shows a toast.

return editor.loadUserInfo(data)
    .catch(err => {
        this.widget.showToast("Error: Invalid data");
        console.log(err);
    });

Parameters:

Name Type Description
data? string A string message to display in the toast.
duration? number Defines how long to show the toast for.

Returns:void