MDL-44855 AJAX: Arrays and Objects should be defined in the initializer

JavaScript is a prototypal language and complex types should be defined as
null in the prototype, and set up in the initializer instead.
This commit is contained in:
Andrew Nicols 2014-04-22 16:48:02 +08:00
parent d55806ce05
commit f857b668f9
8 changed files with 170 additions and 122 deletions

View File

@ -50,8 +50,16 @@ ALERT = function(config) {
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, M.core.notification.info, {
closeEvents: [],
/**
* The list of events to detach when destroying this dialogue.
*
* @property _closeEvents
* @type EventHandle[]
* @private
*/
_closeEvents: null,
initializer: function() {
this._closeEvents = [];
this.publish('complete');
var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
content = Y.Node.create('<div class="confirmation-dialogue"></div>')
@ -63,7 +71,7 @@ Y.extend(ALERT, M.core.notification.info, {
this.setStdModContent(Y.WidgetStdMod.HEADER,
'<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
this.closeEvents.push(
this._closeEvents.push(
Y.on('key', this.submit, window, 'down:13', this),
yes.on('click', this.submit, this)
);
@ -71,13 +79,13 @@ Y.extend(ALERT, M.core.notification.info, {
var closeButton = this.get('boundingBox').one('.closebutton');
if (closeButton) {
// The close button should act exactly like the 'No' button.
this.closeEvents.push(
this._closeEvents.push(
closeButton.on('click', this.submit, this)
);
}
},
submit: function() {
new Y.EventHandle(this.closeEvents).detach();
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete');
this.hide();
this.destroy();

View File

@ -1 +1 @@
YUI.add("moodle-core-notification-alert",function(e,t){var n,r,i,s,o,u,a;n="moodle-dialogue",r="notificationBase",i="yesLabel",s="noLabel",o="title",u="question",a={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var f="Moodle alert",l;l=function(e){e.closeButton=!1,l.superclass.constructor.apply(this,[e])},e.extend(l,M.core.notification.info,{closeEvents:[],initializer:function(){this.publish("complete");var t=e.Node.create('<input type="button" id="id_yuialertconfirm-'+this.get("COUNT")+'" value="'+this.get(i)+'" />'),n=e.Node.create('<div class="confirmation-dialogue"></div>').append(e.Node.create('<div class="confirmation-message">'+this.get("message")+"</div>")).append(e.Node.create('<div class="confirmation-buttons"></div>').append(t));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'<h1 id="moodle-dialogue-'+this.get("COUNT")+'-header-text">'+this.get(o)+"</h1>",e.WidgetStdMod.REPLACE),this.closeEvents.push(e.on("key",this.submit,window,"down:13",this),t.on("click",this.submit,this));var s=this.get("boundingBox").one(".closebutton");s&&this.closeEvents.push(s.on("click",this.submit,this))},submit:function(){(new e.EventHandle(this.closeEvents)).detach(),this.fire("complete"),this.hide(),this.destroy()}},{NAME:f,CSS_PREFIX:n,ATTRS:{title:{validator:e.Lang.isString,value:"Alert"},message:{validator:e.Lang.isString,value:"Confirm"},yesLabel:{validator:e.Lang.isString,setter:function(e){return e||(e="Ok"),e},value:"Ok"}}}),M.core.alert=l},"@VERSION@",{requires:["moodle-core-notification-dialogue"]});
YUI.add("moodle-core-notification-alert",function(e,t){var n,r,i,s,o,u,a;n="moodle-dialogue",r="notificationBase",i="yesLabel",s="noLabel",o="title",u="question",a={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var f="Moodle alert",l;l=function(e){e.closeButton=!1,l.superclass.constructor.apply(this,[e])},e.extend(l,M.core.notification.info,{_closeEvents:null,initializer:function(){this._closeEvents=[],this.publish("complete");var t=e.Node.create('<input type="button" id="id_yuialertconfirm-'+this.get("COUNT")+'" value="'+this.get(i)+'" />'),n=e.Node.create('<div class="confirmation-dialogue"></div>').append(e.Node.create('<div class="confirmation-message">'+this.get("message")+"</div>")).append(e.Node.create('<div class="confirmation-buttons"></div>').append(t));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'<h1 id="moodle-dialogue-'+this.get("COUNT")+'-header-text">'+this.get(o)+"</h1>",e.WidgetStdMod.REPLACE),this._closeEvents.push(e.on("key",this.submit,window,"down:13",this),t.on("click",this.submit,this));var s=this.get("boundingBox").one(".closebutton");s&&this._closeEvents.push(s.on("click",this.submit,this))},submit:function(){(new e.EventHandle(this._closeEvents)).detach(),this.fire("complete"),this.hide(),this.destroy()}},{NAME:f,CSS_PREFIX:n,ATTRS:{title:{validator:e.Lang.isString,value:"Alert"},message:{validator:e.Lang.isString,value:"Confirm"},yesLabel:{validator:e.Lang.isString,setter:function(e){return e||(e="Ok"),e},value:"Ok"}}}),M.core.alert=l},"@VERSION@",{requires:["moodle-core-notification-dialogue"]});

View File

@ -50,8 +50,16 @@ ALERT = function(config) {
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, M.core.notification.info, {
closeEvents: [],
/**
* The list of events to detach when destroying this dialogue.
*
* @property _closeEvents
* @type EventHandle[]
* @private
*/
_closeEvents: null,
initializer: function() {
this._closeEvents = [];
this.publish('complete');
var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
content = Y.Node.create('<div class="confirmation-dialogue"></div>')
@ -63,7 +71,7 @@ Y.extend(ALERT, M.core.notification.info, {
this.setStdModContent(Y.WidgetStdMod.HEADER,
'<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
this.closeEvents.push(
this._closeEvents.push(
Y.on('key', this.submit, window, 'down:13', this),
yes.on('click', this.submit, this)
);
@ -71,13 +79,13 @@ Y.extend(ALERT, M.core.notification.info, {
var closeButton = this.get('boundingBox').one('.closebutton');
if (closeButton) {
// The close button should act exactly like the 'No' button.
this.closeEvents.push(
this._closeEvents.push(
closeButton.on('click', this.submit, this)
);
}
},
submit: function() {
new Y.EventHandle(this.closeEvents).detach();
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete');
this.hide();
this.destroy();

View File

@ -49,8 +49,16 @@ CONFIRM = function(config) {
CONFIRM.superclass.constructor.apply(this, [config]);
};
Y.extend(CONFIRM, M.core.notification.info, {
closeEvents: [],
/**
* The list of events to detach when destroying this dialogue.
*
* @property _closeEvents
* @type EventHandle[]
* @private
*/
_closeEvents: null,
initializer: function() {
this._closeEvents = [];
this.publish('complete');
this.publish('complete-yes');
this.publish('complete-no');
@ -66,7 +74,7 @@ Y.extend(CONFIRM, M.core.notification.info, {
this.setStdModContent(Y.WidgetStdMod.HEADER,
'<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
this.closeEvents.push(
this._closeEvents.push(
Y.on('key', this.submit, window, 'down:27', this, false),
yes.on('click', this.submit, this, true),
no.on('click', this.submit, this, false)
@ -75,13 +83,13 @@ Y.extend(CONFIRM, M.core.notification.info, {
var closeButton = this.get('boundingBox').one('.closebutton');
if (closeButton) {
// The close button should act exactly like the 'No' button.
this.closeEvents.push(
this._closeEvents.push(
closeButton.on('click', this.submit, this)
);
}
},
submit: function(e, outcome) {
new Y.EventHandle(this.closeEvents).detach();
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete', outcome);
if (outcome) {
this.fire('complete-yes');

View File

@ -1 +1 @@
YUI.add("moodle-core-notification-confirm",function(e,t){var n,r,i,s,o,u,a;n="moodle-dialogue",r="notificationBase",i="yesLabel",s="noLabel",o="title",u="question",a={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var f="Moodle confirmation dialogue",l;l=function(e){l.superclass.constructor.apply(this,[e])},e.extend(l,M.core.notification.info,{closeEvents:[],initializer:function(){this.publish("complete"),this.publish("complete-yes"),this.publish("complete-no");var t=e.Node.create('<input type="button" id="id_yuiconfirmyes-'+this.get("COUNT")+'" value="'+this.get(i)+'" />'),n=e.Node.create('<input type="button" id="id_yuiconfirmno-'+this.get("COUNT")+'" value="'+this.get(s)+'" />'),a=e.Node.create('<div class="confirmation-dialogue"></div>').append(e.Node.create('<div class="confirmation-message">'+this.get(u)+"</div>")).append(e.Node.create('<div class="confirmation-buttons"></div>').append(t).append(n));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,a,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'<h1 id="moodle-dialogue-'+this.get("COUNT")+'-header-text">'+this.get(o)+"</h1>",e.WidgetStdMod.REPLACE),this.closeEvents.push(e.on("key",this.submit,window,"down:27",this,!1),t.on("click",this.submit,this,!0),n.on("click",this.submit,this,!1));var f=this.get("boundingBox").one(".closebutton");f&&this.closeEvents.push(f.on("click",this.submit,this))},submit:function(t,n){(new e.EventHandle(this.closeEvents)).detach(),this.fire("complete",n),n?this.fire("complete-yes"):this.fire("complete-no"),this.hide(),this.destroy()}},{NAME:f,CSS_PREFIX:n,ATTRS:{yesLabel:{validator:e.Lang.isString,value:"Yes"},noLabel:{validator:e.Lang.isString,value:"No"},title:{validator:e.Lang.isString,value:"Confirm"},question:{validator:e.Lang.isString,value:"Are you sure?"}}}),e.augment(l,e.EventTarget),M.core.confirm=l},"@VERSION@",{requires:["moodle-core-notification-dialogue"]});
YUI.add("moodle-core-notification-confirm",function(e,t){var n,r,i,s,o,u,a;n="moodle-dialogue",r="notificationBase",i="yesLabel",s="noLabel",o="title",u="question",a={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var f="Moodle confirmation dialogue",l;l=function(e){l.superclass.constructor.apply(this,[e])},e.extend(l,M.core.notification.info,{_closeEvents:null,initializer:function(){this._closeEvents=[],this.publish("complete"),this.publish("complete-yes"),this.publish("complete-no");var t=e.Node.create('<input type="button" id="id_yuiconfirmyes-'+this.get("COUNT")+'" value="'+this.get(i)+'" />'),n=e.Node.create('<input type="button" id="id_yuiconfirmno-'+this.get("COUNT")+'" value="'+this.get(s)+'" />'),a=e.Node.create('<div class="confirmation-dialogue"></div>').append(e.Node.create('<div class="confirmation-message">'+this.get(u)+"</div>")).append(e.Node.create('<div class="confirmation-buttons"></div>').append(t).append(n));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,a,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'<h1 id="moodle-dialogue-'+this.get("COUNT")+'-header-text">'+this.get(o)+"</h1>",e.WidgetStdMod.REPLACE),this._closeEvents.push(e.on("key",this.submit,window,"down:27",this,!1),t.on("click",this.submit,this,!0),n.on("click",this.submit,this,!1));var f=this.get("boundingBox").one(".closebutton");f&&this._closeEvents.push(f.on("click",this.submit,this))},submit:function(t,n){(new e.EventHandle(this._closeEvents)).detach(),this.fire("complete",n),n?this.fire("complete-yes"):this.fire("complete-no"),this.hide(),this.destroy()}},{NAME:f,CSS_PREFIX:n,ATTRS:{yesLabel:{validator:e.Lang.isString,value:"Yes"},noLabel:{validator:e.Lang.isString,value:"No"},title:{validator:e.Lang.isString,value:"Confirm"},question:{validator:e.Lang.isString,value:"Are you sure?"}}}),e.augment(l,e.EventTarget),M.core.confirm=l},"@VERSION@",{requires:["moodle-core-notification-dialogue"]});

View File

@ -49,8 +49,16 @@ CONFIRM = function(config) {
CONFIRM.superclass.constructor.apply(this, [config]);
};
Y.extend(CONFIRM, M.core.notification.info, {
closeEvents: [],
/**
* The list of events to detach when destroying this dialogue.
*
* @property _closeEvents
* @type EventHandle[]
* @private
*/
_closeEvents: null,
initializer: function() {
this._closeEvents = [];
this.publish('complete');
this.publish('complete-yes');
this.publish('complete-no');
@ -66,7 +74,7 @@ Y.extend(CONFIRM, M.core.notification.info, {
this.setStdModContent(Y.WidgetStdMod.HEADER,
'<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
this.closeEvents.push(
this._closeEvents.push(
Y.on('key', this.submit, window, 'down:27', this, false),
yes.on('click', this.submit, this, true),
no.on('click', this.submit, this, false)
@ -75,13 +83,13 @@ Y.extend(CONFIRM, M.core.notification.info, {
var closeButton = this.get('boundingBox').one('.closebutton');
if (closeButton) {
// The close button should act exactly like the 'No' button.
this.closeEvents.push(
this._closeEvents.push(
closeButton.on('click', this.submit, this)
);
}
},
submit: function(e, outcome) {
new Y.EventHandle(this.closeEvents).detach();
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete', outcome);
if (outcome) {
this.fire('complete-yes');

View File

@ -21,8 +21,16 @@ ALERT = function(config) {
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, M.core.notification.info, {
closeEvents: [],
/**
* The list of events to detach when destroying this dialogue.
*
* @property _closeEvents
* @type EventHandle[]
* @private
*/
_closeEvents: null,
initializer: function() {
this._closeEvents = [];
this.publish('complete');
var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />'),
content = Y.Node.create('<div class="confirmation-dialogue"></div>')
@ -34,7 +42,7 @@ Y.extend(ALERT, M.core.notification.info, {
this.setStdModContent(Y.WidgetStdMod.HEADER,
'<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
this.closeEvents.push(
this._closeEvents.push(
Y.on('key', this.submit, window, 'down:13', this),
yes.on('click', this.submit, this)
);
@ -42,13 +50,13 @@ Y.extend(ALERT, M.core.notification.info, {
var closeButton = this.get('boundingBox').one('.closebutton');
if (closeButton) {
// The close button should act exactly like the 'No' button.
this.closeEvents.push(
this._closeEvents.push(
closeButton.on('click', this.submit, this)
);
}
},
submit: function() {
new Y.EventHandle(this.closeEvents).detach();
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete');
this.hide();
this.destroy();

View File

@ -20,8 +20,16 @@ CONFIRM = function(config) {
CONFIRM.superclass.constructor.apply(this, [config]);
};
Y.extend(CONFIRM, M.core.notification.info, {
closeEvents: [],
/**
* The list of events to detach when destroying this dialogue.
*
* @property _closeEvents
* @type EventHandle[]
* @private
*/
_closeEvents: null,
initializer: function() {
this._closeEvents = [];
this.publish('complete');
this.publish('complete-yes');
this.publish('complete-no');
@ -37,7 +45,7 @@ Y.extend(CONFIRM, M.core.notification.info, {
this.setStdModContent(Y.WidgetStdMod.HEADER,
'<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
this.closeEvents.push(
this._closeEvents.push(
Y.on('key', this.submit, window, 'down:27', this, false),
yes.on('click', this.submit, this, true),
no.on('click', this.submit, this, false)
@ -46,13 +54,13 @@ Y.extend(CONFIRM, M.core.notification.info, {
var closeButton = this.get('boundingBox').one('.closebutton');
if (closeButton) {
// The close button should act exactly like the 'No' button.
this.closeEvents.push(
this._closeEvents.push(
closeButton.on('click', this.submit, this)
);
}
},
submit: function(e, outcome) {
new Y.EventHandle(this.closeEvents).detach();
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete', outcome);
if (outcome) {
this.fire('complete-yes');