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.js
1 YUI.add('moodle-core-notification-confirm', function (Y, NAME) {
3 var DIALOGUE_PREFIX,
4     BASE,
5     CONFIRMYES,
6     CONFIRMNO,
7     TITLE,
8     QUESTION,
9     CSS;
11 DIALOGUE_PREFIX = 'moodle-dialogue',
12 BASE = 'notificationBase',
13 CONFIRMYES = 'yesLabel',
14 CONFIRMNO = 'noLabel',
15 TITLE = 'title',
16 QUESTION = 'question',
17 CSS = {
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 };
28 // Set up the namespace once.
29 M.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  */
37 var CONFIRM_NAME = 'Moodle confirmation dialogue',
38     CONFIRM;
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  */
48 CONFIRM = function(config) {
49     CONFIRM.superclass.constructor.apply(this, [config]);
50 };
51 Y.extend(CONFIRM, M.core.notification.info, {
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 = [];
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,
75                 '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
77         this._closeEvents.push(
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         );
83         var closeButton = this.get('boundingBox').one('.closebutton');
84         if (closeButton) {
85             // The close button should act exactly like the 'No' button.
86             this._closeEvents.push(
87                 closeButton.on('click', this.submit, this)
88             );
89         }
90     },
91     submit: function(e, outcome) {
92         new Y.EventHandle(this._closeEvents).detach();
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 }, {
103     NAME: CONFIRM_NAME,
104     CSS_PREFIX: DIALOGUE_PREFIX,
105     ATTRS: {
107         /**
108          * The button text to use to accept the confirmation.
109          *
110          * @attribute yesLabel
111          * @type String
112          * @default 'Yes'
113          */
114         yesLabel: {
115             validator: Y.Lang.isString,
116             value: M.util.get_string('yes', 'moodle')
117         },
119         /**
120          * The button text to use to reject the confirmation.
121          *
122          * @attribute noLabel
123          * @type String
124          * @default 'No'
125          */
126         noLabel: {
127             validator: Y.Lang.isString,
128             value: M.util.get_string('no', 'moodle')
129         },
131         /**
132          * The title of the dialogue.
133          *
134          * @attribute title
135          * @type String
136          * @default 'Confirm'
137          */
138         title: {
139             validator: Y.Lang.isString,
140             value: M.util.get_string('confirm', 'moodle')
141         },
143         /**
144          * The question posed by the dialogue.
145          *
146          * @attribute question
147          * @type String
148          * @default 'Are you sure?'
149          */
150         question: {
151             validator: Y.Lang.isString,
152             value: M.util.get_string('areyousure', 'moodle')
153         }
154     }
155 });
156 Y.augment(CONFIRM, Y.EventTarget);
158 M.core.confirm = CONFIRM;
161 }, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});