MDL-43992 Javascript: Remove <return> key listener for confirmation
[moodle.git] / lib / yui / build / moodle-core-notification-confirm / moodle-core-notification-confirm.js
CommitLineData
78686995
AN
1YUI.add('moodle-core-notification-confirm', function (Y, NAME) {
2
3var DIALOGUE_PREFIX,
4 BASE,
5 COUNT,
6 CONFIRMYES,
7 CONFIRMNO,
8 TITLE,
9 QUESTION,
10 CSS;
11
12DIALOGUE_PREFIX = 'moodle-dialogue',
13BASE = 'notificationBase',
14COUNT = 0,
15CONFIRMYES = 'yesLabel',
16CONFIRMNO = 'noLabel',
17TITLE = 'title',
18QUESTION = 'question',
19CSS = {
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};
29
30// Set up the namespace once.
31M.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 */
38
39var CONFIRM_NAME = 'Moodle confirmation dialogue',
40 CONFIRM;
41
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 */
50CONFIRM = function(config) {
51 CONFIRM.superclass.constructor.apply(this, [config]);
52};
53Y.extend(CONFIRM, M.core.dialogue, {
649c80e6 54 closeEvents: [],
78686995
AN
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);
649c80e6
AN
70
71 this.closeEvents.push(
649c80e6
AN
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 );
76
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 }
78686995
AN
84 },
85 submit : function(e, outcome) {
649c80e6 86 new Y.EventHandle(this.closeEvents).detach();
78686995
AN
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 : {
100
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 },
112
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 },
124
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 },
136
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});
150Y.augment(CONFIRM, Y.EventTarget);
151
152M.core.confirm = CONFIRM;
153
154
155}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});