Revert "Merge branch 'm28_MDL-46431' of https://github.com/totara/moodle"
[moodle.git] / lib / yui / src / notification / js / alert.js
CommitLineData
78686995
AN
1/**
2 * A dialogue type designed to display an alert to the user.
3 *
4 * @module moodle-core-notification
5 * @submodule moodle-core-notification-alert
6 */
7
8var ALERT_NAME = 'Moodle alert',
9 ALERT;
10
11/**
12 * Extends core Dialogue to show the alert dialogue.
13 *
14 * @param {Object} config Object literal specifying the dialogue configuration properties.
15 * @constructor
16 * @class M.core.alert
17 * @extends M.core.dialogue
18 */
19ALERT = function(config) {
20 config.closeButton = false;
21 ALERT.superclass.constructor.apply(this, [config]);
22};
cfa770b4 23Y.extend(ALERT, M.core.notification.info, {
f857b668
AN
24 /**
25 * The list of events to detach when destroying this dialogue.
26 *
27 * @property _closeEvents
28 * @type EventHandle[]
29 * @private
30 */
31 _closeEvents: null,
32 initializer: function() {
33 this._closeEvents = [];
78686995
AN
34 this.publish('complete');
35 var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
36 content = Y.Node.create('<div class="confirmation-dialogue"></div>')
37 .append(Y.Node.create('<div class="confirmation-message">'+this.get('message')+'</div>'))
38 .append(Y.Node.create('<div class="confirmation-buttons"></div>')
39 .append(yes));
40 this.get(BASE).addClass('moodle-dialogue-confirm');
41 this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
42 this.setStdModContent(Y.WidgetStdMod.HEADER,
c44012e0 43 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
2f166b32 44
f857b668 45 this._closeEvents.push(
649c80e6
AN
46 Y.on('key', this.submit, window, 'down:13', this),
47 yes.on('click', this.submit, this)
48 );
49
50 var closeButton = this.get('boundingBox').one('.closebutton');
51 if (closeButton) {
52 // The close button should act exactly like the 'No' button.
f857b668 53 this._closeEvents.push(
649c80e6
AN
54 closeButton.on('click', this.submit, this)
55 );
56 }
78686995 57 },
f857b668
AN
58 submit: function() {
59 new Y.EventHandle(this._closeEvents).detach();
78686995
AN
60 this.fire('complete');
61 this.hide();
62 this.destroy();
63 }
64}, {
f857b668
AN
65 NAME: ALERT_NAME,
66 CSS_PREFIX: DIALOGUE_PREFIX,
67 ATTRS: {
78686995
AN
68
69 /**
70 * The title of the alert.
71 *
72 * @attribute title
73 * @type String
74 * @default 'Alert'
75 */
f857b668
AN
76 title: {
77 validator: Y.Lang.isString,
78 value: 'Alert'
78686995
AN
79 },
80
81 /**
82 * The message of the alert.
83 *
84 * @attribute message
85 * @type String
86 * @default 'Confirm'
87 */
f857b668
AN
88 message: {
89 validator: Y.Lang.isString,
90 value: 'Confirm'
78686995
AN
91 },
92
93 /**
94 * The button text to use to accept the alert.
95 *
96 * @attribute yesLabel
97 * @type String
98 * @default 'Ok'
99 */
f857b668
AN
100 yesLabel: {
101 validator: Y.Lang.isString,
102 setter: function(txt) {
78686995
AN
103 if (!txt) {
104 txt = 'Ok';
105 }
106 return txt;
107 },
f857b668 108 value: 'Ok'
78686995
AN
109 }
110 }
111});
112
113M.core.alert = ALERT;