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:
#alerts
element in its index.html
.
- A precompiled template called
alert
. The template can be compiled at
application start-up:
app.template.compile('alert', 'template body...');
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']
})