Merge branch 'MDL-43885-master' of git://github.com/andrewnicols/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.dialogue, {
24     closeEvents: [],
25     initializer : function() {
26         this.publish('complete');
27         var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
28             content = Y.Node.create('<div class="confirmation-dialogue"></div>')
29                     .append(Y.Node.create('<div class="confirmation-message">'+this.get('message')+'</div>'))
30                     .append(Y.Node.create('<div class="confirmation-buttons"></div>')
31                             .append(yes));
32         this.get(BASE).addClass('moodle-dialogue-confirm');
33         this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
34         this.setStdModContent(Y.WidgetStdMod.HEADER,
35                 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
37         this.closeEvents.push(
38             Y.on('key', this.submit, window, 'down:13', this),
39             yes.on('click', this.submit, this)
40         );
42         var closeButton = this.get('boundingBox').one('.closebutton');
43         if (closeButton) {
44             // The close button should act exactly like the 'No' button.
45             this.closeEvents.push(
46                 closeButton.on('click', this.submit, this)
47             );
48         }
49     },
50     submit : function() {
51         new Y.EventHandle(this.closeEvents).detach();
52         this.fire('complete');
53         this.hide();
54         this.destroy();
55     }
56 }, {
57     NAME : ALERT_NAME,
58     CSS_PREFIX : DIALOGUE_PREFIX,
59     ATTRS : {
61         /**
62          * The title of the alert.
63          *
64          * @attribute title
65          * @type String
66          * @default 'Alert'
67          */
68         title : {
69             validator : Y.Lang.isString,
70             value : 'Alert'
71         },
73         /**
74          * The message of the alert.
75          *
76          * @attribute message
77          * @type String
78          * @default 'Confirm'
79          */
80         message : {
81             validator : Y.Lang.isString,
82             value : 'Confirm'
83         },
85         /**
86          * The button text to use to accept the alert.
87          *
88          * @attribute yesLabel
89          * @type String
90          * @default 'Ok'
91          */
92         yesLabel : {
93             validator : Y.Lang.isString,
94             setter : function(txt) {
95                 if (!txt) {
96                     txt = 'Ok';
97                 }
98                 return txt;
99             },
100             value : 'Ok'
101         }
102     }
103 });
105 M.core.alert = ALERT;