459e5951b670d6c7cb1b52d8e2e1e0714b9f4e30
[moodle.git] / lib / yui / build / moodle-core-notification-confirm / moodle-core-notification-confirm-debug.js
1 YUI.add('moodle-core-notification-confirm', function (Y, NAME) {
3 var DIALOGUE_PREFIX,
4     BASE,
5     CONFIRMYES,
6     CONFIRMNO,
7     TITLE,
8     QUESTION,
9     CSS;
11 DIALOGUE_PREFIX = 'moodle-dialogue',
12 BASE = 'notificationBase',
13 CONFIRMYES = 'yesLabel',
14 CONFIRMNO = 'noLabel',
15 TITLE = 'title',
16 QUESTION = 'question',
17 CSS = {
18     BASE : 'moodle-dialogue-base',
19     WRAP : 'moodle-dialogue-wrap',
20     HEADER : 'moodle-dialogue-hd',
21     BODY : 'moodle-dialogue-bd',
22     CONTENT : 'moodle-dialogue-content',
23     FOOTER : 'moodle-dialogue-ft',
24     HIDDEN : 'hidden',
25     LIGHTBOX : 'moodle-dialogue-lightbox'
26 };
28 // Set up the namespace once.
29 M.core = M.core || {};
30 /**
31  * A dialogue type designed to display a confirmation to the user.
32  *
33  * @module moodle-core-notification
34  * @submodule moodle-core-notification-confirm
35  */
37 var CONFIRM_NAME = 'Moodle confirmation dialogue',
38     CONFIRM;
40 /**
41  * Extends core Dialogue to show the confirmation dialogue.
42  *
43  * @param {Object} config Object literal specifying the dialogue configuration properties.
44  * @constructor
45  * @class M.core.confirm
46  * @extends M.core.dialogue
47  */
48 CONFIRM = function(config) {
49     CONFIRM.superclass.constructor.apply(this, [config]);
50 };
51 Y.extend(CONFIRM, M.core.notification.info, {
52     /**
53      * The list of events to detach when destroying this dialogue.
54      *
55      * @property _closeEvents
56      * @type EventHandle[]
57      * @private
58      */
59     _closeEvents: null,
61     /**
62      * A reference to the yes button.
63      *
64      * @property _yesButton
65      * @type Node
66      * @private
67      */
68     _yesButton: null,
70     /**
71      * A reference to the No button.
72      *
73      * @property _noButton
74      * @type Node
75      * @private
76      */
77     _noButton: null,
79     /**
80      * A reference to the Question.
81      *
82      * @property _question
83      * @type Node
84      * @private
85      */
86     _question: null,
88     initializer: function() {
89         this._closeEvents = [];
90         this.publish('complete');
91         this.publish('complete-yes');
92         this.publish('complete-no');
93         this._yesButton = Y.Node.create('<input type="button" id="id_yuiconfirmyes-' +
94                                         this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />');
95         this._noButton = Y.Node.create('<input type="button" id="id_yuiconfirmno-' +
96                                         this.get('COUNT') + '" value="'+this.get(CONFIRMNO)+'" />');
97         this._question = Y.Node.create('<div class="confirmation-message">' + this.get(QUESTION) + '</div>');
98         var content = Y.Node.create('<div class="confirmation-dialogue"></div>')
99                         .append(this._question)
100                         .append(Y.Node.create('<div class="confirmation-buttons"></div>')
101                             .append(this._yesButton)
102                             .append(this._noButton));
103         this.get(BASE).addClass('moodle-dialogue-confirm');
104         this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
105         this.setStdModContent(Y.WidgetStdMod.HEADER,
106                 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
108         this._closeEvents.push(
109             Y.on('key', this.submit, window, 'down:27', this, false),
110             this._yesButton.on('click', this.submit, this, true),
111             this._noButton.on('click', this.submit, this, false)
112         );
114         var closeButton = this.get('boundingBox').one('.closebutton');
115         if (closeButton) {
116             // The close button should act exactly like the 'No' button.
117             this._closeEvents.push(
118                 closeButton.on('click', this.submit, this)
119             );
120         }
121     },
122     submit: function(e, outcome) {
123         new Y.EventHandle(this._closeEvents).detach();
124         this.fire('complete', outcome);
125         if (outcome) {
126             this.fire('complete-yes');
127         } else {
128             this.fire('complete-no');
129         }
130         this.hide();
131         this.destroy();
132     }
133 }, {
134     NAME: CONFIRM_NAME,
135     CSS_PREFIX: DIALOGUE_PREFIX,
136     ATTRS: {
138         /**
139          * The button text to use to accept the confirmation.
140          *
141          * @attribute yesLabel
142          * @type String
143          * @default 'Yes'
144          */
145         yesLabel: {
146             validator: Y.Lang.isString,
147             valueFn: function() {
148                 return M.util.get_string('yes', 'moodle');
149             },
150             setter: function(value) {
151                 if (this._yesButton) {
152                     this._yesButton.set('value', value);
153                 }
154                 return value;
155             }
156         },
158         /**
159          * The button text to use to reject the confirmation.
160          *
161          * @attribute noLabel
162          * @type String
163          * @default 'No'
164          */
165         noLabel: {
166             validator: Y.Lang.isString,
167             valueFn: function() {
168                 return M.util.get_string('no', 'moodle');
169             },
170             setter: function(value) {
171                 if (this._noButton) {
172                     this._noButton.set('value', value);
173                 }
174                 return value;
175             }
176         },
178         /**
179          * The title of the dialogue.
180          *
181          * @attribute title
182          * @type String
183          * @default 'Confirm'
184          */
185         title: {
186             validator: Y.Lang.isString,
187             value: M.util.get_string('confirm', 'moodle')
188         },
190         /**
191          * The question posed by the dialogue.
192          *
193          * @attribute question
194          * @type String
195          * @default 'Are you sure?'
196          */
197         question: {
198             validator: Y.Lang.isString,
199             valueFn: function() {
200                 return M.util.get_string('areyousure', 'moodle');
201             },
202             setter: function(value) {
203                 if (this._question) {
204                     this._question.set('value', value);
205                 }
206                 return value;
207             }
208         }
209     }
210 });
211 Y.augment(CONFIRM, Y.EventTarget);
213 M.core.confirm = CONFIRM;
216 }, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});