Skip to content

Commit

Permalink
MDL-44855 AJAX: Arrays and Objects should be defined in the initializer
Browse files Browse the repository at this point in the history
JavaScript is a prototypal language and complex types should be defined as
null in the prototype, and set up in the initializer instead.
  • Loading branch information
andrewnicols committed Apr 22, 2014
1 parent d55806c commit f857b66
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ ALERT = function(config) {
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, M.core.notification.info, {
closeEvents: [],
initializer : function() {
/**
* 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>')
Expand All @@ -63,29 +71,29 @@ 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)
);

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();
submit: function() {
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete');
this.hide();
this.destroy();
}
}, {
NAME : ALERT_NAME,
CSS_PREFIX : DIALOGUE_PREFIX,
ATTRS : {
NAME: ALERT_NAME,
CSS_PREFIX: DIALOGUE_PREFIX,
ATTRS: {

/**
* The title of the alert.
Expand All @@ -94,9 +102,9 @@ Y.extend(ALERT, M.core.notification.info, {
* @type String
* @default 'Alert'
*/
title : {
validator : Y.Lang.isString,
value : 'Alert'
title: {
validator: Y.Lang.isString,
value: 'Alert'
},

/**
Expand All @@ -106,9 +114,9 @@ Y.extend(ALERT, M.core.notification.info, {
* @type String
* @default 'Confirm'
*/
message : {
validator : Y.Lang.isString,
value : 'Confirm'
message: {
validator: Y.Lang.isString,
value: 'Confirm'
},

/**
Expand All @@ -118,15 +126,15 @@ Y.extend(ALERT, M.core.notification.info, {
* @type String
* @default 'Ok'
*/
yesLabel : {
validator : Y.Lang.isString,
setter : function(txt) {
yesLabel: {
validator: Y.Lang.isString,
setter: function(txt) {
if (!txt) {
txt = 'Ok';
}
return txt;
},
value : 'Ok'
value: 'Ok'
}
}
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ ALERT = function(config) {
ALERT.superclass.constructor.apply(this, [config]);
};
Y.extend(ALERT, M.core.notification.info, {
closeEvents: [],
initializer : function() {
/**
* 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>')
Expand All @@ -63,29 +71,29 @@ 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)
);

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();
submit: function() {
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete');
this.hide();
this.destroy();
}
}, {
NAME : ALERT_NAME,
CSS_PREFIX : DIALOGUE_PREFIX,
ATTRS : {
NAME: ALERT_NAME,
CSS_PREFIX: DIALOGUE_PREFIX,
ATTRS: {

/**
* The title of the alert.
Expand All @@ -94,9 +102,9 @@ Y.extend(ALERT, M.core.notification.info, {
* @type String
* @default 'Alert'
*/
title : {
validator : Y.Lang.isString,
value : 'Alert'
title: {
validator: Y.Lang.isString,
value: 'Alert'
},

/**
Expand All @@ -106,9 +114,9 @@ Y.extend(ALERT, M.core.notification.info, {
* @type String
* @default 'Confirm'
*/
message : {
validator : Y.Lang.isString,
value : 'Confirm'
message: {
validator: Y.Lang.isString,
value: 'Confirm'
},

/**
Expand All @@ -118,15 +126,15 @@ Y.extend(ALERT, M.core.notification.info, {
* @type String
* @default 'Ok'
*/
yesLabel : {
validator : Y.Lang.isString,
setter : function(txt) {
yesLabel: {
validator: Y.Lang.isString,
setter: function(txt) {
if (!txt) {
txt = 'Ok';
}
return txt;
},
value : 'Ok'
value: 'Ok'
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ CONFIRM = function(config) {
CONFIRM.superclass.constructor.apply(this, [config]);
};
Y.extend(CONFIRM, M.core.notification.info, {
closeEvents: [],
initializer : function() {
/**
* 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');
Expand All @@ -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)
Expand All @@ -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();
submit: function(e, outcome) {
new Y.EventHandle(this._closeEvents).detach();
this.fire('complete', outcome);
if (outcome) {
this.fire('complete-yes');
Expand All @@ -92,9 +100,9 @@ Y.extend(CONFIRM, M.core.notification.info, {
this.destroy();
}
}, {
NAME : CONFIRM_NAME,
CSS_PREFIX : DIALOGUE_PREFIX,
ATTRS : {
NAME: CONFIRM_NAME,
CSS_PREFIX: DIALOGUE_PREFIX,
ATTRS: {

/**
* The button text to use to accept the confirmation.
Expand All @@ -103,9 +111,9 @@ Y.extend(CONFIRM, M.core.notification.info, {
* @type String
* @default 'Yes'
*/
yesLabel : {
validator : Y.Lang.isString,
value : 'Yes'
yesLabel: {
validator: Y.Lang.isString,
value: 'Yes'
},

/**
Expand All @@ -115,9 +123,9 @@ Y.extend(CONFIRM, M.core.notification.info, {
* @type String
* @default 'No'
*/
noLabel : {
validator : Y.Lang.isString,
value : 'No'
noLabel: {
validator: Y.Lang.isString,
value: 'No'
},

/**
Expand All @@ -127,9 +135,9 @@ Y.extend(CONFIRM, M.core.notification.info, {
* @type String
* @default 'Confirm'
*/
title : {
validator : Y.Lang.isString,
value : 'Confirm'
title: {
validator: Y.Lang.isString,
value: 'Confirm'
},

/**
Expand All @@ -139,9 +147,9 @@ Y.extend(CONFIRM, M.core.notification.info, {
* @type String
* @default 'Are you sure?'
*/
question : {
validator : Y.Lang.isString,
value : 'Are you sure?'
question: {
validator: Y.Lang.isString,
value: 'Are you sure?'
}
}
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f857b66

Please sign in to comment.