Module: View/Alert

Alert.

Interface for creating alerts via show and dismiss. Also, this module keeps an internal dictionary of alerts created which can later be accessed by key. This is useful so that client code can dismiss a particular alert.

Note that the client application may provide custom implementation of the View/AlertView class. This implementation will be in charge of rendering the alert to its UI.

At minimum, a client app must provide:

  1. #alerts element in its index.html.
  2. A precompiled template called alert. The template can be compiled at application start-up: app.template.compile('alert', 'template body...');

Members


<static> klass :function

Alert view class.

The default value is View/AlertView. However, if a ViewManager.[Capitalized-appId]AlertView or ViewManager.[Capitalized-platform]AlertView class exists, it will be used instead.

Type:
  • function

Methods


<static> dismiss(key [, options])

Removes an alert message by key.

Parameters:
Name Type Argument Description
key string

The key provided when previously calling show.

options Object <optional>

Options.


<static> dismissAll( [level] [, options])

Removes all alert messages with a given level.

Parameters:
Name Type Argument Description
level string <optional>

Level of alerts to dismiss. If not specified, all alerts are dismissed.

options Object <optional>

Dismissal options.


<static> get(key)

Gets an alert with a given key.

Parameters:
Name Type Description
key string

The key of the alert to retrieve.

Returns:

Alert view with the specified key.

Type
View/AlertView

<static> getAll()

Gets alerts that are currently displayed.

Returns:

All alerts.

Type
Object

<static> init()

Initializes this module at application start-up.


<static> show(key [, options])

Displays an alert message and adds to the internal dictionary of alerts. Use supplied key later to dismiss the alert. Caller is responsible for using language translation before calling!

To create and close alerts, this function instantiates the View/AlertView class specified by the View.Alert#klass property and places the alert instance in the DOM as the first element in the View.Alert#$alerts element.

The View/AlertView class provides boilerplate implementation for a typical single alert view. You can customize alert behavior by extending the View/AlertView class. At minimum, you have to make sure that a pre-compiled template named 'alert' exists.

In case we are showing a confirmation alert, we want to dismiss all other existing alerts and prevent any other alerts.

Examples:

const Alert = require('view/alert');
var a1 = Alert.show('delete_warning', {
    level: 'warning',
    title: 'Warning',
    messages: 'Are you sure you want to delete this record?',
    autoclose: true
});

var a2 = Alert.show('internal_error', {
    level: 'error',
    messages: ['Internal Error', 'Response code: 500']
})
Parameters:
Name Type Argument Description
key string

Index into the cache of defined alert views.

options Object <optional>

The options specified here are handled by the framework.

Properties
Name Type Argument Description
level string <optional>

Alert level. alert-[level] class will be added to the alert view.

autoClose boolean <optional>

Boolean flag indicating if the alert must be closed after dismiss delay: See Config#alertAutoCloseDelay setting.

messages string | Array.<string> <optional>

Messages.

title string <optional>

The title of the alert. It is displayed in bold.

Returns:

AlertView instance.

Type
View/AlertView