Revert "Merge branch 'm28_MDL-46431' of https://github.com/totara/moodle"
[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
3var DIALOGUE_PREFIX,
4 BASE,
78686995
AN
5 CONFIRMYES,
6 CONFIRMNO,
7 TITLE,
8 QUESTION,
9 CSS;
10
11DIALOGUE_PREFIX = 'moodle-dialogue',
12BASE = 'notificationBase',
78686995
AN
13CONFIRMYES = 'yesLabel',
14CONFIRMNO = 'noLabel',
15TITLE = 'title',
16QUESTION = 'question',
17CSS = {
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};
27
28// Set up the namespace once.
29M.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 */
36
37var CONFIRM_NAME = 'Moodle confirmation dialogue',
38 CONFIRM;
39
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 */
48CONFIRM = function(config) {
49 CONFIRM.superclass.constructor.apply(this, [config]);
50};
cfa770b4 51Y.extend(CONFIRM, M.core.notification.info, {
f857b668
AN
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,
60 initializer: function() {
61 this._closeEvents = [];
78686995
AN
62 this.publish('complete');
63 this.publish('complete-yes');
64 this.publish('complete-no');
65 var yes = Y.Node.create('<input type="button" id="id_yuiconfirmyes-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
66 no = Y.Node.create('<input type="button" id="id_yuiconfirmno-' + this.get('COUNT') + '" value="'+this.get(CONFIRMNO)+'" />'),
67 content = Y.Node.create('<div class="confirmation-dialogue"></div>')
68 .append(Y.Node.create('<div class="confirmation-message">'+this.get(QUESTION)+'</div>'))
69 .append(Y.Node.create('<div class="confirmation-buttons"></div>')
70 .append(yes)
71 .append(no));
72 this.get(BASE).addClass('moodle-dialogue-confirm');
73 this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
74 this.setStdModContent(Y.WidgetStdMod.HEADER,
c44012e0 75 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
649c80e6 76
f857b668 77 this._closeEvents.push(
649c80e6
AN
78 Y.on('key', this.submit, window, 'down:27', this, false),
79 yes.on('click', this.submit, this, true),
80 no.on('click', this.submit, this, false)
81 );
82
83 var closeButton = this.get('boundingBox').one('.closebutton');
84 if (closeButton) {
85 // The close button should act exactly like the 'No' button.
f857b668 86 this._closeEvents.push(
649c80e6
AN
87 closeButton.on('click', this.submit, this)
88 );
89 }
78686995 90 },
f857b668
AN
91 submit: function(e, outcome) {
92 new Y.EventHandle(this._closeEvents).detach();
78686995
AN
93 this.fire('complete', outcome);
94 if (outcome) {
95 this.fire('complete-yes');
96 } else {
97 this.fire('complete-no');
98 }
99 this.hide();
100 this.destroy();
101 }
102}, {
f857b668
AN
103 NAME: CONFIRM_NAME,
104 CSS_PREFIX: DIALOGUE_PREFIX,
105 ATTRS: {
78686995
AN
106
107 /**
108 * The button text to use to accept the confirmation.
109 *
110 * @attribute yesLabel
111 * @type String
112 * @default 'Yes'
113 */
f857b668
AN
114 yesLabel: {
115 validator: Y.Lang.isString,
0d1d5423 116 value: M.util.get_string('yes', 'moodle')
78686995
AN
117 },
118
119 /**
120 * The button text to use to reject the confirmation.
121 *
122 * @attribute noLabel
123 * @type String
124 * @default 'No'
125 */
f857b668
AN
126 noLabel: {
127 validator: Y.Lang.isString,
0d1d5423 128 value: M.util.get_string('no', 'moodle')
78686995
AN
129 },
130
131 /**
132 * The title of the dialogue.
133 *
134 * @attribute title
135 * @type String
136 * @default 'Confirm'
137 */
f857b668
AN
138 title: {
139 validator: Y.Lang.isString,
0d1d5423 140 value: M.util.get_string('confirm', 'moodle')
78686995
AN
141 },
142
143 /**
144 * The question posed by the dialogue.
145 *
146 * @attribute question
147 * @type String
148 * @default 'Are you sure?'
149 */
f857b668
AN
150 question: {
151 validator: Y.Lang.isString,
0d1d5423 152 value: M.util.get_string('areyousure', 'moodle')
78686995
AN
153 }
154 }
155});
156Y.augment(CONFIRM, Y.EventTarget);
157
158M.core.confirm = CONFIRM;
159
160
161}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});