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