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