From 7868699535a6fc2527fc03e500e09eb4c011cc6f Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 15 Jul 2013 23:44:17 +0100 Subject: [PATCH] MDL-40678 JavaScript: Split out moodle-core-notification into submodules --- lib/upgrade.txt | 10 + ...e-core-notification-ajaxexception-debug.js | 170 +++++++ ...dle-core-notification-ajaxexception-min.js | 1 + .../moodle-core-notification-ajaxexception.js | 170 +++++++ .../moodle-core-notification-alert-debug.js | 129 ++++++ .../moodle-core-notification-alert-min.js | 1 + .../moodle-core-notification-alert.js | 129 ++++++ .../moodle-core-notification-confirm-debug.js | 148 ++++++ .../moodle-core-notification-confirm-min.js | 1 + .../moodle-core-notification-confirm.js | 148 ++++++ ...moodle-core-notification-dialogue-debug.js | 214 +++++++++ .../moodle-core-notification-dialogue-min.js | 1 + .../moodle-core-notification-dialogue.js | 214 +++++++++ ...oodle-core-notification-exception-debug.js | 183 ++++++++ .../moodle-core-notification-exception-min.js | 1 + .../moodle-core-notification-exception.js | 183 ++++++++ .../moodle-core-notification-debug.js | 434 ++---------------- .../moodle-core-notification-min.js | 3 +- .../moodle-core-notification.js | 432 ++--------------- lib/yui/src/notification/build.json | 30 ++ lib/yui/src/notification/js/ajaxexception.js | 136 ++++++ lib/yui/src/notification/js/alert.js | 95 ++++ lib/yui/src/notification/js/confirm.js | 114 +++++ lib/yui/src/notification/js/dialogue.js | 180 ++++++++ lib/yui/src/notification/js/exception.js | 149 ++++++ lib/yui/src/notification/js/notification.js | 426 +---------------- lib/yui/src/notification/js/shared.js | 29 ++ .../src/notification/meta/notification.json | 29 ++ 28 files changed, 2552 insertions(+), 1208 deletions(-) create mode 100644 lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-debug.js create mode 100644 lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-min.js create mode 100644 lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception.js create mode 100644 lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js create mode 100644 lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-min.js create mode 100644 lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js create mode 100644 lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js create mode 100644 lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js create mode 100644 lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js create mode 100644 lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js create mode 100644 lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-min.js create mode 100644 lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue.js create mode 100644 lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js create mode 100644 lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-min.js create mode 100644 lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js create mode 100644 lib/yui/src/notification/js/ajaxexception.js create mode 100644 lib/yui/src/notification/js/alert.js create mode 100644 lib/yui/src/notification/js/confirm.js create mode 100644 lib/yui/src/notification/js/dialogue.js create mode 100644 lib/yui/src/notification/js/exception.js create mode 100644 lib/yui/src/notification/js/shared.js diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 4c865c0c853..4430ab36577 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -78,6 +78,16 @@ Misc: * detect_munged_arguments() -> clean_param([...], PARAM_FILE) * mygroupid() -> groups_get_all_groups() +YUI: + * moodle-core-notification has been deprecated with a recommendation of + using its subclasses intead. This is to allow for reduced page + transport costs. Current subclasses include: + * dialogue + * alert + * confirm + * exception + * ajaxexception + === 2.5.1 === * New get_course() function for use when obtaining the course record from database. Will diff --git a/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-debug.js b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-debug.js new file mode 100644 index 00000000000..10c9edf4634 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-debug.js @@ -0,0 +1,170 @@ +YUI.add('moodle-core-notification-ajaxexception', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * A dialogue type designed to display an appropriate error when an error + * thrown in the Moodle codebase was reported during an AJAX request. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-ajaxexception + */ + +var AJAXEXCEPTION_NAME = 'Moodle AJAX exception', + AJAXEXCEPTION; + +/** + * Extends core Dialogue to show the exception dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.ajaxException + * @extends M.core.dialogue + */ +AJAXEXCEPTION = function(config) { + config.name = config.name || 'Error'; + config.closeButton = true; + AJAXEXCEPTION.superclass.constructor.apply(this, [config]); +}; +Y.extend(AJAXEXCEPTION, M.core.dialogue, { + _keypress : null, + initializer : function(config) { + var content, + self = this, + delay = this.get('hideTimeoutDelay'); + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + config.name + '

', Y.WidgetStdMod.REPLACE); + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('error')+'
')) + .append(Y.Node.create('')) + .append(Y.Node.create('')) + .append(Y.Node.create('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + if (delay) { + this._hideTimeout = setTimeout(function(){self.hide();}, delay); + } + this.after('visibleChange', this.visibilityChanged, this); + this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this); + this.centerDialogue(); + }, + visibilityChanged : function(e) { + if (e.attrName === 'visible' && e.prevVal && !e.newVal) { + var self = this; + this._keypress.detach(); + setTimeout(function(){self.destroy();}, 1000); + } + } +}, { + NAME : AJAXEXCEPTION_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The error message given in the exception. + * + * @attribute error + * @type String + * @default 'Unknown error' + * @optional + */ + error : { + validator : Y.Lang.isString, + value : 'Unknown error' + }, + + /** + * Any additional debug information given in the exception. + * + * @attribute stacktrace + * @type String|null + * @default null + * @optional + */ + debuginfo : { + value : null + }, + + /** + * The complete stack trace provided in the exception. + * + * @attribute stacktrace + * @type String|null + * @default null + * @optional + */ + stacktrace : { + value : null + }, + + /** + * A link which may be used by support staff to replicate the issue. + * + * @attribute reproductionlink + * @type String + * @default null + * @optional + */ + reproductionlink : { + setter : function(link) { + if (link !== null) { + link = ''+link.replace(M.cfg.wwwroot, '')+''; + } + return link; + }, + value : null + }, + + /** + * If set, the dialogue is hidden after the specified timeout period. + * + * @attribute hideTimeoutDelay + * @type Number + * @default null + * @optional + */ + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +M.core.ajaxException = AJAXEXCEPTION; + + +}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-min.js b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-min.js new file mode 100644 index 00000000000..21c6f277d41 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-min.js @@ -0,0 +1 @@ +YUI.add("moodle-core-notification-ajaxexception",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={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 l="Moodle AJAX exception",c;c=function(e){e.name=e.name||"Error",e.closeButton=!0,c.superclass.constructor.apply(this,[e])},e.extend(c,M.core.dialogue,{_keypress:null,initializer:function(t){var n,i=this,s=this.get("hideTimeoutDelay");this.get(r).addClass("moodle-dialogue-exception"),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+t.name+"

",e.WidgetStdMod.REPLACE),n=e.Node.create('
').append(e.Node.create('
'+this.get("error")+"
")).append(e.Node.create('")).append(e.Node.create('")).append(e.Node.create('")),M.cfg.developerdebug&&n.all(".moodle-exception-param").removeClass("hidden"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),s&&(this._hideTimeout=setTimeout(function(){i.hide()},s)),this.after("visibleChange",this.visibilityChanged,this),this._keypress=e.on("key",this.hide,window,"down:13, 27",this),this.centerDialogue()},visibilityChanged:function(e){if(e.attrName==="visible"&&e.prevVal&&!e.newVal){var t=this;this._keypress.detach(),setTimeout(function(){t.destroy()},1e3)}}},{NAME:l,CSS_PREFIX:n,ATTRS:{error:{validator:e.Lang.isString,value:"Unknown error"},debuginfo:{value:null},stacktrace:{value:null},reproductionlink:{setter:function(e){return e!==null&&(e=''+e.replace(M.cfg.wwwroot,"")+""),e},value:null},hideTimeoutDelay:{validator:e.Lang.isNumber,value:null}}}),M.core.ajaxException=c},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception.js b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception.js new file mode 100644 index 00000000000..10c9edf4634 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception.js @@ -0,0 +1,170 @@ +YUI.add('moodle-core-notification-ajaxexception', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * A dialogue type designed to display an appropriate error when an error + * thrown in the Moodle codebase was reported during an AJAX request. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-ajaxexception + */ + +var AJAXEXCEPTION_NAME = 'Moodle AJAX exception', + AJAXEXCEPTION; + +/** + * Extends core Dialogue to show the exception dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.ajaxException + * @extends M.core.dialogue + */ +AJAXEXCEPTION = function(config) { + config.name = config.name || 'Error'; + config.closeButton = true; + AJAXEXCEPTION.superclass.constructor.apply(this, [config]); +}; +Y.extend(AJAXEXCEPTION, M.core.dialogue, { + _keypress : null, + initializer : function(config) { + var content, + self = this, + delay = this.get('hideTimeoutDelay'); + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + config.name + '

', Y.WidgetStdMod.REPLACE); + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('error')+'
')) + .append(Y.Node.create('')) + .append(Y.Node.create('')) + .append(Y.Node.create('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + if (delay) { + this._hideTimeout = setTimeout(function(){self.hide();}, delay); + } + this.after('visibleChange', this.visibilityChanged, this); + this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this); + this.centerDialogue(); + }, + visibilityChanged : function(e) { + if (e.attrName === 'visible' && e.prevVal && !e.newVal) { + var self = this; + this._keypress.detach(); + setTimeout(function(){self.destroy();}, 1000); + } + } +}, { + NAME : AJAXEXCEPTION_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The error message given in the exception. + * + * @attribute error + * @type String + * @default 'Unknown error' + * @optional + */ + error : { + validator : Y.Lang.isString, + value : 'Unknown error' + }, + + /** + * Any additional debug information given in the exception. + * + * @attribute stacktrace + * @type String|null + * @default null + * @optional + */ + debuginfo : { + value : null + }, + + /** + * The complete stack trace provided in the exception. + * + * @attribute stacktrace + * @type String|null + * @default null + * @optional + */ + stacktrace : { + value : null + }, + + /** + * A link which may be used by support staff to replicate the issue. + * + * @attribute reproductionlink + * @type String + * @default null + * @optional + */ + reproductionlink : { + setter : function(link) { + if (link !== null) { + link = ''+link.replace(M.cfg.wwwroot, '')+''; + } + return link; + }, + value : null + }, + + /** + * If set, the dialogue is hidden after the specified timeout period. + * + * @attribute hideTimeoutDelay + * @type Number + * @default null + * @optional + */ + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +M.core.ajaxException = AJAXEXCEPTION; + + +}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js new file mode 100644 index 00000000000..2d90867b424 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js @@ -0,0 +1,129 @@ +YUI.add('moodle-core-notification-alert', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * A dialogue type designed to display an alert to the user. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-alert + */ + +var ALERT_NAME = 'Moodle alert', + ALERT; + +/** + * Extends core Dialogue to show the alert dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.alert + * @extends M.core.dialogue + */ +ALERT = function(config) { + config.closeButton = false; + ALERT.superclass.constructor.apply(this, [config]); +}; +Y.extend(ALERT, M.core.dialogue, { + _enterKeypress : null, + initializer : function() { + this.publish('complete'); + var yes = Y.Node.create(''), + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('message')+'
')) + .append(Y.Node.create('
') + .append(yes)); + this.get(BASE).addClass('moodle-dialogue-confirm'); + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); + yes.on('click', this.submit, this); + }, + submit : function() { + this._enterKeypress.detach(); + this.fire('complete'); + this.hide(); + this.destroy(); + } +}, { + NAME : ALERT_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The title of the alert. + * + * @attribute title + * @type String + * @default 'Alert' + */ + title : { + validator : Y.Lang.isString, + value : 'Alert' + }, + + /** + * The message of the alert. + * + * @attribute message + * @type String + * @default 'Confirm' + */ + message : { + validator : Y.Lang.isString, + value : 'Confirm' + }, + + /** + * The button text to use to accept the alert. + * + * @attribute yesLabel + * @type String + * @default 'Ok' + */ + yesLabel : { + validator : Y.Lang.isString, + setter : function(txt) { + if (!txt) { + txt = 'Ok'; + } + return txt; + }, + value : 'Ok' + } + } +}); + +M.core.alert = ALERT; + + +}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-min.js b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-min.js new file mode 100644 index 00000000000..18a02823ade --- /dev/null +++ b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-min.js @@ -0,0 +1 @@ +YUI.add("moodle-core-notification-alert",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={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 l="Moodle alert",c;c=function(e){e.closeButton=!1,c.superclass.constructor.apply(this,[e])},e.extend(c,M.core.dialogue,{_enterKeypress:null,initializer:function(){this.publish("complete");var t=e.Node.create(''),n=e.Node.create('
').append(e.Node.create('
'+this.get("message")+"
")).append(e.Node.create('
').append(t));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(u)+"

",e.WidgetStdMod.REPLACE),this.after("destroyedChange",function(){this.get(r).remove()},this),this._enterKeypress=e.on("key",this.submit,window,"down:13",this),t.on("click",this.submit,this)},submit:function(){this._enterKeypress.detach(),this.fire("complete"),this.hide(),this.destroy()}},{NAME:l,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=c},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js new file mode 100644 index 00000000000..2d90867b424 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js @@ -0,0 +1,129 @@ +YUI.add('moodle-core-notification-alert', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * A dialogue type designed to display an alert to the user. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-alert + */ + +var ALERT_NAME = 'Moodle alert', + ALERT; + +/** + * Extends core Dialogue to show the alert dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.alert + * @extends M.core.dialogue + */ +ALERT = function(config) { + config.closeButton = false; + ALERT.superclass.constructor.apply(this, [config]); +}; +Y.extend(ALERT, M.core.dialogue, { + _enterKeypress : null, + initializer : function() { + this.publish('complete'); + var yes = Y.Node.create(''), + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('message')+'
')) + .append(Y.Node.create('
') + .append(yes)); + this.get(BASE).addClass('moodle-dialogue-confirm'); + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); + yes.on('click', this.submit, this); + }, + submit : function() { + this._enterKeypress.detach(); + this.fire('complete'); + this.hide(); + this.destroy(); + } +}, { + NAME : ALERT_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The title of the alert. + * + * @attribute title + * @type String + * @default 'Alert' + */ + title : { + validator : Y.Lang.isString, + value : 'Alert' + }, + + /** + * The message of the alert. + * + * @attribute message + * @type String + * @default 'Confirm' + */ + message : { + validator : Y.Lang.isString, + value : 'Confirm' + }, + + /** + * The button text to use to accept the alert. + * + * @attribute yesLabel + * @type String + * @default 'Ok' + */ + yesLabel : { + validator : Y.Lang.isString, + setter : function(txt) { + if (!txt) { + txt = 'Ok'; + } + return txt; + }, + value : 'Ok' + } + } +}); + +M.core.alert = ALERT; + + +}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]}); 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 new file mode 100644 index 00000000000..cf8103cccdf --- /dev/null +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js @@ -0,0 +1,148 @@ +YUI.add('moodle-core-notification-confirm', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * A dialogue type designed to display a confirmation to the user. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-confirm + */ + +var CONFIRM_NAME = 'Moodle confirmation dialogue', + CONFIRM; + +/** + * Extends core Dialogue to show the confirmation dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.confirm + * @extends M.core.dialogue + */ +CONFIRM = function(config) { + CONFIRM.superclass.constructor.apply(this, [config]); +}; +Y.extend(CONFIRM, M.core.dialogue, { + _enterKeypress : null, + _escKeypress : null, + initializer : function() { + 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)+'
')) + .append(Y.Node.create('
') + .append(yes) + .append(no)); + this.get(BASE).addClass('moodle-dialogue-confirm'); + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); + this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); + yes.on('click', this.submit, this, true); + no.on('click', this.submit, this, false); + }, + submit : function(e, outcome) { + this._enterKeypress.detach(); + this._escKeypress.detach(); + this.fire('complete', outcome); + if (outcome) { + this.fire('complete-yes'); + } else { + this.fire('complete-no'); + } + this.hide(); + this.destroy(); + } +}, { + NAME : CONFIRM_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The button text to use to accept the confirmation. + * + * @attribute yesLabel + * @type String + * @default 'Yes' + */ + yesLabel : { + validator : Y.Lang.isString, + value : 'Yes' + }, + + /** + * The button text to use to reject the confirmation. + * + * @attribute noLabel + * @type String + * @default 'No' + */ + noLabel : { + validator : Y.Lang.isString, + value : 'No' + }, + + /** + * The title of the dialogue. + * + * @attribute title + * @type String + * @default 'Confirm' + */ + title : { + validator : Y.Lang.isString, + value : 'Confirm' + }, + + /** + * The question posed by the dialogue. + * + * @attribute question + * @type String + * @default 'Are you sure?' + */ + question : { + validator : Y.Lang.isString, + value : 'Are you sure?' + } + } +}); +Y.augment(CONFIRM, Y.EventTarget); + +M.core.confirm = CONFIRM; + + +}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]}); 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 new file mode 100644 index 00000000000..cdef098e771 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-min.js @@ -0,0 +1 @@ +YUI.add("moodle-core-notification-confirm",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={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 l="Moodle confirmation dialogue",c;c=function(e){c.superclass.constructor.apply(this,[e])},e.extend(c,M.core.dialogue,{_enterKeypress:null,_escKeypress:null,initializer:function(){this.publish("complete"),this.publish("complete-yes"),this.publish("complete-no");var t=e.Node.create(''),n=e.Node.create(''),i=e.Node.create('
').append(e.Node.create('
'+this.get(a)+"
")).append(e.Node.create('
').append(t).append(n));this.get(r).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,i,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(u)+"

",e.WidgetStdMod.REPLACE),this.after("destroyedChange",function(){this.get(r).remove()},this),this._enterKeypress=e.on("key",this.submit,window,"down:13",this,!0),this._escKeypress=e.on("key",this.submit,window,"down:27",this,!1),t.on("click",this.submit,this,!0),n.on("click",this.submit,this,!1)},submit:function(e,t){this._enterKeypress.detach(),this._escKeypress.detach(),this.fire("complete",t),t?this.fire("complete-yes"):this.fire("complete-no"),this.hide(),this.destroy()}},{NAME:l,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(c,e.EventTarget),M.core.confirm=c},"@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 new file mode 100644 index 00000000000..cf8103cccdf --- /dev/null +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js @@ -0,0 +1,148 @@ +YUI.add('moodle-core-notification-confirm', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * A dialogue type designed to display a confirmation to the user. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-confirm + */ + +var CONFIRM_NAME = 'Moodle confirmation dialogue', + CONFIRM; + +/** + * Extends core Dialogue to show the confirmation dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.confirm + * @extends M.core.dialogue + */ +CONFIRM = function(config) { + CONFIRM.superclass.constructor.apply(this, [config]); +}; +Y.extend(CONFIRM, M.core.dialogue, { + _enterKeypress : null, + _escKeypress : null, + initializer : function() { + 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)+'
')) + .append(Y.Node.create('
') + .append(yes) + .append(no)); + this.get(BASE).addClass('moodle-dialogue-confirm'); + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); + this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); + yes.on('click', this.submit, this, true); + no.on('click', this.submit, this, false); + }, + submit : function(e, outcome) { + this._enterKeypress.detach(); + this._escKeypress.detach(); + this.fire('complete', outcome); + if (outcome) { + this.fire('complete-yes'); + } else { + this.fire('complete-no'); + } + this.hide(); + this.destroy(); + } +}, { + NAME : CONFIRM_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The button text to use to accept the confirmation. + * + * @attribute yesLabel + * @type String + * @default 'Yes' + */ + yesLabel : { + validator : Y.Lang.isString, + value : 'Yes' + }, + + /** + * The button text to use to reject the confirmation. + * + * @attribute noLabel + * @type String + * @default 'No' + */ + noLabel : { + validator : Y.Lang.isString, + value : 'No' + }, + + /** + * The title of the dialogue. + * + * @attribute title + * @type String + * @default 'Confirm' + */ + title : { + validator : Y.Lang.isString, + value : 'Confirm' + }, + + /** + * The question posed by the dialogue. + * + * @attribute question + * @type String + * @default 'Are you sure?' + */ + question : { + validator : Y.Lang.isString, + value : 'Are you sure?' + } + } +}); +Y.augment(CONFIRM, Y.EventTarget); + +M.core.confirm = CONFIRM; + + +}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js new file mode 100644 index 00000000000..639aaee9fec --- /dev/null +++ b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js @@ -0,0 +1,214 @@ +YUI.add('moodle-core-notification-dialogue', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * The generic dialogue class for use in Moodle. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-dialogue + */ + +var DIALOGUE_NAME = 'Moodle dialogue', + DIALOGUE; + +/** + * A re-usable dialogue box with Moodle classes applied. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.dialogue + * @extends Y.Panel + */ +DIALOGUE = function(config) { + COUNT++; + var id = 'moodle-dialogue-'+COUNT; + config.notificationBase = + Y.Node.create('
') + .append(Y.Node.create('') + .append(Y.Node.create('
')) + .append(Y.Node.create('
')) + .append(Y.Node.create('
'))); + Y.one(document.body).append(config.notificationBase); + config.srcNode = '#'+id; + config.width = config.width || '400px'; + config.visible = config.visible || false; + config.center = config.centered || true; + config.centered = false; + config.COUNT = COUNT; + + // lightbox param to keep the stable versions API. + if (config.lightbox !== false) { + config.modal = true; + } + delete config.lightbox; + + // closeButton param to keep the stable versions API. + if (config.closeButton === false) { + config.buttons = null; + } else { + config.buttons = [ + { + section: Y.WidgetStdMod.HEADER, + classNames: 'closebutton', + action: function () { + this.hide(); + } + } + ]; + } + DIALOGUE.superclass.constructor.apply(this, [config]); + + if (config.closeButton !== false) { + // The buttons constructor does not allow custom attributes + this.get('buttons').header[0].setAttribute('title', this.get('closeButtonTitle')); + } +}; +Y.extend(DIALOGUE, Y.Panel, { + initializer : function() { + this.after('visibleChange', this.visibilityChanged, this); + this.render(); + this.show(); + this.set('COUNT', COUNT); + + // Workaround upstream YUI bug http://yuilibrary.com/projects/yui3/ticket/2532507 + // and allow setting of z-index in theme. + this.get('boundingBox').setStyle('zIndex', null); + }, + visibilityChanged : function(e) { + var titlebar; + if (e.attrName === 'visible') { + this.get('maskNode').addClass(CSS.LIGHTBOX); + if (this.get('center') && !e.prevVal && e.newVal) { + this.centerDialogue(); + } + if (this.get('draggable')) { + titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; + this.plug(Y.Plugin.Drag, {handles : [titlebar]}); + Y.one(titlebar).setStyle('cursor', 'move'); + } + } + }, + centerDialogue : function() { + var bb = this.get('boundingBox'), + hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'), + x, y; + if (hidden) { + bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); + } + x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); + y = Math.max(Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2), 15) + Y.one(window).get('scrollTop'); + + if (hidden) { + bb.addClass(DIALOGUE_PREFIX+'-hidden'); + } + bb.setStyle('left', x).setStyle('top', y); + } +}, { + NAME : DIALOGUE_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + notificationBase : { + + }, + + /** + * Whether to display the dialogue modally and with a + * lightbox style. + * + * @attribute lightbox + * @type Boolean + * @default true + */ + lightbox : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * Whether to display a close button on the dialogue. + * + * Note, we do not recommend hiding the close button as this has + * potential accessibility concerns. + * + * @attribute closeButton + * @type Boolean + * @default true + */ + closeButton : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * The title for the close button if one is to be shown. + * + * @attribute closeButtonTitle + * @type String + * @default 'Close' + */ + closeButtonTitle : { + validator : Y.Lang.isString, + value : 'Close' + }, + + /** + * Whether to display the dialogue centrally on the screen. + * + * @attribute center + * @type Boolean + * @default true + */ + center : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * Whether to make the dialogue movable around the page. + * + * @attribute draggable + * @type Boolean + * @default false + */ + draggable : { + validator : Y.Lang.isBoolean, + value : false + }, + COUNT: { + value: 0 + } + } +}); + +M.core.dialogue = DIALOGUE; + + +}, '@VERSION@', {"requires": ["base", "node", "panel", "event-key", "dd-plugin"]}); diff --git a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-min.js b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-min.js new file mode 100644 index 00000000000..c48c7c7ce46 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-min.js @@ -0,0 +1 @@ +YUI.add("moodle-core-notification-dialogue",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={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 l="Moodle dialogue",c;c=function(t){i++;var n="moodle-dialogue-"+i;t.notificationBase=e.Node.create('
').append(e.Node.create('').append(e.Node.create('
')).append(e.Node.create('
')).append(e.Node.create('
'))),e.one(document.body).append(t.notificationBase),t.srcNode="#"+n,t.width=t.width||"400px",t.visible=t.visible||!1,t.center=t.centered||!0,t.centered=!1,t.COUNT=i,t.lightbox!==!1&&(t.modal=!0),delete t.lightbox,t.closeButton===!1?t.buttons=null:t.buttons=[{section:e.WidgetStdMod.HEADER,classNames:"closebutton",action:function(){this.hide()}}],c.superclass.constructor.apply(this,[t]),t.closeButton!==!1&&this.get("buttons").header[0].setAttribute("title",this.get("closeButtonTitle"))},e.extend(c,e.Panel,{initializer:function(){this.after("visibleChange",this.visibilityChanged,this),this.render(),this.show(),this.set("COUNT",i),this.get("boundingBox").setStyle("zIndex",null)},visibilityChanged:function(t){var n;t.attrName==="visible"&&(this.get("maskNode").addClass(f.LIGHTBOX),this.get("center")&&!t.prevVal&&t.newVal&&this.centerDialogue(),this.get("draggable")&&(n="#"+this.get("id")+" ."+f.HEADER,this.plug(e.Plugin.Drag,{handles:[n]}),e.one(n).setStyle("cursor","move")))},centerDialogue:function(){var t=this.get("boundingBox"),r=t.hasClass(n+"-hidden"),i,s;r&&t.setStyle("top","-1000px").removeClass(n+"-hidden"),i=Math.max(Math.round((t.get("winWidth")-t.get("offsetWidth"))/2),15),s=Math.max(Math.round((t.get("winHeight")-t.get("offsetHeight"))/2),15)+e.one(window).get("scrollTop"),r&&t.addClass(n+"-hidden"),t.setStyle("left",i).setStyle("top",s)}},{NAME:l,CSS_PREFIX:n,ATTRS:{notificationBase:{},lightbox:{validator:e.Lang.isBoolean,value:!0},closeButton:{validator:e.Lang.isBoolean,value:!0},closeButtonTitle:{validator:e.Lang.isString,value:"Close"},center:{validator:e.Lang.isBoolean,value:!0},draggable:{validator:e.Lang.isBoolean,value:!1},COUNT:{value:0}}}),M.core.dialogue=c},"@VERSION@",{requires:["base","node","panel","event-key","dd-plugin"]}); diff --git a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue.js b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue.js new file mode 100644 index 00000000000..639aaee9fec --- /dev/null +++ b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue.js @@ -0,0 +1,214 @@ +YUI.add('moodle-core-notification-dialogue', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * The generic dialogue class for use in Moodle. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-dialogue + */ + +var DIALOGUE_NAME = 'Moodle dialogue', + DIALOGUE; + +/** + * A re-usable dialogue box with Moodle classes applied. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.dialogue + * @extends Y.Panel + */ +DIALOGUE = function(config) { + COUNT++; + var id = 'moodle-dialogue-'+COUNT; + config.notificationBase = + Y.Node.create('
') + .append(Y.Node.create('') + .append(Y.Node.create('
')) + .append(Y.Node.create('
')) + .append(Y.Node.create('
'))); + Y.one(document.body).append(config.notificationBase); + config.srcNode = '#'+id; + config.width = config.width || '400px'; + config.visible = config.visible || false; + config.center = config.centered || true; + config.centered = false; + config.COUNT = COUNT; + + // lightbox param to keep the stable versions API. + if (config.lightbox !== false) { + config.modal = true; + } + delete config.lightbox; + + // closeButton param to keep the stable versions API. + if (config.closeButton === false) { + config.buttons = null; + } else { + config.buttons = [ + { + section: Y.WidgetStdMod.HEADER, + classNames: 'closebutton', + action: function () { + this.hide(); + } + } + ]; + } + DIALOGUE.superclass.constructor.apply(this, [config]); + + if (config.closeButton !== false) { + // The buttons constructor does not allow custom attributes + this.get('buttons').header[0].setAttribute('title', this.get('closeButtonTitle')); + } +}; +Y.extend(DIALOGUE, Y.Panel, { + initializer : function() { + this.after('visibleChange', this.visibilityChanged, this); + this.render(); + this.show(); + this.set('COUNT', COUNT); + + // Workaround upstream YUI bug http://yuilibrary.com/projects/yui3/ticket/2532507 + // and allow setting of z-index in theme. + this.get('boundingBox').setStyle('zIndex', null); + }, + visibilityChanged : function(e) { + var titlebar; + if (e.attrName === 'visible') { + this.get('maskNode').addClass(CSS.LIGHTBOX); + if (this.get('center') && !e.prevVal && e.newVal) { + this.centerDialogue(); + } + if (this.get('draggable')) { + titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; + this.plug(Y.Plugin.Drag, {handles : [titlebar]}); + Y.one(titlebar).setStyle('cursor', 'move'); + } + } + }, + centerDialogue : function() { + var bb = this.get('boundingBox'), + hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'), + x, y; + if (hidden) { + bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); + } + x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); + y = Math.max(Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2), 15) + Y.one(window).get('scrollTop'); + + if (hidden) { + bb.addClass(DIALOGUE_PREFIX+'-hidden'); + } + bb.setStyle('left', x).setStyle('top', y); + } +}, { + NAME : DIALOGUE_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + notificationBase : { + + }, + + /** + * Whether to display the dialogue modally and with a + * lightbox style. + * + * @attribute lightbox + * @type Boolean + * @default true + */ + lightbox : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * Whether to display a close button on the dialogue. + * + * Note, we do not recommend hiding the close button as this has + * potential accessibility concerns. + * + * @attribute closeButton + * @type Boolean + * @default true + */ + closeButton : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * The title for the close button if one is to be shown. + * + * @attribute closeButtonTitle + * @type String + * @default 'Close' + */ + closeButtonTitle : { + validator : Y.Lang.isString, + value : 'Close' + }, + + /** + * Whether to display the dialogue centrally on the screen. + * + * @attribute center + * @type Boolean + * @default true + */ + center : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * Whether to make the dialogue movable around the page. + * + * @attribute draggable + * @type Boolean + * @default false + */ + draggable : { + validator : Y.Lang.isBoolean, + value : false + }, + COUNT: { + value: 0 + } + } +}); + +M.core.dialogue = DIALOGUE; + + +}, '@VERSION@', {"requires": ["base", "node", "panel", "event-key", "dd-plugin"]}); diff --git a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js new file mode 100644 index 00000000000..065a4e259c9 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js @@ -0,0 +1,183 @@ +YUI.add('moodle-core-notification-exception', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * A dialogue type designed to display an appropriate error when a generic + * javascript error was thrown and caught. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-exception + */ + +var EXCEPTION_NAME = 'Moodle exception', + EXCEPTION; + +/** + * Extends core Dialogue to show the exception dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.exception + * @extends M.core.dialogue + */ +EXCEPTION = function(config) { + config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; + config.closeButton = true; + EXCEPTION.superclass.constructor.apply(this, [config]); +}; +Y.extend(EXCEPTION, M.core.dialogue, { + _hideTimeout : null, + _keypress : null, + initializer : function(config) { + var content, + self = this, + delay = this.get('hideTimeoutDelay'); + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + config.name + '

', Y.WidgetStdMod.REPLACE); + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('message')+'
')) + .append(Y.Node.create('')) + .append(Y.Node.create('')) + .append(Y.Node.create('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + if (delay) { + this._hideTimeout = setTimeout(function(){self.hide();}, delay); + } + this.after('visibleChange', this.visibilityChanged, this); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._keypress = Y.on('key', this.hide, window, 'down:13,27', this); + this.centerDialogue(); + }, + visibilityChanged : function(e) { + if (e.attrName === 'visible' && e.prevVal && !e.newVal) { + if (this._keypress) { + this._keypress.detach(); + } + var self = this; + setTimeout(function(){self.destroy();}, 1000); + } + } +}, { + NAME : EXCEPTION_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + /** + * The message of the alert. + * + * @attribute message + * @type String + * @default '' + */ + message : { + value : '' + }, + + /** + * The name of the alert. + * + * @attribute title + * @type String + * @default '' + */ + name : { + value : '' + }, + + /** + * The name of the file where the error was thrown. + * + * @attribute fileName + * @type String + * @default '' + */ + fileName : { + value : '' + }, + + /** + * The line number where the error was thrown. + * + * @attribute lineNumber + * @type String + * @default '' + */ + lineNumber : { + value : '' + }, + + /** + * The backtrace from the error + * + * @attribute lineNumber + * @type String + * @default '' + */ + stack : { + setter : function(str) { + var lines = str.split("\n"), + pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'), + i; + for (i in lines) { + lines[i] = lines[i].replace(pattern, + "
ln: $4
$3
$1
"); + } + return lines.join(''); + }, + value : '' + }, + + /** + * If set, the dialogue is hidden after the specified timeout period. + * + * @attribute hideTimeoutDelay + * @type Number + * @default null + * @optional + */ + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +M.core.exception = EXCEPTION; + + +}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-min.js b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-min.js new file mode 100644 index 00000000000..731bf9f0768 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-min.js @@ -0,0 +1 @@ +YUI.add("moodle-core-notification-exception",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={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 l="Moodle exception",c;c=function(t){t.width=t.width||M.cfg.developerdebug?Math.floor(e.one(document.body).get("winWidth")/3)+"px":null,t.closeButton=!0,c.superclass.constructor.apply(this,[t])},e.extend(c,M.core.dialogue,{_hideTimeout:null,_keypress:null,initializer:function(t){var n,s=this,o=this.get("hideTimeoutDelay");this.get(r).addClass("moodle-dialogue-exception"),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+t.name+"

",e.WidgetStdMod.REPLACE),n=e.Node.create('
').append(e.Node.create('
'+this.get("message")+"
")).append(e.Node.create('")).append(e.Node.create('")).append(e.Node.create('")),M.cfg.developerdebug&&n.all(".moodle-exception-param").removeClass("hidden"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),o&&(this._hideTimeout=setTimeout(function(){s.hide()},o)),this.after("visibleChange",this.visibilityChanged,this),this.after("destroyedChange",function(){this.get(r).remove()},this),this._keypress=e.on("key",this.hide,window,"down:13,27",this),this.centerDialogue()},visibilityChanged:function(e){if(e.attrName==="visible"&&e.prevVal&&!e.newVal){this._keypress&&this._keypress.detach();var t=this;setTimeout(function(){t.destroy()},1e3)}}},{NAME:l,CSS_PREFIX:n,ATTRS:{message:{value:""},name:{value:""},fileName:{value:""},lineNumber:{value:""},stack:{setter:function(e){var t=e.split("\n"),n=new RegExp("^(.+)@("+M.cfg.wwwroot+")?(.{0,75}).*:(\\d+)$"),r;for(r in t)t[r]=t[r].replace(n,"
ln: $4
$3
$1
");return t.join("")},value:""},hideTimeoutDelay:{validator:e.Lang.isNumber,value:null}}}),M.core.exception=c},"@VERSION@",{requires:["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js new file mode 100644 index 00000000000..065a4e259c9 --- /dev/null +++ b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js @@ -0,0 +1,183 @@ +YUI.add('moodle-core-notification-exception', function (Y, NAME) { + +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; +/** + * A dialogue type designed to display an appropriate error when a generic + * javascript error was thrown and caught. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-exception + */ + +var EXCEPTION_NAME = 'Moodle exception', + EXCEPTION; + +/** + * Extends core Dialogue to show the exception dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.exception + * @extends M.core.dialogue + */ +EXCEPTION = function(config) { + config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; + config.closeButton = true; + EXCEPTION.superclass.constructor.apply(this, [config]); +}; +Y.extend(EXCEPTION, M.core.dialogue, { + _hideTimeout : null, + _keypress : null, + initializer : function(config) { + var content, + self = this, + delay = this.get('hideTimeoutDelay'); + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + config.name + '

', Y.WidgetStdMod.REPLACE); + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('message')+'
')) + .append(Y.Node.create('')) + .append(Y.Node.create('')) + .append(Y.Node.create('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + if (delay) { + this._hideTimeout = setTimeout(function(){self.hide();}, delay); + } + this.after('visibleChange', this.visibilityChanged, this); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._keypress = Y.on('key', this.hide, window, 'down:13,27', this); + this.centerDialogue(); + }, + visibilityChanged : function(e) { + if (e.attrName === 'visible' && e.prevVal && !e.newVal) { + if (this._keypress) { + this._keypress.detach(); + } + var self = this; + setTimeout(function(){self.destroy();}, 1000); + } + } +}, { + NAME : EXCEPTION_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + /** + * The message of the alert. + * + * @attribute message + * @type String + * @default '' + */ + message : { + value : '' + }, + + /** + * The name of the alert. + * + * @attribute title + * @type String + * @default '' + */ + name : { + value : '' + }, + + /** + * The name of the file where the error was thrown. + * + * @attribute fileName + * @type String + * @default '' + */ + fileName : { + value : '' + }, + + /** + * The line number where the error was thrown. + * + * @attribute lineNumber + * @type String + * @default '' + */ + lineNumber : { + value : '' + }, + + /** + * The backtrace from the error + * + * @attribute lineNumber + * @type String + * @default '' + */ + stack : { + setter : function(str) { + var lines = str.split("\n"), + pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'), + i; + for (i in lines) { + lines[i] = lines[i].replace(pattern, + "
ln: $4
$3
$1
"); + } + return lines.join(''); + }, + value : '' + }, + + /** + * If set, the dialogue is hidden after the specified timeout period. + * + * @attribute hideTimeoutDelay + * @type Number + * @default null + * @optional + */ + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +M.core.exception = EXCEPTION; + + +}, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]}); diff --git a/lib/yui/build/moodle-core-notification/moodle-core-notification-debug.js b/lib/yui/build/moodle-core-notification/moodle-core-notification-debug.js index d12a077634d..3a222456c3f 100644 --- a/lib/yui/build/moodle-core-notification/moodle-core-notification-debug.js +++ b/lib/yui/build/moodle-core-notification/moodle-core-notification-debug.js @@ -1,408 +1,38 @@ YUI.add('moodle-core-notification', function (Y, NAME) { -var DIALOGUE_NAME = 'Moodle dialogue', - DIALOGUE_PREFIX = 'moodle-dialogue', - CONFIRM_NAME = 'Moodle confirmation dialogue', - EXCEPTION_NAME = 'Moodle exception', - AJAXEXCEPTION_NAME = 'Moodle AJAX exception', - ALERT_NAME = 'Moodle alert', - BASE = 'notificationBase', - COUNT = 0, - CONFIRMYES = 'yesLabel', - CONFIRMNO = 'noLabel', - TITLE = 'title', - QUESTION = 'question', - CSS = { - 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' - }, - EXCEPTION, - ALERT, - CONFIRM, - AJAXEXCEPTION, - DIALOGUE; +/** + * The notification module provides a standard set of dialogues for use + * within Moodle. + * + * @module moodle-core-notification + * @main + */ -DIALOGUE = function(config) { - COUNT++; - var id = 'moodle-dialogue-'+COUNT; - config.notificationBase = - Y.Node.create('
') - .append(Y.Node.create('') - .append(Y.Node.create('
')) - .append(Y.Node.create('
')) - .append(Y.Node.create('
'))); - Y.one(document.body).append(config.notificationBase); - config.srcNode = '#'+id; - config.width = config.width || '400px'; - config.visible = config.visible || false; - config.center = config.centered || true; - config.centered = false; +/** + * To avoid bringing moodle-core-notification into modules in it's + * entirety, we now recommend using on of the subclasses of + * moodle-core-notification. These include: + *
+ *
moodle-core-notification-dialogue
+ *
moodle-core-notification-alert
+ *
moodle-core-notification-confirm
+ *
moodle-core-notification-exception
+ *
moodle-core-notification-ajaxexception
+ *
+ * + * @class M.core.notification + * @deprecated + */ +Y.log("The moodle-core-notification parent module has been deprecated. " + + "Please use one of its' subclasses instead.", 'moodle-core-notification', 'warn'); - // lightbox param to keep the stable versions API. - if (config.lightbox !== false) { - config.modal = true; - } - delete config.lightbox; - // closeButton param to keep the stable versions API. - if (config.closeButton === false) { - config.buttons = null; - } else { - config.buttons = [ - { - section: Y.WidgetStdMod.HEADER, - classNames: 'closebutton', - action: function () { - this.hide(); - } - } - ]; - } - DIALOGUE.superclass.constructor.apply(this, [config]); - - if (config.closeButton !== false) { - // The buttons constructor does not allow custom attributes - this.get('buttons').header[0].setAttribute('title', this.get('closeButtonTitle')); - } -}; -Y.extend(DIALOGUE, Y.Panel, { - initializer : function() { - this.after('visibleChange', this.visibilityChanged, this); - this.render(); - this.show(); - - // Workaround upstream YUI bug http://yuilibrary.com/projects/yui3/ticket/2532507 - // and allow setting of z-index in theme. - this.get('boundingBox').setStyle('zIndex', null); - }, - visibilityChanged : function(e) { - var titlebar; - if (e.attrName === 'visible') { - this.get('maskNode').addClass(CSS.LIGHTBOX); - if (this.get('center') && !e.prevVal && e.newVal) { - this.centerDialogue(); - } - if (this.get('draggable')) { - titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; - this.plug(Y.Plugin.Drag, {handles : [titlebar]}); - Y.one(titlebar).setStyle('cursor', 'move'); - } - } - }, - centerDialogue : function() { - var bb = this.get('boundingBox'), - hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'), - x, y; - if (hidden) { - bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); - } - x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); - y = Math.max(Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2), 15) + Y.one(window).get('scrollTop'); - - if (hidden) { - bb.addClass(DIALOGUE_PREFIX+'-hidden'); - } - bb.setStyle('left', x).setStyle('top', y); - } -}, { - NAME : DIALOGUE_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - notificationBase : { - - }, - lightbox : { - validator : Y.Lang.isBoolean, - value : true - }, - closeButton : { - validator : Y.Lang.isBoolean, - value : true - }, - closeButtonTitle : { - validator : Y.Lang.isString, - value : 'Close' - }, - center : { - validator : Y.Lang.isBoolean, - value : true - }, - draggable : { - validator : Y.Lang.isBoolean, - value : false - } - } +}, '@VERSION@', { + "requires": [ + "moodle-core-notification-dialogue", + "moodle-core-notification-alert", + "moodle-core-notification-confirm", + "moodle-core-notification-exception", + "moodle-core-notification-ajaxexception" + ] }); - -ALERT = function(config) { - config.closeButton = false; - ALERT.superclass.constructor.apply(this, [config]); -}; -Y.extend(ALERT, DIALOGUE, { - _enterKeypress : null, - initializer : function() { - this.publish('complete'); - var yes = Y.Node.create(''), - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('message')+'
')) - .append(Y.Node.create('
') - .append(yes)); - this.get(BASE).addClass('moodle-dialogue-confirm'); - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); - yes.on('click', this.submit, this); - }, - submit : function() { - this._enterKeypress.detach(); - this.fire('complete'); - this.hide(); - this.destroy(); - } -}, { - NAME : ALERT_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - title : { - validator : Y.Lang.isString, - value : 'Alert' - }, - message : { - validator : Y.Lang.isString, - value : 'Confirm' - }, - yesLabel : { - validator : Y.Lang.isString, - setter : function(txt) { - if (!txt) { - txt = 'Ok'; - } - return txt; - }, - value : 'Ok' - } - } -}); - -CONFIRM = function(config) { - CONFIRM.superclass.constructor.apply(this, [config]); -}; -Y.extend(CONFIRM, DIALOGUE, { - _enterKeypress : null, - _escKeypress : null, - initializer : function() { - 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)+'
')) - .append(Y.Node.create('
') - .append(yes) - .append(no)); - this.get(BASE).addClass('moodle-dialogue-confirm'); - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); - this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); - yes.on('click', this.submit, this, true); - no.on('click', this.submit, this, false); - }, - submit : function(e, outcome) { - this._enterKeypress.detach(); - this._escKeypress.detach(); - this.fire('complete', outcome); - if (outcome) { - this.fire('complete-yes'); - } else { - this.fire('complete-no'); - } - this.hide(); - this.destroy(); - } -}, { - NAME : CONFIRM_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - yesLabel : { - validator : Y.Lang.isString, - value : 'Yes' - }, - noLabel : { - validator : Y.Lang.isString, - value : 'No' - }, - title : { - validator : Y.Lang.isString, - value : 'Confirm' - }, - question : { - validator : Y.Lang.isString, - value : 'Are you sure?' - } - } -}); -Y.augment(CONFIRM, Y.EventTarget); - -EXCEPTION = function(config) { - config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; - config.closeButton = true; - EXCEPTION.superclass.constructor.apply(this, [config]); -}; -Y.extend(EXCEPTION, DIALOGUE, { - _hideTimeout : null, - _keypress : null, - initializer : function(config) { - var content, - self = this, - delay = this.get('hideTimeoutDelay'); - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + config.name + '

', Y.WidgetStdMod.REPLACE); - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('message')+'
')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - if (delay) { - this._hideTimeout = setTimeout(function(){self.hide();}, delay); - } - this.after('visibleChange', this.visibilityChanged, this); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._keypress = Y.on('key', this.hide, window, 'down:13,27', this); - this.centerDialogue(); - }, - visibilityChanged : function(e) { - if (e.attrName === 'visible' && e.prevVal && !e.newVal) { - if (this._keypress) { - this._keypress.detach(); - } - var self = this; - setTimeout(function(){self.destroy();}, 1000); - } - } -}, { - NAME : EXCEPTION_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - message : { - value : '' - }, - name : { - value : '' - }, - fileName : { - value : '' - }, - lineNumber : { - value : '' - }, - stack : { - setter : function(str) { - var lines = str.split("\n"), - pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'), - i; - for (i in lines) { - lines[i] = lines[i].replace(pattern, - "
ln: $4
$3
$1
"); - } - return lines.join(''); - }, - value : '' - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -AJAXEXCEPTION = function(config) { - config.name = config.name || 'Error'; - config.closeButton = true; - AJAXEXCEPTION.superclass.constructor.apply(this, [config]); -}; -Y.extend(AJAXEXCEPTION, DIALOGUE, { - _keypress : null, - initializer : function(config) { - var content, - self = this, - delay = this.get('hideTimeoutDelay'); - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + config.name + '

', Y.WidgetStdMod.REPLACE); - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('error')+'
')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - if (delay) { - this._hideTimeout = setTimeout(function(){self.hide();}, delay); - } - this.after('visibleChange', this.visibilityChanged, this); - this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this); - this.centerDialogue(); - }, - visibilityChanged : function(e) { - if (e.attrName === 'visible' && e.prevVal && !e.newVal) { - var self = this; - this._keypress.detach(); - setTimeout(function(){self.destroy();}, 1000); - } - } -}, { - NAME : AJAXEXCEPTION_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - error : { - validator : Y.Lang.isString, - value : 'Unknown error' - }, - debuginfo : { - value : null - }, - stacktrace : { - value : null - }, - reproductionlink : { - setter : function(link) { - if (link !== null) { - link = ''+link.replace(M.cfg.wwwroot, '')+''; - } - return link; - }, - value : null - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -M.core = M.core || {}; -M.core.dialogue = DIALOGUE; -M.core.alert = ALERT; -M.core.confirm = CONFIRM; -M.core.exception = EXCEPTION; -M.core.ajaxException = AJAXEXCEPTION; - - -}, '@VERSION@', {"requires": ["base", "node", "panel", "event-key", "dd-plugin"]}); diff --git a/lib/yui/build/moodle-core-notification/moodle-core-notification-min.js b/lib/yui/build/moodle-core-notification/moodle-core-notification-min.js index 738909ef367..9a0ca2ad53e 100644 --- a/lib/yui/build/moodle-core-notification/moodle-core-notification-min.js +++ b/lib/yui/build/moodle-core-notification/moodle-core-notification-min.js @@ -1,2 +1 @@ -YUI.add("moodle-core-notification",function(e,t){var n="Moodle dialogue",r="moodle-dialogue",i="Moodle confirmation dialogue",s="Moodle exception",o="Moodle AJAX exception",u="Moodle alert",a="notificationBase",f=0,l="yesLabel",c="noLabel",h="title",p="question",d={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"},v,m,g,y,b;b=function(t){f++;var n="moodle-dialogue-"+f;t.notificationBase=e.Node.create('
').append(e.Node.create('').append(e.Node.create('
')).append(e.Node.create('
')).append(e.Node.create('
'))),e.one(document.body).append(t.notificationBase),t.srcNode="#"+n,t.width=t.width||"400px",t.visible=t.visible||!1,t.center=t.centered||!0,t.centered=!1,t.lightbox!==!1&&(t.modal=!0),delete t.lightbox,t.closeButton===!1?t.buttons=null:t.buttons=[{section:e.WidgetStdMod.HEADER,classNames:"closebutton",action:function(){this.hide()}}],b.superclass.constructor.apply(this,[t]),t.closeButton!==!1&&this.get("buttons").header[0].setAttribute("title",this.get("closeButtonTitle"))},e.extend(b,e.Panel,{initializer:function(){this.after("visibleChange",this.visibilityChanged,this),this.render(),this.show(),this.get("boundingBox").setStyle("zIndex",null)},visibilityChanged:function(t){var n;t.attrName==="visible"&&(this.get("maskNode").addClass(d.LIGHTBOX),this.get("center")&&!t.prevVal&&t.newVal&&this.centerDialogue(),this.get("draggable")&&(n="#"+this.get("id")+" ."+d.HEADER,this.plug(e.Plugin.Drag,{handles:[n]}),e.one(n).setStyle("cursor","move")))},centerDialogue:function(){var t=this.get("boundingBox"),n=t.hasClass(r+"-hidden"),i,s;n&&t.setStyle("top","-1000px").removeClass(r+"-hidden"),i=Math.max(Math.round((t.get("winWidth")-t.get("offsetWidth"))/2),15),s=Math.max(Math.round((t.get("winHeight")-t.get("offsetHeight"))/2),15)+e.one(window).get("scrollTop"),n&&t.addClass(r+"-hidden"),t.setStyle("left",i).setStyle("top",s)}},{NAME:n,CSS_PREFIX:r,ATTRS:{notificationBase:{},lightbox:{validator:e.Lang.isBoolean,value:!0},closeButton:{validator:e.Lang.isBoolean,value:!0},closeButtonTitle:{validator:e.Lang.isString,value:"Close"},center:{validator:e.Lang.isBoolean,value:!0},draggable:{validator:e.Lang.isBoolean,value:!1}}}),m=function(e){e.closeButton=!1,m.superclass.constructor.apply(this,[e])},e.extend(m,b,{_enterKeypress:null,initializer:function(){this.publish("complete");var t=e.Node.create(''),n=e.Node.create('
').append(e.Node.create('
'+this.get("message")+"
")).append(e.Node.create('
').append(t));this.get(a).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(h)+"

",e.WidgetStdMod.REPLACE),this.after("destroyedChange",function(){this.get(a).remove()},this),this._enterKeypress=e.on("key",this.submit,window,"down:13",this),t.on("click",this.submit,this)},submit:function(){this._enterKeypress.detach(),this.fire("complete"),this.hide(),this.destroy()}},{NAME:u,CSS_PREFIX:r,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"}}}),g=function(e){g.superclass.constructor.apply(this,[e])},e.extend(g,b,{_enterKeypress:null,_escKeypress:null,initializer:function(){this.publish("complete"),this.publish("complete-yes"),this.publish("complete-no");var t=e.Node.create(''),n=e.Node.create(''),r=e.Node.create('
').append(e.Node.create('
'+this.get(p)+"
")).append(e.Node.create('
').append(t).append(n));this.get(a).addClass("moodle-dialogue-confirm"),this.setStdModContent(e.WidgetStdMod.BODY,r,e.WidgetStdMod.REPLACE),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+this.get(h)+"

",e.WidgetStdMod.REPLACE),this.after("destroyedChange",function(){this.get(a).remove()},this),this._enterKeypress=e.on("key",this.submit,window,"down:13",this,!0),this._escKeypress=e.on("key",this.submit,window,"down:27",this,!1),t.on("click",this.submit,this,!0),n.on("click",this.submit,this,!1)},submit:function(e,t){this._enterKeypress.detach(),this._escKeypress.detach(),this.fire("complete",t),t?this.fire("complete-yes"):this.fire("complete-no"),this.hide(),this.destroy()}},{NAME:i,CSS_PREFIX:r,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(g,e.EventTarget),v=function(t){t.width=t.width||M.cfg.developerdebug?Math.floor(e.one(document.body).get("winWidth")/3)+"px":null,t.closeButton=!0,v.superclass.constructor.apply(this,[t])},e.extend(v,b,{_hideTimeout:null,_keypress:null,initializer:function(t){var n,r=this,i=this.get("hideTimeoutDelay");this.get(a).addClass("moodle-dialogue-exception"),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+t.name+"

",e.WidgetStdMod.REPLACE),n=e.Node.create('
').append(e.Node.create('
'+ -this.get("message")+"
")).append(e.Node.create('")).append(e.Node.create('")).append(e.Node.create('")),M.cfg.developerdebug&&n.all(".moodle-exception-param").removeClass("hidden"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),i&&(this._hideTimeout=setTimeout(function(){r.hide()},i)),this.after("visibleChange",this.visibilityChanged,this),this.after("destroyedChange",function(){this.get(a).remove()},this),this._keypress=e.on("key",this.hide,window,"down:13,27",this),this.centerDialogue()},visibilityChanged:function(e){if(e.attrName==="visible"&&e.prevVal&&!e.newVal){this._keypress&&this._keypress.detach();var t=this;setTimeout(function(){t.destroy()},1e3)}}},{NAME:s,CSS_PREFIX:r,ATTRS:{message:{value:""},name:{value:""},fileName:{value:""},lineNumber:{value:""},stack:{setter:function(e){var t=e.split("\n"),n=new RegExp("^(.+)@("+M.cfg.wwwroot+")?(.{0,75}).*:(\\d+)$"),r;for(r in t)t[r]=t[r].replace(n,"
ln: $4
$3
$1
");return t.join("")},value:""},hideTimeoutDelay:{validator:e.Lang.isNumber,value:null}}}),y=function(e){e.name=e.name||"Error",e.closeButton=!0,y.superclass.constructor.apply(this,[e])},e.extend(y,b,{_keypress:null,initializer:function(t){var n,r=this,i=this.get("hideTimeoutDelay");this.get(a).addClass("moodle-dialogue-exception"),this.setStdModContent(e.WidgetStdMod.HEADER,'

'+t.name+"

",e.WidgetStdMod.REPLACE),n=e.Node.create('
').append(e.Node.create('
'+this.get("error")+"
")).append(e.Node.create('")).append(e.Node.create('")).append(e.Node.create('")),M.cfg.developerdebug&&n.all(".moodle-exception-param").removeClass("hidden"),this.setStdModContent(e.WidgetStdMod.BODY,n,e.WidgetStdMod.REPLACE),i&&(this._hideTimeout=setTimeout(function(){r.hide()},i)),this.after("visibleChange",this.visibilityChanged,this),this._keypress=e.on("key",this.hide,window,"down:13, 27",this),this.centerDialogue()},visibilityChanged:function(e){if(e.attrName==="visible"&&e.prevVal&&!e.newVal){var t=this;this._keypress.detach(),setTimeout(function(){t.destroy()},1e3)}}},{NAME:o,CSS_PREFIX:r,ATTRS:{error:{validator:e.Lang.isString,value:"Unknown error"},debuginfo:{value:null},stacktrace:{value:null},reproductionlink:{setter:function(e){return e!==null&&(e=''+e.replace(M.cfg.wwwroot,"")+""),e},value:null},hideTimeoutDelay:{validator:e.Lang.isNumber,value:null}}}),M.core=M.core||{},M.core.dialogue=b,M.core.alert=m,M.core.confirm=g,M.core.exception=v,M.core.ajaxException=y},"@VERSION@",{requires:["base","node","panel","event-key","dd-plugin"]}); +YUI.add("moodle-core-notification",function(e,t){},"@VERSION@",{requires:["moodle-core-notification-dialogue","moodle-core-notification-alert","moodle-core-notification-confirm","moodle-core-notification-exception","moodle-core-notification-ajaxexception"]}); diff --git a/lib/yui/build/moodle-core-notification/moodle-core-notification.js b/lib/yui/build/moodle-core-notification/moodle-core-notification.js index d12a077634d..0de335377ff 100644 --- a/lib/yui/build/moodle-core-notification/moodle-core-notification.js +++ b/lib/yui/build/moodle-core-notification/moodle-core-notification.js @@ -1,408 +1,36 @@ YUI.add('moodle-core-notification', function (Y, NAME) { -var DIALOGUE_NAME = 'Moodle dialogue', - DIALOGUE_PREFIX = 'moodle-dialogue', - CONFIRM_NAME = 'Moodle confirmation dialogue', - EXCEPTION_NAME = 'Moodle exception', - AJAXEXCEPTION_NAME = 'Moodle AJAX exception', - ALERT_NAME = 'Moodle alert', - BASE = 'notificationBase', - COUNT = 0, - CONFIRMYES = 'yesLabel', - CONFIRMNO = 'noLabel', - TITLE = 'title', - QUESTION = 'question', - CSS = { - 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' - }, - EXCEPTION, - ALERT, - CONFIRM, - AJAXEXCEPTION, - DIALOGUE; +/** + * The notification module provides a standard set of dialogues for use + * within Moodle. + * + * @module moodle-core-notification + * @main + */ -DIALOGUE = function(config) { - COUNT++; - var id = 'moodle-dialogue-'+COUNT; - config.notificationBase = - Y.Node.create('
') - .append(Y.Node.create('') - .append(Y.Node.create('
')) - .append(Y.Node.create('
')) - .append(Y.Node.create('
'))); - Y.one(document.body).append(config.notificationBase); - config.srcNode = '#'+id; - config.width = config.width || '400px'; - config.visible = config.visible || false; - config.center = config.centered || true; - config.centered = false; +/** + * To avoid bringing moodle-core-notification into modules in it's + * entirety, we now recommend using on of the subclasses of + * moodle-core-notification. These include: + *
+ *
moodle-core-notification-dialogue
+ *
moodle-core-notification-alert
+ *
moodle-core-notification-confirm
+ *
moodle-core-notification-exception
+ *
moodle-core-notification-ajaxexception
+ *
+ * + * @class M.core.notification + * @deprecated + */ - // lightbox param to keep the stable versions API. - if (config.lightbox !== false) { - config.modal = true; - } - delete config.lightbox; - // closeButton param to keep the stable versions API. - if (config.closeButton === false) { - config.buttons = null; - } else { - config.buttons = [ - { - section: Y.WidgetStdMod.HEADER, - classNames: 'closebutton', - action: function () { - this.hide(); - } - } - ]; - } - DIALOGUE.superclass.constructor.apply(this, [config]); - - if (config.closeButton !== false) { - // The buttons constructor does not allow custom attributes - this.get('buttons').header[0].setAttribute('title', this.get('closeButtonTitle')); - } -}; -Y.extend(DIALOGUE, Y.Panel, { - initializer : function() { - this.after('visibleChange', this.visibilityChanged, this); - this.render(); - this.show(); - - // Workaround upstream YUI bug http://yuilibrary.com/projects/yui3/ticket/2532507 - // and allow setting of z-index in theme. - this.get('boundingBox').setStyle('zIndex', null); - }, - visibilityChanged : function(e) { - var titlebar; - if (e.attrName === 'visible') { - this.get('maskNode').addClass(CSS.LIGHTBOX); - if (this.get('center') && !e.prevVal && e.newVal) { - this.centerDialogue(); - } - if (this.get('draggable')) { - titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; - this.plug(Y.Plugin.Drag, {handles : [titlebar]}); - Y.one(titlebar).setStyle('cursor', 'move'); - } - } - }, - centerDialogue : function() { - var bb = this.get('boundingBox'), - hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'), - x, y; - if (hidden) { - bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); - } - x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); - y = Math.max(Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2), 15) + Y.one(window).get('scrollTop'); - - if (hidden) { - bb.addClass(DIALOGUE_PREFIX+'-hidden'); - } - bb.setStyle('left', x).setStyle('top', y); - } -}, { - NAME : DIALOGUE_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - notificationBase : { - - }, - lightbox : { - validator : Y.Lang.isBoolean, - value : true - }, - closeButton : { - validator : Y.Lang.isBoolean, - value : true - }, - closeButtonTitle : { - validator : Y.Lang.isString, - value : 'Close' - }, - center : { - validator : Y.Lang.isBoolean, - value : true - }, - draggable : { - validator : Y.Lang.isBoolean, - value : false - } - } +}, '@VERSION@', { + "requires": [ + "moodle-core-notification-dialogue", + "moodle-core-notification-alert", + "moodle-core-notification-confirm", + "moodle-core-notification-exception", + "moodle-core-notification-ajaxexception" + ] }); - -ALERT = function(config) { - config.closeButton = false; - ALERT.superclass.constructor.apply(this, [config]); -}; -Y.extend(ALERT, DIALOGUE, { - _enterKeypress : null, - initializer : function() { - this.publish('complete'); - var yes = Y.Node.create(''), - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('message')+'
')) - .append(Y.Node.create('
') - .append(yes)); - this.get(BASE).addClass('moodle-dialogue-confirm'); - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); - yes.on('click', this.submit, this); - }, - submit : function() { - this._enterKeypress.detach(); - this.fire('complete'); - this.hide(); - this.destroy(); - } -}, { - NAME : ALERT_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - title : { - validator : Y.Lang.isString, - value : 'Alert' - }, - message : { - validator : Y.Lang.isString, - value : 'Confirm' - }, - yesLabel : { - validator : Y.Lang.isString, - setter : function(txt) { - if (!txt) { - txt = 'Ok'; - } - return txt; - }, - value : 'Ok' - } - } -}); - -CONFIRM = function(config) { - CONFIRM.superclass.constructor.apply(this, [config]); -}; -Y.extend(CONFIRM, DIALOGUE, { - _enterKeypress : null, - _escKeypress : null, - initializer : function() { - 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)+'
')) - .append(Y.Node.create('
') - .append(yes) - .append(no)); - this.get(BASE).addClass('moodle-dialogue-confirm'); - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); - this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); - yes.on('click', this.submit, this, true); - no.on('click', this.submit, this, false); - }, - submit : function(e, outcome) { - this._enterKeypress.detach(); - this._escKeypress.detach(); - this.fire('complete', outcome); - if (outcome) { - this.fire('complete-yes'); - } else { - this.fire('complete-no'); - } - this.hide(); - this.destroy(); - } -}, { - NAME : CONFIRM_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - yesLabel : { - validator : Y.Lang.isString, - value : 'Yes' - }, - noLabel : { - validator : Y.Lang.isString, - value : 'No' - }, - title : { - validator : Y.Lang.isString, - value : 'Confirm' - }, - question : { - validator : Y.Lang.isString, - value : 'Are you sure?' - } - } -}); -Y.augment(CONFIRM, Y.EventTarget); - -EXCEPTION = function(config) { - config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; - config.closeButton = true; - EXCEPTION.superclass.constructor.apply(this, [config]); -}; -Y.extend(EXCEPTION, DIALOGUE, { - _hideTimeout : null, - _keypress : null, - initializer : function(config) { - var content, - self = this, - delay = this.get('hideTimeoutDelay'); - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + config.name + '

', Y.WidgetStdMod.REPLACE); - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('message')+'
')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - if (delay) { - this._hideTimeout = setTimeout(function(){self.hide();}, delay); - } - this.after('visibleChange', this.visibilityChanged, this); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._keypress = Y.on('key', this.hide, window, 'down:13,27', this); - this.centerDialogue(); - }, - visibilityChanged : function(e) { - if (e.attrName === 'visible' && e.prevVal && !e.newVal) { - if (this._keypress) { - this._keypress.detach(); - } - var self = this; - setTimeout(function(){self.destroy();}, 1000); - } - } -}, { - NAME : EXCEPTION_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - message : { - value : '' - }, - name : { - value : '' - }, - fileName : { - value : '' - }, - lineNumber : { - value : '' - }, - stack : { - setter : function(str) { - var lines = str.split("\n"), - pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'), - i; - for (i in lines) { - lines[i] = lines[i].replace(pattern, - "
ln: $4
$3
$1
"); - } - return lines.join(''); - }, - value : '' - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -AJAXEXCEPTION = function(config) { - config.name = config.name || 'Error'; - config.closeButton = true; - AJAXEXCEPTION.superclass.constructor.apply(this, [config]); -}; -Y.extend(AJAXEXCEPTION, DIALOGUE, { - _keypress : null, - initializer : function(config) { - var content, - self = this, - delay = this.get('hideTimeoutDelay'); - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + config.name + '

', Y.WidgetStdMod.REPLACE); - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('error')+'
')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - if (delay) { - this._hideTimeout = setTimeout(function(){self.hide();}, delay); - } - this.after('visibleChange', this.visibilityChanged, this); - this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this); - this.centerDialogue(); - }, - visibilityChanged : function(e) { - if (e.attrName === 'visible' && e.prevVal && !e.newVal) { - var self = this; - this._keypress.detach(); - setTimeout(function(){self.destroy();}, 1000); - } - } -}, { - NAME : AJAXEXCEPTION_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - error : { - validator : Y.Lang.isString, - value : 'Unknown error' - }, - debuginfo : { - value : null - }, - stacktrace : { - value : null - }, - reproductionlink : { - setter : function(link) { - if (link !== null) { - link = ''+link.replace(M.cfg.wwwroot, '')+''; - } - return link; - }, - value : null - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -M.core = M.core || {}; -M.core.dialogue = DIALOGUE; -M.core.alert = ALERT; -M.core.confirm = CONFIRM; -M.core.exception = EXCEPTION; -M.core.ajaxException = AJAXEXCEPTION; - - -}, '@VERSION@', {"requires": ["base", "node", "panel", "event-key", "dd-plugin"]}); diff --git a/lib/yui/src/notification/build.json b/lib/yui/src/notification/build.json index dfc25ad2402..bd7cc1df3d5 100644 --- a/lib/yui/src/notification/build.json +++ b/lib/yui/src/notification/build.json @@ -5,6 +5,36 @@ "jsfiles": [ "notification.js" ] + }, + "moodle-core-notification-dialogue": { + "jsfiles": [ + "shared.js", + "dialogue.js" + ] + }, + "moodle-core-notification-alert": { + "jsfiles": [ + "shared.js", + "alert.js" + ] + }, + "moodle-core-notification-confirm": { + "jsfiles": [ + "shared.js", + "confirm.js" + ] + }, + "moodle-core-notification-exception": { + "jsfiles": [ + "shared.js", + "exception.js" + ] + }, + "moodle-core-notification-ajaxexception": { + "jsfiles": [ + "shared.js", + "ajaxexception.js" + ] } } } diff --git a/lib/yui/src/notification/js/ajaxexception.js b/lib/yui/src/notification/js/ajaxexception.js new file mode 100644 index 00000000000..19b444154fc --- /dev/null +++ b/lib/yui/src/notification/js/ajaxexception.js @@ -0,0 +1,136 @@ +/** + * A dialogue type designed to display an appropriate error when an error + * thrown in the Moodle codebase was reported during an AJAX request. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-ajaxexception + */ + +var AJAXEXCEPTION_NAME = 'Moodle AJAX exception', + AJAXEXCEPTION; + +/** + * Extends core Dialogue to show the exception dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.ajaxException + * @extends M.core.dialogue + */ +AJAXEXCEPTION = function(config) { + config.name = config.name || 'Error'; + config.closeButton = true; + AJAXEXCEPTION.superclass.constructor.apply(this, [config]); +}; +Y.extend(AJAXEXCEPTION, M.core.dialogue, { + _keypress : null, + initializer : function(config) { + var content, + self = this, + delay = this.get('hideTimeoutDelay'); + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + config.name + '

', Y.WidgetStdMod.REPLACE); + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('error')+'
')) + .append(Y.Node.create('')) + .append(Y.Node.create('')) + .append(Y.Node.create('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + if (delay) { + this._hideTimeout = setTimeout(function(){self.hide();}, delay); + } + this.after('visibleChange', this.visibilityChanged, this); + this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this); + this.centerDialogue(); + }, + visibilityChanged : function(e) { + if (e.attrName === 'visible' && e.prevVal && !e.newVal) { + var self = this; + this._keypress.detach(); + setTimeout(function(){self.destroy();}, 1000); + } + } +}, { + NAME : AJAXEXCEPTION_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The error message given in the exception. + * + * @attribute error + * @type String + * @default 'Unknown error' + * @optional + */ + error : { + validator : Y.Lang.isString, + value : 'Unknown error' + }, + + /** + * Any additional debug information given in the exception. + * + * @attribute stacktrace + * @type String|null + * @default null + * @optional + */ + debuginfo : { + value : null + }, + + /** + * The complete stack trace provided in the exception. + * + * @attribute stacktrace + * @type String|null + * @default null + * @optional + */ + stacktrace : { + value : null + }, + + /** + * A link which may be used by support staff to replicate the issue. + * + * @attribute reproductionlink + * @type String + * @default null + * @optional + */ + reproductionlink : { + setter : function(link) { + if (link !== null) { + link = ''+link.replace(M.cfg.wwwroot, '')+''; + } + return link; + }, + value : null + }, + + /** + * If set, the dialogue is hidden after the specified timeout period. + * + * @attribute hideTimeoutDelay + * @type Number + * @default null + * @optional + */ + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +M.core.ajaxException = AJAXEXCEPTION; diff --git a/lib/yui/src/notification/js/alert.js b/lib/yui/src/notification/js/alert.js new file mode 100644 index 00000000000..f51c20b03ac --- /dev/null +++ b/lib/yui/src/notification/js/alert.js @@ -0,0 +1,95 @@ +/** + * A dialogue type designed to display an alert to the user. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-alert + */ + +var ALERT_NAME = 'Moodle alert', + ALERT; + +/** + * Extends core Dialogue to show the alert dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.alert + * @extends M.core.dialogue + */ +ALERT = function(config) { + config.closeButton = false; + ALERT.superclass.constructor.apply(this, [config]); +}; +Y.extend(ALERT, M.core.dialogue, { + _enterKeypress : null, + initializer : function() { + this.publish('complete'); + var yes = Y.Node.create(''), + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('message')+'
')) + .append(Y.Node.create('
') + .append(yes)); + this.get(BASE).addClass('moodle-dialogue-confirm'); + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); + yes.on('click', this.submit, this); + }, + submit : function() { + this._enterKeypress.detach(); + this.fire('complete'); + this.hide(); + this.destroy(); + } +}, { + NAME : ALERT_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The title of the alert. + * + * @attribute title + * @type String + * @default 'Alert' + */ + title : { + validator : Y.Lang.isString, + value : 'Alert' + }, + + /** + * The message of the alert. + * + * @attribute message + * @type String + * @default 'Confirm' + */ + message : { + validator : Y.Lang.isString, + value : 'Confirm' + }, + + /** + * The button text to use to accept the alert. + * + * @attribute yesLabel + * @type String + * @default 'Ok' + */ + yesLabel : { + validator : Y.Lang.isString, + setter : function(txt) { + if (!txt) { + txt = 'Ok'; + } + return txt; + }, + value : 'Ok' + } + } +}); + +M.core.alert = ALERT; diff --git a/lib/yui/src/notification/js/confirm.js b/lib/yui/src/notification/js/confirm.js new file mode 100644 index 00000000000..fe80edc7e9e --- /dev/null +++ b/lib/yui/src/notification/js/confirm.js @@ -0,0 +1,114 @@ +/** + * A dialogue type designed to display a confirmation to the user. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-confirm + */ + +var CONFIRM_NAME = 'Moodle confirmation dialogue', + CONFIRM; + +/** + * Extends core Dialogue to show the confirmation dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.confirm + * @extends M.core.dialogue + */ +CONFIRM = function(config) { + CONFIRM.superclass.constructor.apply(this, [config]); +}; +Y.extend(CONFIRM, M.core.dialogue, { + _enterKeypress : null, + _escKeypress : null, + initializer : function() { + 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)+'
')) + .append(Y.Node.create('
') + .append(yes) + .append(no)); + this.get(BASE).addClass('moodle-dialogue-confirm'); + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); + this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); + yes.on('click', this.submit, this, true); + no.on('click', this.submit, this, false); + }, + submit : function(e, outcome) { + this._enterKeypress.detach(); + this._escKeypress.detach(); + this.fire('complete', outcome); + if (outcome) { + this.fire('complete-yes'); + } else { + this.fire('complete-no'); + } + this.hide(); + this.destroy(); + } +}, { + NAME : CONFIRM_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + + /** + * The button text to use to accept the confirmation. + * + * @attribute yesLabel + * @type String + * @default 'Yes' + */ + yesLabel : { + validator : Y.Lang.isString, + value : 'Yes' + }, + + /** + * The button text to use to reject the confirmation. + * + * @attribute noLabel + * @type String + * @default 'No' + */ + noLabel : { + validator : Y.Lang.isString, + value : 'No' + }, + + /** + * The title of the dialogue. + * + * @attribute title + * @type String + * @default 'Confirm' + */ + title : { + validator : Y.Lang.isString, + value : 'Confirm' + }, + + /** + * The question posed by the dialogue. + * + * @attribute question + * @type String + * @default 'Are you sure?' + */ + question : { + validator : Y.Lang.isString, + value : 'Are you sure?' + } + } +}); +Y.augment(CONFIRM, Y.EventTarget); + +M.core.confirm = CONFIRM; diff --git a/lib/yui/src/notification/js/dialogue.js b/lib/yui/src/notification/js/dialogue.js new file mode 100644 index 00000000000..0a2bf7c1ebb --- /dev/null +++ b/lib/yui/src/notification/js/dialogue.js @@ -0,0 +1,180 @@ +/** + * The generic dialogue class for use in Moodle. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-dialogue + */ + +var DIALOGUE_NAME = 'Moodle dialogue', + DIALOGUE; + +/** + * A re-usable dialogue box with Moodle classes applied. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.dialogue + * @extends Y.Panel + */ +DIALOGUE = function(config) { + COUNT++; + var id = 'moodle-dialogue-'+COUNT; + config.notificationBase = + Y.Node.create('
') + .append(Y.Node.create('') + .append(Y.Node.create('
')) + .append(Y.Node.create('
')) + .append(Y.Node.create('
'))); + Y.one(document.body).append(config.notificationBase); + config.srcNode = '#'+id; + config.width = config.width || '400px'; + config.visible = config.visible || false; + config.center = config.centered || true; + config.centered = false; + config.COUNT = COUNT; + + // lightbox param to keep the stable versions API. + if (config.lightbox !== false) { + config.modal = true; + } + delete config.lightbox; + + // closeButton param to keep the stable versions API. + if (config.closeButton === false) { + config.buttons = null; + } else { + config.buttons = [ + { + section: Y.WidgetStdMod.HEADER, + classNames: 'closebutton', + action: function () { + this.hide(); + } + } + ]; + } + DIALOGUE.superclass.constructor.apply(this, [config]); + + if (config.closeButton !== false) { + // The buttons constructor does not allow custom attributes + this.get('buttons').header[0].setAttribute('title', this.get('closeButtonTitle')); + } +}; +Y.extend(DIALOGUE, Y.Panel, { + initializer : function() { + this.after('visibleChange', this.visibilityChanged, this); + this.render(); + this.show(); + this.set('COUNT', COUNT); + + // Workaround upstream YUI bug http://yuilibrary.com/projects/yui3/ticket/2532507 + // and allow setting of z-index in theme. + this.get('boundingBox').setStyle('zIndex', null); + }, + visibilityChanged : function(e) { + var titlebar; + if (e.attrName === 'visible') { + this.get('maskNode').addClass(CSS.LIGHTBOX); + if (this.get('center') && !e.prevVal && e.newVal) { + this.centerDialogue(); + } + if (this.get('draggable')) { + titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; + this.plug(Y.Plugin.Drag, {handles : [titlebar]}); + Y.one(titlebar).setStyle('cursor', 'move'); + } + } + }, + centerDialogue : function() { + var bb = this.get('boundingBox'), + hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'), + x, y; + if (hidden) { + bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); + } + x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); + y = Math.max(Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2), 15) + Y.one(window).get('scrollTop'); + + if (hidden) { + bb.addClass(DIALOGUE_PREFIX+'-hidden'); + } + bb.setStyle('left', x).setStyle('top', y); + } +}, { + NAME : DIALOGUE_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + notificationBase : { + + }, + + /** + * Whether to display the dialogue modally and with a + * lightbox style. + * + * @attribute lightbox + * @type Boolean + * @default true + */ + lightbox : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * Whether to display a close button on the dialogue. + * + * Note, we do not recommend hiding the close button as this has + * potential accessibility concerns. + * + * @attribute closeButton + * @type Boolean + * @default true + */ + closeButton : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * The title for the close button if one is to be shown. + * + * @attribute closeButtonTitle + * @type String + * @default 'Close' + */ + closeButtonTitle : { + validator : Y.Lang.isString, + value : 'Close' + }, + + /** + * Whether to display the dialogue centrally on the screen. + * + * @attribute center + * @type Boolean + * @default true + */ + center : { + validator : Y.Lang.isBoolean, + value : true + }, + + /** + * Whether to make the dialogue movable around the page. + * + * @attribute draggable + * @type Boolean + * @default false + */ + draggable : { + validator : Y.Lang.isBoolean, + value : false + }, + COUNT: { + value: 0 + } + } +}); + +M.core.dialogue = DIALOGUE; diff --git a/lib/yui/src/notification/js/exception.js b/lib/yui/src/notification/js/exception.js new file mode 100644 index 00000000000..ed4324c284b --- /dev/null +++ b/lib/yui/src/notification/js/exception.js @@ -0,0 +1,149 @@ +/** + * A dialogue type designed to display an appropriate error when a generic + * javascript error was thrown and caught. + * + * @module moodle-core-notification + * @submodule moodle-core-notification-exception + */ + +var EXCEPTION_NAME = 'Moodle exception', + EXCEPTION; + +/** + * Extends core Dialogue to show the exception dialogue. + * + * @param {Object} config Object literal specifying the dialogue configuration properties. + * @constructor + * @class M.core.exception + * @extends M.core.dialogue + */ +EXCEPTION = function(config) { + config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; + config.closeButton = true; + EXCEPTION.superclass.constructor.apply(this, [config]); +}; +Y.extend(EXCEPTION, M.core.dialogue, { + _hideTimeout : null, + _keypress : null, + initializer : function(config) { + var content, + self = this, + delay = this.get('hideTimeoutDelay'); + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, + '

' + config.name + '

', Y.WidgetStdMod.REPLACE); + content = Y.Node.create('
') + .append(Y.Node.create('
'+this.get('message')+'
')) + .append(Y.Node.create('')) + .append(Y.Node.create('')) + .append(Y.Node.create('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + if (delay) { + this._hideTimeout = setTimeout(function(){self.hide();}, delay); + } + this.after('visibleChange', this.visibilityChanged, this); + this.after('destroyedChange', function(){this.get(BASE).remove();}, this); + this._keypress = Y.on('key', this.hide, window, 'down:13,27', this); + this.centerDialogue(); + }, + visibilityChanged : function(e) { + if (e.attrName === 'visible' && e.prevVal && !e.newVal) { + if (this._keypress) { + this._keypress.detach(); + } + var self = this; + setTimeout(function(){self.destroy();}, 1000); + } + } +}, { + NAME : EXCEPTION_NAME, + CSS_PREFIX : DIALOGUE_PREFIX, + ATTRS : { + /** + * The message of the alert. + * + * @attribute message + * @type String + * @default '' + */ + message : { + value : '' + }, + + /** + * The name of the alert. + * + * @attribute title + * @type String + * @default '' + */ + name : { + value : '' + }, + + /** + * The name of the file where the error was thrown. + * + * @attribute fileName + * @type String + * @default '' + */ + fileName : { + value : '' + }, + + /** + * The line number where the error was thrown. + * + * @attribute lineNumber + * @type String + * @default '' + */ + lineNumber : { + value : '' + }, + + /** + * The backtrace from the error + * + * @attribute lineNumber + * @type String + * @default '' + */ + stack : { + setter : function(str) { + var lines = str.split("\n"), + pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'), + i; + for (i in lines) { + lines[i] = lines[i].replace(pattern, + "
ln: $4
$3
$1
"); + } + return lines.join(''); + }, + value : '' + }, + + /** + * If set, the dialogue is hidden after the specified timeout period. + * + * @attribute hideTimeoutDelay + * @type Number + * @default null + * @optional + */ + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +M.core.exception = EXCEPTION; diff --git a/lib/yui/src/notification/js/notification.js b/lib/yui/src/notification/js/notification.js index e15286dbc76..86559edab74 100644 --- a/lib/yui/src/notification/js/notification.js +++ b/lib/yui/src/notification/js/notification.js @@ -1,403 +1,25 @@ -var DIALOGUE_NAME = 'Moodle dialogue', - DIALOGUE_PREFIX = 'moodle-dialogue', - CONFIRM_NAME = 'Moodle confirmation dialogue', - EXCEPTION_NAME = 'Moodle exception', - AJAXEXCEPTION_NAME = 'Moodle AJAX exception', - ALERT_NAME = 'Moodle alert', - BASE = 'notificationBase', - COUNT = 0, - CONFIRMYES = 'yesLabel', - CONFIRMNO = 'noLabel', - TITLE = 'title', - QUESTION = 'question', - CSS = { - 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' - }, - EXCEPTION, - ALERT, - CONFIRM, - AJAXEXCEPTION, - DIALOGUE; +/** + * The notification module provides a standard set of dialogues for use + * within Moodle. + * + * @module moodle-core-notification + * @main + */ -DIALOGUE = function(config) { - COUNT++; - var id = 'moodle-dialogue-'+COUNT; - config.notificationBase = - Y.Node.create('
') - .append(Y.Node.create('') - .append(Y.Node.create('
')) - .append(Y.Node.create('
')) - .append(Y.Node.create('
'))); - Y.one(document.body).append(config.notificationBase); - config.srcNode = '#'+id; - config.width = config.width || '400px'; - config.visible = config.visible || false; - config.center = config.centered || true; - config.centered = false; - - // lightbox param to keep the stable versions API. - if (config.lightbox !== false) { - config.modal = true; - } - delete config.lightbox; - - // closeButton param to keep the stable versions API. - if (config.closeButton === false) { - config.buttons = null; - } else { - config.buttons = [ - { - section: Y.WidgetStdMod.HEADER, - classNames: 'closebutton', - action: function () { - this.hide(); - } - } - ]; - } - DIALOGUE.superclass.constructor.apply(this, [config]); - - if (config.closeButton !== false) { - // The buttons constructor does not allow custom attributes - this.get('buttons').header[0].setAttribute('title', this.get('closeButtonTitle')); - } -}; -Y.extend(DIALOGUE, Y.Panel, { - initializer : function() { - this.after('visibleChange', this.visibilityChanged, this); - this.render(); - this.show(); - - // Workaround upstream YUI bug http://yuilibrary.com/projects/yui3/ticket/2532507 - // and allow setting of z-index in theme. - this.get('boundingBox').setStyle('zIndex', null); - }, - visibilityChanged : function(e) { - var titlebar; - if (e.attrName === 'visible') { - this.get('maskNode').addClass(CSS.LIGHTBOX); - if (this.get('center') && !e.prevVal && e.newVal) { - this.centerDialogue(); - } - if (this.get('draggable')) { - titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; - this.plug(Y.Plugin.Drag, {handles : [titlebar]}); - Y.one(titlebar).setStyle('cursor', 'move'); - } - } - }, - centerDialogue : function() { - var bb = this.get('boundingBox'), - hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'), - x, y; - if (hidden) { - bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); - } - x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); - y = Math.max(Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2), 15) + Y.one(window).get('scrollTop'); - - if (hidden) { - bb.addClass(DIALOGUE_PREFIX+'-hidden'); - } - bb.setStyle('left', x).setStyle('top', y); - } -}, { - NAME : DIALOGUE_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - notificationBase : { - - }, - lightbox : { - validator : Y.Lang.isBoolean, - value : true - }, - closeButton : { - validator : Y.Lang.isBoolean, - value : true - }, - closeButtonTitle : { - validator : Y.Lang.isString, - value : 'Close' - }, - center : { - validator : Y.Lang.isBoolean, - value : true - }, - draggable : { - validator : Y.Lang.isBoolean, - value : false - } - } -}); - -ALERT = function(config) { - config.closeButton = false; - ALERT.superclass.constructor.apply(this, [config]); -}; -Y.extend(ALERT, DIALOGUE, { - _enterKeypress : null, - initializer : function() { - this.publish('complete'); - var yes = Y.Node.create(''), - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('message')+'
')) - .append(Y.Node.create('
') - .append(yes)); - this.get(BASE).addClass('moodle-dialogue-confirm'); - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this); - yes.on('click', this.submit, this); - }, - submit : function() { - this._enterKeypress.detach(); - this.fire('complete'); - this.hide(); - this.destroy(); - } -}, { - NAME : ALERT_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - title : { - validator : Y.Lang.isString, - value : 'Alert' - }, - message : { - validator : Y.Lang.isString, - value : 'Confirm' - }, - yesLabel : { - validator : Y.Lang.isString, - setter : function(txt) { - if (!txt) { - txt = 'Ok'; - } - return txt; - }, - value : 'Ok' - } - } -}); - -CONFIRM = function(config) { - CONFIRM.superclass.constructor.apply(this, [config]); -}; -Y.extend(CONFIRM, DIALOGUE, { - _enterKeypress : null, - _escKeypress : null, - initializer : function() { - 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)+'
')) - .append(Y.Node.create('
') - .append(yes) - .append(no)); - this.get(BASE).addClass('moodle-dialogue-confirm'); - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + this.get(TITLE) + '

', Y.WidgetStdMod.REPLACE); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true); - this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false); - yes.on('click', this.submit, this, true); - no.on('click', this.submit, this, false); - }, - submit : function(e, outcome) { - this._enterKeypress.detach(); - this._escKeypress.detach(); - this.fire('complete', outcome); - if (outcome) { - this.fire('complete-yes'); - } else { - this.fire('complete-no'); - } - this.hide(); - this.destroy(); - } -}, { - NAME : CONFIRM_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - yesLabel : { - validator : Y.Lang.isString, - value : 'Yes' - }, - noLabel : { - validator : Y.Lang.isString, - value : 'No' - }, - title : { - validator : Y.Lang.isString, - value : 'Confirm' - }, - question : { - validator : Y.Lang.isString, - value : 'Are you sure?' - } - } -}); -Y.augment(CONFIRM, Y.EventTarget); - -EXCEPTION = function(config) { - config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null; - config.closeButton = true; - EXCEPTION.superclass.constructor.apply(this, [config]); -}; -Y.extend(EXCEPTION, DIALOGUE, { - _hideTimeout : null, - _keypress : null, - initializer : function(config) { - var content, - self = this, - delay = this.get('hideTimeoutDelay'); - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + config.name + '

', Y.WidgetStdMod.REPLACE); - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('message')+'
')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - if (delay) { - this._hideTimeout = setTimeout(function(){self.hide();}, delay); - } - this.after('visibleChange', this.visibilityChanged, this); - this.after('destroyedChange', function(){this.get(BASE).remove();}, this); - this._keypress = Y.on('key', this.hide, window, 'down:13,27', this); - this.centerDialogue(); - }, - visibilityChanged : function(e) { - if (e.attrName === 'visible' && e.prevVal && !e.newVal) { - if (this._keypress) { - this._keypress.detach(); - } - var self = this; - setTimeout(function(){self.destroy();}, 1000); - } - } -}, { - NAME : EXCEPTION_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - message : { - value : '' - }, - name : { - value : '' - }, - fileName : { - value : '' - }, - lineNumber : { - value : '' - }, - stack : { - setter : function(str) { - var lines = str.split("\n"), - pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'), - i; - for (i in lines) { - lines[i] = lines[i].replace(pattern, - "
ln: $4
$3
$1
"); - } - return lines.join(''); - }, - value : '' - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -AJAXEXCEPTION = function(config) { - config.name = config.name || 'Error'; - config.closeButton = true; - AJAXEXCEPTION.superclass.constructor.apply(this, [config]); -}; -Y.extend(AJAXEXCEPTION, DIALOGUE, { - _keypress : null, - initializer : function(config) { - var content, - self = this, - delay = this.get('hideTimeoutDelay'); - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, '

' + config.name + '

', Y.WidgetStdMod.REPLACE); - content = Y.Node.create('
') - .append(Y.Node.create('
'+this.get('error')+'
')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - if (delay) { - this._hideTimeout = setTimeout(function(){self.hide();}, delay); - } - this.after('visibleChange', this.visibilityChanged, this); - this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this); - this.centerDialogue(); - }, - visibilityChanged : function(e) { - if (e.attrName === 'visible' && e.prevVal && !e.newVal) { - var self = this; - this._keypress.detach(); - setTimeout(function(){self.destroy();}, 1000); - } - } -}, { - NAME : AJAXEXCEPTION_NAME, - CSS_PREFIX : DIALOGUE_PREFIX, - ATTRS : { - error : { - validator : Y.Lang.isString, - value : 'Unknown error' - }, - debuginfo : { - value : null - }, - stacktrace : { - value : null - }, - reproductionlink : { - setter : function(link) { - if (link !== null) { - link = ''+link.replace(M.cfg.wwwroot, '')+''; - } - return link; - }, - value : null - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -M.core = M.core || {}; -M.core.dialogue = DIALOGUE; -M.core.alert = ALERT; -M.core.confirm = CONFIRM; -M.core.exception = EXCEPTION; -M.core.ajaxException = AJAXEXCEPTION; +/** + * To avoid bringing moodle-core-notification into modules in it's + * entirety, we now recommend using on of the subclasses of + * moodle-core-notification. These include: + *
+ *
moodle-core-notification-dialogue
+ *
moodle-core-notification-alert
+ *
moodle-core-notification-confirm
+ *
moodle-core-notification-exception
+ *
moodle-core-notification-ajaxexception
+ *
+ * + * @class M.core.notification + * @deprecated + */ +Y.log("The moodle-core-notification parent module has been deprecated. " + + "Please use one of its' subclasses instead.", 'moodle-core-notification', 'warn'); diff --git a/lib/yui/src/notification/js/shared.js b/lib/yui/src/notification/js/shared.js new file mode 100644 index 00000000000..6f7bc108fe7 --- /dev/null +++ b/lib/yui/src/notification/js/shared.js @@ -0,0 +1,29 @@ +var DIALOGUE_PREFIX, + BASE, + COUNT, + CONFIRMYES, + CONFIRMNO, + TITLE, + QUESTION, + CSS; + +DIALOGUE_PREFIX = 'moodle-dialogue', +BASE = 'notificationBase', +COUNT = 0, +CONFIRMYES = 'yesLabel', +CONFIRMNO = 'noLabel', +TITLE = 'title', +QUESTION = 'question', +CSS = { + 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' +}; + +// Set up the namespace once. +M.core = M.core || {}; diff --git a/lib/yui/src/notification/meta/notification.json b/lib/yui/src/notification/meta/notification.json index 739c8279ec7..ef33211e45b 100644 --- a/lib/yui/src/notification/meta/notification.json +++ b/lib/yui/src/notification/meta/notification.json @@ -1,5 +1,14 @@ { "moodle-core-notification": { + "requires": [ + "moodle-core-notification-dialogue", + "moodle-core-notification-alert", + "moodle-core-notification-confirm", + "moodle-core-notification-exception", + "moodle-core-notification-ajaxexception" + ] + }, + "moodle-core-notification-dialogue": { "requires": [ "base", "node", @@ -7,5 +16,25 @@ "event-key", "dd-plugin" ] + }, + "moodle-core-notification-alert": { + "requires": [ + "moodle-core-notification-dialogue" + ] + }, + "moodle-core-notification-confirm": { + "requires": [ + "moodle-core-notification-dialogue" + ] + }, + "moodle-core-notification-exception": { + "requires": [ + "moodle-core-notification-dialogue" + ] + }, + "moodle-core-notification-ajaxexception": { + "requires": [ + "moodle-core-notification-dialogue" + ] } }