MDL-43992 Javascript: Remove <return> key listener for confirmation
[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     COUNT,
6     CONFIRMYES,
7     CONFIRMNO,
8     TITLE,
9     QUESTION,
10     CSS;
12 DIALOGUE_PREFIX = 'moodle-dialogue',
13 BASE = 'notificationBase',
14 COUNT = 0,
15 CONFIRMYES = 'yesLabel',
16 CONFIRMNO = 'noLabel',
17 TITLE = 'title',
18 QUESTION = 'question',
19 CSS = {
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',
26     HIDDEN : 'hidden',
27     LIGHTBOX : 'moodle-dialogue-lightbox'
28 };
30 // Set up the namespace once.
31 M.core = M.core || {};
32 /**
33  * A dialogue type designed to display a confirmation to the user.
34  *
35  * @module moodle-core-notification
36  * @submodule moodle-core-notification-confirm
37  */
39 var CONFIRM_NAME = 'Moodle confirmation dialogue',
40     CONFIRM;
42 /**
43  * Extends core Dialogue to show the confirmation dialogue.
44  *
45  * @param {Object} config Object literal specifying the dialogue configuration properties.
46  * @constructor
47  * @class M.core.confirm
48  * @extends M.core.dialogue
49  */
50 CONFIRM = function(config) {
51     CONFIRM.superclass.constructor.apply(this, [config]);
52 };
53 Y.extend(CONFIRM, M.core.dialogue, {
54     closeEvents: [],
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>')
64                             .append(yes)
65                             .append(no));
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)
75         );
77         var closeButton = this.get('boundingBox').one('.closebutton');
78         if (closeButton) {
79             // The close button should act exactly like the 'No' button.
80             this.closeEvents.push(
81                 closeButton.on('click', this.submit, this)
82             );
83         }
84     },
85     submit : function(e, outcome) {
86         new Y.EventHandle(this.closeEvents).detach();
87         this.fire('complete', outcome);
88         if (outcome) {
89             this.fire('complete-yes');
90         } else {
91             this.fire('complete-no');
92         }
93         this.hide();
94         this.destroy();
95     }
96 }, {
97     NAME : CONFIRM_NAME,
98     CSS_PREFIX : DIALOGUE_PREFIX,
99     ATTRS : {
101         /**
102          * The button text to use to accept the confirmation.
103          *
104          * @attribute yesLabel
105          * @type String
106          * @default 'Yes'
107          */
108         yesLabel : {
109             validator : Y.Lang.isString,
110             value : 'Yes'
111         },
113         /**
114          * The button text to use to reject the confirmation.
115          *
116          * @attribute noLabel
117          * @type String
118          * @default 'No'
119          */
120         noLabel : {
121             validator : Y.Lang.isString,
122             value : 'No'
123         },
125         /**
126          * The title of the dialogue.
127          *
128          * @attribute title
129          * @type String
130          * @default 'Confirm'
131          */
132         title : {
133             validator : Y.Lang.isString,
134             value : 'Confirm'
135         },
137         /**
138          * The question posed by the dialogue.
139          *
140          * @attribute question
141          * @type String
142          * @default 'Are you sure?'
143          */
144         question : {
145             validator : Y.Lang.isString,
146             value : 'Are you sure?'
147         }
148     }
149 });
150 Y.augment(CONFIRM, Y.EventTarget);
152 M.core.confirm = CONFIRM;
155 }, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});