From cf93e03ea048cce74ddc2def0a048ee949228513 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 30 May 2014 00:11:24 +0800 Subject: [PATCH] MDL-45759 javascript: Handle setting of the confirm button fields post-init --- .../moodle-core-notification-confirm-debug.js | 75 ++++++++++++++++--- .../moodle-core-notification-confirm-min.js | 2 +- .../moodle-core-notification-confirm.js | 75 ++++++++++++++++--- lib/yui/src/notification/js/confirm.js | 75 ++++++++++++++++--- 4 files changed, 193 insertions(+), 34 deletions(-) diff --git a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js index 6348d4d11d1..ea014f2e5e5 100644 --- a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js @@ -57,18 +57,47 @@ Y.extend(CONFIRM, M.core.notification.info, { * @private */ _closeEvents: null, + + /** + * A reference to the yes button. + * + * @property _yesButton + * @type Node + * @private + */ + _yesButton: null, + + /** + * A reference to the No button. + * + * @property _noButton + * @type Node + * @private + */ + _noButton: null, + + /** + * A reference to the Question. + * + * @property _question + * @type Node + * @private + */ + _question: null, + initializer: function() { this._closeEvents = []; this.publish('complete'); this.publish('complete-yes'); this.publish('complete-no'); - var yes = Y.Node.create(''), - no = Y.Node.create(''), - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get(QUESTION)+'
')) + this._yesButton = Y.Node.create(''); + this._noButton = Y.Node.create(''); + this._question = Y.Node.create('
' + this.get(QUESTION) + '
'); + var content = Y.Node.create('
') + .append(this._question) .append(Y.Node.create('
') - .append(yes) - .append(no)); + .append(this._yesButton) + .append(this._noButton)); this.get(BASE).addClass('moodle-dialogue-confirm'); this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); this.setStdModContent(Y.WidgetStdMod.HEADER, @@ -76,8 +105,8 @@ Y.extend(CONFIRM, M.core.notification.info, { 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) + this._yesButton.on('click', this.submit, this, true), + this._noButton.on('click', this.submit, this, false) ); var closeButton = this.get('boundingBox').one('.closebutton'); @@ -113,7 +142,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ yesLabel: { validator: Y.Lang.isString, - value: M.util.get_string('yes', 'moodle') + valueFn: function() { + return M.util.get_string('yes', 'moodle'); + }, + setter: function(value) { + if (this._yesButton) { + this._yesButton.set('value', value); + } + return value; + } }, /** @@ -125,7 +162,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ noLabel: { validator: Y.Lang.isString, - value: M.util.get_string('no', 'moodle') + valueFn: function() { + return M.util.get_string('no', 'moodle'); + }, + setter: function(value) { + if (this._noButton) { + this._noButton.set('value', value); + } + return value; + } }, /** @@ -149,7 +194,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ question: { validator: Y.Lang.isString, - value: M.util.get_string('areyousure', 'moodle') + valueFn: function() { + return M.util.get_string('areyousure', 'moodle'); + }, + setter: function(value) { + if (this._question) { + this._question.set('value', value); + } + return value; + } } } }); diff --git a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js index 3d45e820d84..ee9b63b2601 100644 --- a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js @@ -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:null,initializer:function(){this._closeEvents=[],this.publish("complete"),this.publish("complete-yes"),this.publish("complete-no");var t=e.Node.create(''),n=e.Node.create(''),a=e.Node.create('
').append(e.Node.create('
'+this.get(u)+"
")).append(e.Node.create('
').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,'

'+this.get(o)+"

",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:M.util.get_string("yes","moodle")},noLabel:{validator:e.Lang.isString,value:M.util.get_string("no","moodle")},title:{validator:e.Lang.isString,value:M.util.get_string("confirm","moodle")},question:{validator:e.Lang.isString,value:M.util.get_string("areyousure","moodle")}}}),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,_yesButton:null,_noButton:null,_question:null,initializer:function(){this._closeEvents=[],this.publish("complete"),this.publish("complete-yes"),this.publish("complete-no"),this._yesButton=e.Node.create(''),this._noButton=e.Node.create(''),this._question=e.Node.create('
'+this.get(u)+"
");var t=e.Node.create('
').append(this._question).append(e.Node.create('
').append(this._yesButton).append(this._noButton));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,t,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(o)+"

",e.WidgetStdMod.REPLACE),this._closeEvents.push(e.on("key",this.submit,window,"down:27",this,!1),this._yesButton.on("click",this.submit,this,!0),this._noButton.on("click",this.submit,this,!1));var n=this.get("boundingBox").one(".closebutton");n&&this._closeEvents.push(n.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,valueFn:function(){return M.util.get_string("yes","moodle")},setter:function(e){return this._yesButton&&this._yesButton.set("value",e),e}},noLabel:{validator:e.Lang.isString,valueFn:function(){return M.util.get_string("no","moodle")},setter:function(e){return this._noButton&&this._noButton.set("value",e),e}},title:{validator:e.Lang.isString,value:M.util.get_string("confirm","moodle")},question:{validator:e.Lang.isString,valueFn:function(){return M.util.get_string("areyousure","moodle")},setter:function(e){return this._question&&this._question.set("value",e),e}}}}),e.augment(l,e.EventTarget),M.core.confirm=l},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js index 6348d4d11d1..ea014f2e5e5 100644 --- a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js @@ -57,18 +57,47 @@ Y.extend(CONFIRM, M.core.notification.info, { * @private */ _closeEvents: null, + + /** + * A reference to the yes button. + * + * @property _yesButton + * @type Node + * @private + */ + _yesButton: null, + + /** + * A reference to the No button. + * + * @property _noButton + * @type Node + * @private + */ + _noButton: null, + + /** + * A reference to the Question. + * + * @property _question + * @type Node + * @private + */ + _question: null, + initializer: function() { this._closeEvents = []; this.publish('complete'); this.publish('complete-yes'); this.publish('complete-no'); - var yes = Y.Node.create(''), - no = Y.Node.create(''), - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get(QUESTION)+'
')) + this._yesButton = Y.Node.create(''); + this._noButton = Y.Node.create(''); + this._question = Y.Node.create('
' + this.get(QUESTION) + '
'); + var content = Y.Node.create('
') + .append(this._question) .append(Y.Node.create('
') - .append(yes) - .append(no)); + .append(this._yesButton) + .append(this._noButton)); this.get(BASE).addClass('moodle-dialogue-confirm'); this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); this.setStdModContent(Y.WidgetStdMod.HEADER, @@ -76,8 +105,8 @@ Y.extend(CONFIRM, M.core.notification.info, { 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) + this._yesButton.on('click', this.submit, this, true), + this._noButton.on('click', this.submit, this, false) ); var closeButton = this.get('boundingBox').one('.closebutton'); @@ -113,7 +142,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ yesLabel: { validator: Y.Lang.isString, - value: M.util.get_string('yes', 'moodle') + valueFn: function() { + return M.util.get_string('yes', 'moodle'); + }, + setter: function(value) { + if (this._yesButton) { + this._yesButton.set('value', value); + } + return value; + } }, /** @@ -125,7 +162,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ noLabel: { validator: Y.Lang.isString, - value: M.util.get_string('no', 'moodle') + valueFn: function() { + return M.util.get_string('no', 'moodle'); + }, + setter: function(value) { + if (this._noButton) { + this._noButton.set('value', value); + } + return value; + } }, /** @@ -149,7 +194,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ question: { validator: Y.Lang.isString, - value: M.util.get_string('areyousure', 'moodle') + valueFn: function() { + return M.util.get_string('areyousure', 'moodle'); + }, + setter: function(value) { + if (this._question) { + this._question.set('value', value); + } + return value; + } } } }); diff --git a/lib/yui/src/notification/js/confirm.js b/lib/yui/src/notification/js/confirm.js index d2e640be212..798e49914f4 100644 --- a/lib/yui/src/notification/js/confirm.js +++ b/lib/yui/src/notification/js/confirm.js @@ -28,18 +28,47 @@ Y.extend(CONFIRM, M.core.notification.info, { * @private */ _closeEvents: null, + + /** + * A reference to the yes button. + * + * @property _yesButton + * @type Node + * @private + */ + _yesButton: null, + + /** + * A reference to the No button. + * + * @property _noButton + * @type Node + * @private + */ + _noButton: null, + + /** + * A reference to the Question. + * + * @property _question + * @type Node + * @private + */ + _question: null, + initializer: function() { this._closeEvents = []; this.publish('complete'); this.publish('complete-yes'); this.publish('complete-no'); - var yes = Y.Node.create(''), - no = Y.Node.create(''), - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get(QUESTION)+'
')) + this._yesButton = Y.Node.create(''); + this._noButton = Y.Node.create(''); + this._question = Y.Node.create('
' + this.get(QUESTION) + '
'); + var content = Y.Node.create('
') + .append(this._question) .append(Y.Node.create('
') - .append(yes) - .append(no)); + .append(this._yesButton) + .append(this._noButton)); this.get(BASE).addClass('moodle-dialogue-confirm'); this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); this.setStdModContent(Y.WidgetStdMod.HEADER, @@ -47,8 +76,8 @@ Y.extend(CONFIRM, M.core.notification.info, { 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) + this._yesButton.on('click', this.submit, this, true), + this._noButton.on('click', this.submit, this, false) ); var closeButton = this.get('boundingBox').one('.closebutton'); @@ -84,7 +113,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ yesLabel: { validator: Y.Lang.isString, - value: M.util.get_string('yes', 'moodle') + valueFn: function() { + return M.util.get_string('yes', 'moodle'); + }, + setter: function(value) { + if (this._yesButton) { + this._yesButton.set('value', value); + } + return value; + } }, /** @@ -96,7 +133,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ noLabel: { validator: Y.Lang.isString, - value: M.util.get_string('no', 'moodle') + valueFn: function() { + return M.util.get_string('no', 'moodle'); + }, + setter: function(value) { + if (this._noButton) { + this._noButton.set('value', value); + } + return value; + } }, /** @@ -120,7 +165,15 @@ Y.extend(CONFIRM, M.core.notification.info, { */ question: { validator: Y.Lang.isString, - value: M.util.get_string('areyousure', 'moodle') + valueFn: function() { + return M.util.get_string('areyousure', 'moodle'); + }, + setter: function(value) { + if (this._question) { + this._question.set('value', value); + } + return value; + } } } });