
# Class: AuWidgetAssetStorageAjax

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

The following example illustrates how you can populate a gallery with images obtained through an HTTP request.
```
{
  "widgets": [
   {
     "name": "bg-request",
     "type": "asset-storage-ajax",
     "params": {
          "autoCompile": false,
          "assetType": "designs",
          "folder": "",
          "entriesFilter": [
              "{{ #function(asset) asset.metadata.surfaces[0].width > 100 }}"
          ],
          "previewOptions": {
              "name": "medium",
              "namespace": "storefront",
              "width": 600,
              "height": 600
          }
     }
   },
   {
     "name": "gallery",
     "title": "Gallery",
     "type": "gallery",
     "params": {
       "prompt": "Set a background",
       "showTitle": false,
       "forceSelection": true,
       "items": "{{ $['bg-request'].response }}"
     }
   }
 ]
}
```

## Hierarchy

* AuBaseInvisibleWidget

  ↳ **AuWidgetAssetStorageAjax**

## Implements

* [IWidget](../interfaces/iwidget.md)
* [IRestorableWidget](../interfaces/irestorablewidget.md)

## Index

### Properties

* [apiResponse](auwidgetassetstorageajax.md#apiresponse)
* [assetType](auwidgetassetstorageajax.md#assettype)
* [entriesFilter](auwidgetassetstorageajax.md#entriesfilter)
* [folder](auwidgetassetstorageajax.md#folder)
* [folderFilter](auwidgetassetstorageajax.md#folderfilter)
* [params](auwidgetassetstorageajax.md#params)
* [previewOptions](auwidgetassetstorageajax.md#previewoptions)
* [requestPromise](auwidgetassetstorageajax.md#requestpromise)
* [response](auwidgetassetstorageajax.md#response)

### Accessors

* [template](auwidgetassetstorageajax.md#static-template)

### Methods

* [checkInitDependenciesWidgets](auwidgetassetstorageajax.md#checkinitdependencieswidgets)
* [exportWidgetData](auwidgetassetstorageajax.md#exportwidgetdata)
* [resetPreloaderState](auwidgetassetstorageajax.md#resetpreloaderstate)
* [restoreWidgetFromData](auwidgetassetstorageajax.md#restorewidgetfromdata)
* [showPreloader](auwidgetassetstorageajax.md#showpreloader)
* [showToast](auwidgetassetstorageajax.md#showtoast)

## Properties

###  apiResponse

• **apiResponse**: *[AssetStorageApiClientResult](../README.md#assetstorageapiclientresult)*

A server response, interpreted based on the [responseType](../interfaces/iauwidgetajaxconfig.md#responsetype) param. If [autoCompile](../interfaces/idesigneditordefinitionmodifyitems.md#optional-autocompile) is `true`, it is automatically updated every time the widget gets a server response.

___

###  assetType

• **assetType**: *[AssetType](../README.md#assettype)*

___

###  entriesFilter

• **entriesFilter**: *Function*

___

###  folder

• **folder**: *string*

___

###  folderFilter

• **folderFilter**: *Function*

___

###  params

• **params**: *[IAuWidgetAssetStorageAjaxConfig](../interfaces/iauwidgetassetstorageajaxconfig.md)*

*Overrides [AuBaseWidget](aubasewidget.md).[params](aubasewidget.md#params)*

Parameters of the widget.

___

###  previewOptions

• **previewOptions**: *[IPreviewOptions](../interfaces/ipreviewoptions.md)*

___

###  requestPromise

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

Promise, for awaiting in #function for getting response.
```
"{{ #function $['image-request'].compile() }}",
"{{ #asyncFunction await $['image-request'].requestPromise }}"
```

___

###  response

• **response**: *Array‹[IAssetDataResult](../interfaces/iassetdataresult.md)›* =  []

## Accessors

### `Static` template

• **get template**(): *HTMLTemplateElement*

*Inherited from void*

**Returns:** *HTMLTemplateElement*

## Methods

###  checkInitDependenciesWidgets

▸ **checkInitDependenciesWidgets**(): *string[]*

*Inherited from [AuBaseWidget](aubasewidget.md).[checkInitDependenciesWidgets](aubasewidget.md#checkinitdependencieswidgets)*

Returns an array of widget names, due to which the current widget cannot receive parameters.

**Returns:** *string[]*

___

###  exportWidgetData

▸ **exportWidgetData**(`force`: boolean): *Promise‹AssetStorageAjaxWidgetData›*

*Implementation of [IRestorableWidget](../interfaces/irestorablewidget.md)*

**Parameters:**

Name | Type |
------ | ------ |
`force` | boolean |

**Returns:** *Promise‹AssetStorageAjaxWidgetData›*

___

###  resetPreloaderState

▸ **resetPreloaderState**(): *void*

*Inherited from [AuBaseWidget](aubasewidget.md).[resetPreloaderState](aubasewidget.md#resetpreloaderstate)*

**Returns:** *void*

___

###  restoreWidgetFromData

▸ **restoreWidgetFromData**(`widgetData`: AssetStorageAjaxWidgetData, `force`: boolean): *Promise‹void›*

**Parameters:**

Name | Type |
------ | ------ |
`widgetData` | AssetStorageAjaxWidgetData |
`force` | boolean |

**Returns:** *Promise‹void›*

___

###  showPreloader

▸ **showPreloader**(`isShow`: boolean): *void*

*Overrides [AuBaseWidget](aubasewidget.md).[showPreloader](aubasewidget.md#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](aubasewidget.md).[showToast](aubasewidget.md#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*
