UI Framework ReferenceAuWidgetAjax

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

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:54

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


error

error: any = null

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:72


headers

headers: any

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:59

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"

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:62

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


params

params: IAuWidgetAjaxConfig

Overrides AuBaseWidget.params

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:273

Parameters of the Ajax widget.


paramsRaw

paramsRaw: any

Inherited from AuBaseWidget.paramsRaw

Defined in src/widgets/widget/AuBaseWidget.ts:53

Uncompiled widget configuration.


request

request: any

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:51

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


requestPromise

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

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:81


requests

requests: Array‹any›

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:56


response

response: any

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:68

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

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:76


responseType

responseType: ResponseType = "json"

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:79

Defines how to interpret the response received from the server.


responses

responses: any = []

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:70


statusCode

statusCode: number = null

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:74


url

url: string

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:65

A URL that is used to accept requests.

Accessors

Static template

get template(): HTMLTemplateElement

Inherited from void

Defined in src/widgets/widget/AuBaseWidget.ts:534

Returns:HTMLTemplateElement

Methods

addCustomStyles

addCustomStyles(params: any): void

Inherited from AuBaseWidget.addCustomStyles

Defined in src/widgets/widget/AuBaseWidget.ts:352

Applies new styles to a widget.

Parameters:

Name Type
params any

Returns:void


compile

compile(additionalParam: any): Promise‹any›

Inherited from AuBaseWidget.compile

Defined in src/widgets/widget/AuBaseWidget.ts:185

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

Defined in src/widgets/widget/AuBaseWidget.ts:161

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

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:333

Parameters:

Name Type
force boolean

Returns:Promise‹AjaxWidgetData›


restoreWidgetFromData

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

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:337

Parameters:

Name Type
widgetData AjaxWidgetData
force boolean

Returns:Promise‹void›


showPreloader

showPreloader(isShow: boolean): void

Overrides AuBaseWidget.showPreloader

Defined in src/widgets/au-widget-ajax/au-widget-ajax.ts:352

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

Defined in src/widgets/widget/AuBaseWidget.ts:514

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