Revert "Merge branch 'm28_MDL-46431' of https://github.com/totara/moodle"
[moodle.git] / lib / yui / src / notification / js / alert.js
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  */
8 var ALERT_NAME = 'Moodle alert',
9     ALERT;
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  */
19 ALERT = function(config) {
20     config.closeButton = false;
21     ALERT.superclass.constructor.apply(this, [config]);
22 };
23 Y.extend(ALERT, M.core.notification.info, {
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 = [];
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,
43                 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
45         this._closeEvents.push(
46             Y.on('key', this.submit, window, 'down:13', this),
47             yes.on('click', this.submit, this)
48         );
50         var closeButton = this.get('boundingBox').one('.closebutton');
51         if (closeButton) {
52             // The close button should act exactly like the 'No' button.
53             this._closeEvents.push(
54                 closeButton.on('click', this.submit, this)
55             );
56         }
57     },
58     submit: function() {
59         new Y.EventHandle(this._closeEvents).detach();
60         this.fire('complete');
61         this.hide();
62         this.destroy();
63     }
64 }, {
65     NAME: ALERT_NAME,
66     CSS_PREFIX: DIALOGUE_PREFIX,
67     ATTRS: {
69         /**
70          * The title of the alert.
71          *
72          * @attribute title
73          * @type String
74          * @default 'Alert'
75          */
76         title: {
77             validator: Y.Lang.isString,
78             value: 'Alert'
79         },
81         /**
82          * The message of the alert.
83          *
84          * @attribute message
85          * @type String
86          * @default 'Confirm'
87          */
88         message: {
89             validator: Y.Lang.isString,
90             value: 'Confirm'
91         },
93         /**
94          * The button text to use to accept the alert.
95          *
96          * @attribute yesLabel
97          * @type String
98          * @default 'Ok'
99          */
100         yesLabel: {
101             validator: Y.Lang.isString,
102             setter: function(txt) {
103                 if (!txt) {
104                     txt = 'Ok';
105                 }
106                 return txt;
107             },
108             value: 'Ok'
109         }
110     }
111 });
113 M.core.alert = ALERT;