1 YUI.add('moodle-core-notification-confirm', function (Y, NAME) {
12 DIALOGUE_PREFIX = 'moodle-dialogue',
13 BASE = 'notificationBase',
15 CONFIRMYES = 'yesLabel',
16 CONFIRMNO = 'noLabel',
18 QUESTION = 'question',
20 BASE : 'moodle-dialogue-base',
21 WRAP : 'moodle-dialogue-wrap',
22 HEADER : 'moodle-dialogue-hd',
23 BODY : 'moodle-dialogue-bd',
24 CONTENT : 'moodle-dialogue-content',
25 FOOTER : 'moodle-dialogue-ft',
27 LIGHTBOX : 'moodle-dialogue-lightbox'
30 // Set up the namespace once.
31 M.core = M.core || {};
33 * A dialogue type designed to display a confirmation to the user.
35 * @module moodle-core-notification
36 * @submodule moodle-core-notification-confirm
39 var CONFIRM_NAME = 'Moodle confirmation dialogue',
43 * Extends core Dialogue to show the confirmation dialogue.
45 * @param {Object} config Object literal specifying the dialogue configuration properties.
47 * @class M.core.confirm
48 * @extends M.core.dialogue
50 CONFIRM = function(config) {
51 CONFIRM.superclass.constructor.apply(this, [config]);
53 Y.extend(CONFIRM, M.core.dialogue, {
55 initializer : function() {
56 this.publish('complete');
57 this.publish('complete-yes');
58 this.publish('complete-no');
59 var yes = Y.Node.create('<input type="button" id="id_yuiconfirmyes-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
60 no = Y.Node.create('<input type="button" id="id_yuiconfirmno-' + this.get('COUNT') + '" value="'+this.get(CONFIRMNO)+'" />'),
61 content = Y.Node.create('<div class="confirmation-dialogue"></div>')
62 .append(Y.Node.create('<div class="confirmation-message">'+this.get(QUESTION)+'</div>'))
63 .append(Y.Node.create('<div class="confirmation-buttons"></div>')
66 this.get(BASE).addClass('moodle-dialogue-confirm');
67 this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
68 this.setStdModContent(Y.WidgetStdMod.HEADER,
69 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
71 this.closeEvents.push(
72 Y.on('key', this.submit, window, 'down:27', this, false),
73 yes.on('click', this.submit, this, true),
74 no.on('click', this.submit, this, false)
77 var closeButton = this.get('boundingBox').one('.closebutton');
79 // The close button should act exactly like the 'No' button.
80 this.closeEvents.push(
81 closeButton.on('click', this.submit, this)
85 submit : function(e, outcome) {
86 new Y.EventHandle(this.closeEvents).detach();
87 this.fire('complete', outcome);
89 this.fire('complete-yes');
91 this.fire('complete-no');
98 CSS_PREFIX : DIALOGUE_PREFIX,
102 * The button text to use to accept the confirmation.
104 * @attribute yesLabel
109 validator : Y.Lang.isString,
114 * The button text to use to reject the confirmation.
121 validator : Y.Lang.isString,
126 * The title of the dialogue.
133 validator : Y.Lang.isString,
138 * The question posed by the dialogue.
140 * @attribute question
142 * @default 'Are you sure?'
145 validator : Y.Lang.isString,
146 value : 'Are you sure?'
150 Y.augment(CONFIRM, Y.EventTarget);
152 M.core.confirm = CONFIRM;
155 }, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});