define([], function () {
'use strict';
/**
* UI notification descriptor support.
* <p>
* Helps creating notifications to be displayed to users. Notification can
* have various parameters - i.e. level (INFO, SUCCESS, WARNING, ...).
*
* @AbcsAPI stable
* @exports ui/js/api/Notification
* @constructor
*
* @see {@link ui/js/api/Notification.Level Notification.Level}
*/
var Notification = function(parameters) {
AbcsLib.checkDefined(parameters.message, 'parameters.message');
this._message = parameters.message;
this._level = parameters.level || Notification.INFO;
};
/**
* Creates new notification instance.
*
* @AbcsAPI stable
* @version 15.4.5
*
* @static
* @param {string} parameters.message message to show
* @param {number} [parameters.level=Level.INFO] message level
* @returns {ui/js/api/Notification}
*
* @example
* <caption>Creates the simplest Notification instance</caption>
* var notification = Notification.create({
* message: 'Ahoy'
* });
* @example
* <caption>Creates Notification including level information</caption>
* var notification = Notification.create({
* message: 'Ahoy',
* level: Notification.Level.SUCCESS
* });
*/
Notification.create = function (parameters) {
return new Notification(parameters);
};
/**
* Sets the notification message.
*
* @AbcsAPI stable
* @version 15.4.5
*
* @param {string} message message to show
* @returns {ui/js/api/Notification}
*
* @example
* <caption>Sets the message "Ahoy" to the Notification instance</caption>
* Notification.create().message('Ahoy');
*/
Notification.prototype.message = function (message) {
this._message = message;
return this;
};
/**
* Sets the notification level.
*
* @AbcsAPI stable
* @version 15.4.5
*
* @param {ui/js/api/Notification.Level} level severity of the reporting to use
* @returns {ui/js/api/Notification}
*
* @example
* <caption>Sets the message "Beware" and WARNING level to the Notification instance</caption>
* Notification.create().message('Beware').level(Notification.Level.WARNING);
* @example
* <caption>Sets the message "OK" and SUCCESS level to the Notification instance</caption>
* var notification = Notification.create({message: 'OK'});
* notification.level(Notification.Level.SUCCESS);
*/
Notification.prototype.level = function (level) {
this._level = level;
return this;
};
/**
* Gets the notification's message.
*
*
* @returns {string} message of the notification
*/
Notification.prototype.getMessage = function () {
return this._message;
};
/**
* Gets the notification's level.
*
*
* @returns {string} level (severity) to be used in notification
*/
Notification.prototype.getLevel = function () {
return this._level;
};
/**
* Notification levels.
*
* @AbcsAPI stable
* @version 15.4.5
* @enum {number}
*/
Notification.Level = {
/**
* Success message.
*/
SUCCESS: 1,
/**
* Information message.
*/
INFO: 2,
/**
* Warning message.
*/
WARNING: 3,
/**
* Error message.
*/
ERROR: 4
};
return Notification;
});