From d2a27ab01bc3d9fd07c7ded2e32ea551a96cf4b0 Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Sat, 7 Jul 2012 11:31:55 +0100 Subject: [PATCH] MDL-29007 Rename moodle-enrol-notification to moodle-core-notification --- .../ui/yui/confirmcancel/confirmcancel.js | 2 +- blocks/community/yui/comments/comments.js | 4 +- .../yui/imagegallery/imagegallery.js | 2 +- course/yui/dragdrop/dragdrop.js | 2 +- .../yui/quickenrolment/quickenrolment.js | 2 +- .../yui/quickenrolment/quickenrolment.js | 2 +- enrol/yui/notification/notification.js | 390 +----------------- .../otherusersmanager/otherusersmanager.js | 2 +- enrol/yui/rolemanager/rolemanager.js | 2 +- filter/glossary/yui/autolinker/autolinker.js | 2 +- lib/upgrade.txt | 3 + lib/yui/blocks/blocks.js | 2 +- lib/yui/chooserdialogue/chooserdialogue.js | 2 +- lib/yui/dragdrop/dragdrop.js | 2 +- .../assets/skins/sam/notification.css | 0 .../notification/assets/skins/sam/sprite.png | Bin lib/yui/notification/notification.js | 385 +++++++++++++++++ 17 files changed, 407 insertions(+), 397 deletions(-) rename {enrol => lib}/yui/notification/assets/skins/sam/notification.css (100%) rename {enrol => lib}/yui/notification/assets/skins/sam/sprite.png (100%) create mode 100644 lib/yui/notification/notification.js diff --git a/backup/util/ui/yui/confirmcancel/confirmcancel.js b/backup/util/ui/yui/confirmcancel/confirmcancel.js index 6d84615e543..77deaf1c466 100644 --- a/backup/util/ui/yui/confirmcancel/confirmcancel.js +++ b/backup/util/ui/yui/confirmcancel/confirmcancel.js @@ -27,4 +27,4 @@ M.core_backup.watch_cancel_buttons = function(config) { }); } -}, '@VERSION@', {'requires':['base','node','node-event-simulate','moodle-enrol-notification']}); +}, '@VERSION@', {'requires':['base','node','node-event-simulate','moodle-core-notification']}); diff --git a/blocks/community/yui/comments/comments.js b/blocks/community/yui/comments/comments.js index 155a823c570..817e3ac5d8a 100644 --- a/blocks/community/yui/comments/comments.js +++ b/blocks/community/yui/comments/comments.js @@ -85,5 +85,5 @@ YUI.add('moodle-block_community-comments', function(Y) { } }, '@VERSION@', { - requires:['base','overlay', 'moodle-enrol-notification'] -}); \ No newline at end of file + requires:['base','overlay', 'moodle-core-notification'] +}); diff --git a/blocks/community/yui/imagegallery/imagegallery.js b/blocks/community/yui/imagegallery/imagegallery.js index f91abb08e42..e7072aaee87 100644 --- a/blocks/community/yui/imagegallery/imagegallery.js +++ b/blocks/community/yui/imagegallery/imagegallery.js @@ -195,5 +195,5 @@ YUI.add('moodle-block_community-imagegallery', function(Y) { } }, '@VERSION@', { - requires:['base','node','overlay', 'moodle-enrol-notification'] + requires:['base','node','overlay', 'moodle-core-notification'] }); diff --git a/course/yui/dragdrop/dragdrop.js b/course/yui/dragdrop/dragdrop.js index 435b3559bc1..431408d1ae1 100644 --- a/course/yui/dragdrop/dragdrop.js +++ b/course/yui/dragdrop/dragdrop.js @@ -411,4 +411,4 @@ YUI.add('moodle-course-dragdrop', function(Y) { M.course.init_section_dragdrop = function(params) { new DRAGSECTION(params); } -}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-enrol-notification', 'moodle-course-coursebase']}); +}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-core-notification', 'moodle-course-coursebase']}); diff --git a/enrol/cohort/yui/quickenrolment/quickenrolment.js b/enrol/cohort/yui/quickenrolment/quickenrolment.js index 7f5437ec137..6c22963ef33 100644 --- a/enrol/cohort/yui/quickenrolment/quickenrolment.js +++ b/enrol/cohort/yui/quickenrolment/quickenrolment.js @@ -381,4 +381,4 @@ YUI.add('moodle-enrol_cohort-quickenrolment', function(Y) { } } -}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-core-notification']}); diff --git a/enrol/manual/yui/quickenrolment/quickenrolment.js b/enrol/manual/yui/quickenrolment/quickenrolment.js index 88c09ea4dab..08f8d702823 100644 --- a/enrol/manual/yui/quickenrolment/quickenrolment.js +++ b/enrol/manual/yui/quickenrolment/quickenrolment.js @@ -524,4 +524,4 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { } } -}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-core-notification']}); diff --git a/enrol/yui/notification/notification.js b/enrol/yui/notification/notification.js index 8b9144331a9..f2bf542a384 100644 --- a/enrol/yui/notification/notification.js +++ b/enrol/yui/notification/notification.js @@ -1,385 +1,7 @@ +/** + * This module provides backwards compatability and should be removed + * entirely in Moodle 2.5 + */ YUI.add('moodle-enrol-notification', function(Y) { - -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', - C = Y.Node.create, - BASE = 'notificationBase', - LIGHTBOX = 'lightbox', - NODELIGHTBOX = 'nodeLightbox', - 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-fd', - HIDDEN : 'hidden', - LIGHTBOX : 'moodle-dialogue-lightbox' - }; - -var DIALOGUE = function(config) { - COUNT++; - var id = 'moodle-dialogue-'+COUNT; - config.notificationBase = - C('
') - .append(C('
')) - .append(C('
') - .append(C('
')) - .append(C('
')) - .append(C('
'))); - 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; - DIALOGUE.superclass.constructor.apply(this, [config]); -}; -Y.extend(DIALOGUE, Y.Overlay, { - initializer : function(config) { - this.set(NODELIGHTBOX, this.get(BASE).one('.'+CSS.LIGHTBOX).setStyle('opacity', 0.5)); - this.after('visibleChange', this.visibilityChanged, this); - this.after('headerContentChange', function(e){ - var h = (this.get('closeButton'))?this.get(BASE).one('.'+CSS.HEADER):false; - if (h && !h.one('.closebutton')) { - var c = C('
'); - c.on('click', this.hide, this); - h.append(c); - } - }, this); - this.render(); - this.show(); - }, - visibilityChanged : function(e) { - switch (e.attrName) { - case 'visible': - if (this.get(LIGHTBOX)) { - var l = this.get(NODELIGHTBOX); - if (!e.prevVal && e.newVal) { - l.setStyle('height',l.get('docHeight')+'px').removeClass(CSS.HIDDEN); - } else if (e.prevVal && !e.newVal) { - l.addClass(CSS.HIDDEN); - } - } - if (this.get('center') && !e.prevVal && e.newVal) { - this.centerDialogue(); - } - if (this.get('draggable')) { - var titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; - this.plug(Y.Plugin.Drag, {handles : [titlebar]}); - this.dd.addInvalid('div.closebutton'); - Y.one(titlebar).setStyle('cursor', 'move'); - } - break; - } - }, - centerDialogue : function() { - var bb = this.get('boundingBox'), hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'); - if (hidden) { - bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); - } - var x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); - var 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 : { - - }, - nodeLightbox : { - value : null - }, - lightbox : { - validator : Y.Lang.isBoolean, - value : true - }, - closeButton : { - validator : Y.Lang.isBoolean, - value : true - }, - center : { - validator : Y.Lang.isBoolean, - value : true - }, - draggable : { - validator : Y.Lang.isBoolean, - value : false - } - } -}); - -var ALERT = function(config) { - config.closeButton = false; - ALERT.superclass.constructor.apply(this, [config]); -}; -Y.extend(ALERT, DIALOGUE, { - _enterKeypress : null, - initializer : function(config) { - this.publish('complete'); - var yes = C(''), - content = C('
') - .append(C('
'+this.get('message')+'
')) - .append(C('
') - .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(e, outcome) { - 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' - } - } -}); - -var CONFIRM = function(config) { - CONFIRM.superclass.constructor.apply(this, [config]); -}; -Y.extend(CONFIRM, DIALOGUE, { - _enterKeypress : null, - _escKeypress : null, - initializer : function(config) { - this.publish('complete'); - this.publish('complete-yes'); - this.publish('complete-no'); - var yes = C(''), - no = C(''), - content = C('
') - .append(C('
'+this.get(QUESTION)+'
')) - .append(C('
') - .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); - -var 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) { - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE); - var content = C('
') - .append(C('
'+this.get('message')+'
')) - .append(C('')) - .append(C('')) - .append(C('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - var self = this; - var delay = this.get('hideTimeoutDelay'); - 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"); - var pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'); - for (var i in lines) { - lines[i] = lines[i].replace(pattern, "
ln: $4
$3
$1
"); - } - return lines.join(''); - }, - value : '' - }, - hideTimeoutDelay : { - validator : Y.Lang.isNumber, - value : null - } - } -}); - -var 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) { - this.get(BASE).addClass('moodle-dialogue-exception'); - this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE); - var content = C('
') - .append(C('
'+this.get('error')+'
')) - .append(C('')) - .append(C('')) - .append(C('')); - if (M.cfg.developerdebug) { - content.all('.moodle-exception-param').removeClass('hidden'); - } - this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); - - var self = this; - var delay = this.get('hideTimeoutDelay'); - 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','overlay','event-key', 'moodle-enrol-notification-skin', 'dd-plugin']}); + console.log("You are using a deprecated name. Please update your YUI module to use moodle-core-notification instead of moodle-enrol-notification"); +}, '@VERSION@', {requires:['base','node','overlay','event-key', 'moodle-core-notification']}); diff --git a/enrol/yui/otherusersmanager/otherusersmanager.js b/enrol/yui/otherusersmanager/otherusersmanager.js index 6685c1989fc..32b1ad87476 100644 --- a/enrol/yui/otherusersmanager/otherusersmanager.js +++ b/enrol/yui/otherusersmanager/otherusersmanager.js @@ -391,4 +391,4 @@ YUI.add('moodle-enrol-otherusersmanager', function(Y) { } } -}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']}); \ No newline at end of file +}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-core-notification']}); diff --git a/enrol/yui/rolemanager/rolemanager.js b/enrol/yui/rolemanager/rolemanager.js index a03bc3502f5..afa52c2beb4 100644 --- a/enrol/yui/rolemanager/rolemanager.js +++ b/enrol/yui/rolemanager/rolemanager.js @@ -416,4 +416,4 @@ YUI.add('moodle-enrol-rolemanager', function(Y) { } } -}, '@VERSION@', {requires:['base','node','io-base','json-parse','test','moodle-enrol-notification']}); \ No newline at end of file +}, '@VERSION@', {requires:['base','node','io-base','json-parse','test','moodle-core-notification']}); diff --git a/filter/glossary/yui/autolinker/autolinker.js b/filter/glossary/yui/autolinker/autolinker.js index 484c42ef21b..1a1586df4a2 100644 --- a/filter/glossary/yui/autolinker/autolinker.js +++ b/filter/glossary/yui/autolinker/autolinker.js @@ -130,4 +130,4 @@ YUI.add('moodle-filter_glossary-autolinker', function(Y) { return new AUTOLINKER(config); } -}, '@VERSION@', {requires:['base','node','io-base','json-parse','event-delegate','overlay','moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base','node','io-base','json-parse','event-delegate','overlay','moodle-core-notification']}); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 58682c5673f..d3bc9c16f35 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -6,6 +6,9 @@ information provided here is intended especially for developers. * Pagelib: Numerous deprecated functions were removed as classes page_base, page_course and page_generic_activity. +YUI changes: +* moodle-enrol-notification has been renamed to moodle-core-notification + === 2.3 === Database layer changes: diff --git a/lib/yui/blocks/blocks.js b/lib/yui/blocks/blocks.js index cec719f859b..f487b02fba1 100644 --- a/lib/yui/blocks/blocks.js +++ b/lib/yui/blocks/blocks.js @@ -268,5 +268,5 @@ YUI.add('moodle-core-blocks', function(Y) { M.core_blocks.init_dragdrop = function(params) { new DRAGBLOCK(params); } -}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'dd-scroll', 'moodle-core-dragdrop', 'moodle-core-notification']}); diff --git a/lib/yui/chooserdialogue/chooserdialogue.js b/lib/yui/chooserdialogue/chooserdialogue.js index 9560b3e7880..874bb938c6c 100644 --- a/lib/yui/chooserdialogue/chooserdialogue.js +++ b/lib/yui/chooserdialogue/chooserdialogue.js @@ -303,6 +303,6 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { M.core.chooserdialogue = CHOOSERDIALOGUE; }, '@VERSION@', { - requires:['base', 'overlay', 'moodle-enrol-notification'] + requires:['base', 'overlay', 'moodle-core-notification'] } ); diff --git a/lib/yui/dragdrop/dragdrop.js b/lib/yui/dragdrop/dragdrop.js index 6669f37126a..db4c73aaad5 100644 --- a/lib/yui/dragdrop/dragdrop.js +++ b/lib/yui/dragdrop/dragdrop.js @@ -200,4 +200,4 @@ YUI.add('moodle-core-dragdrop', function(Y) { M.core = M.core || {}; M.core.dragdrop = DRAGDROP; -}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'moodle-enrol-notification']}); +}, '@VERSION@', {requires:['base', 'node', 'io', 'dom', 'dd', 'moodle-core-notification']}); diff --git a/enrol/yui/notification/assets/skins/sam/notification.css b/lib/yui/notification/assets/skins/sam/notification.css similarity index 100% rename from enrol/yui/notification/assets/skins/sam/notification.css rename to lib/yui/notification/assets/skins/sam/notification.css diff --git a/enrol/yui/notification/assets/skins/sam/sprite.png b/lib/yui/notification/assets/skins/sam/sprite.png similarity index 100% rename from enrol/yui/notification/assets/skins/sam/sprite.png rename to lib/yui/notification/assets/skins/sam/sprite.png diff --git a/lib/yui/notification/notification.js b/lib/yui/notification/notification.js new file mode 100644 index 00000000000..3df1c5292d3 --- /dev/null +++ b/lib/yui/notification/notification.js @@ -0,0 +1,385 @@ +YUI.add('moodle-core-notification', function(Y) { + +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', + C = Y.Node.create, + BASE = 'notificationBase', + LIGHTBOX = 'lightbox', + NODELIGHTBOX = 'nodeLightbox', + 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-fd', + HIDDEN : 'hidden', + LIGHTBOX : 'moodle-dialogue-lightbox' + }; + +var DIALOGUE = function(config) { + COUNT++; + var id = 'moodle-dialogue-'+COUNT; + config.notificationBase = + C('
') + .append(C('
')) + .append(C('
') + .append(C('
')) + .append(C('
')) + .append(C('
'))); + 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; + DIALOGUE.superclass.constructor.apply(this, [config]); +}; +Y.extend(DIALOGUE, Y.Overlay, { + initializer : function(config) { + this.set(NODELIGHTBOX, this.get(BASE).one('.'+CSS.LIGHTBOX).setStyle('opacity', 0.5)); + this.after('visibleChange', this.visibilityChanged, this); + this.after('headerContentChange', function(e){ + var h = (this.get('closeButton'))?this.get(BASE).one('.'+CSS.HEADER):false; + if (h && !h.one('.closebutton')) { + var c = C('
'); + c.on('click', this.hide, this); + h.append(c); + } + }, this); + this.render(); + this.show(); + }, + visibilityChanged : function(e) { + switch (e.attrName) { + case 'visible': + if (this.get(LIGHTBOX)) { + var l = this.get(NODELIGHTBOX); + if (!e.prevVal && e.newVal) { + l.setStyle('height',l.get('docHeight')+'px').removeClass(CSS.HIDDEN); + } else if (e.prevVal && !e.newVal) { + l.addClass(CSS.HIDDEN); + } + } + if (this.get('center') && !e.prevVal && e.newVal) { + this.centerDialogue(); + } + if (this.get('draggable')) { + var titlebar = '#' + this.get('id') + ' .' + CSS.HEADER; + this.plug(Y.Plugin.Drag, {handles : [titlebar]}); + this.dd.addInvalid('div.closebutton'); + Y.one(titlebar).setStyle('cursor', 'move'); + } + break; + } + }, + centerDialogue : function() { + var bb = this.get('boundingBox'), hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden'); + if (hidden) { + bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden'); + } + var x = Math.max(Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2), 15); + var 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 : { + + }, + nodeLightbox : { + value : null + }, + lightbox : { + validator : Y.Lang.isBoolean, + value : true + }, + closeButton : { + validator : Y.Lang.isBoolean, + value : true + }, + center : { + validator : Y.Lang.isBoolean, + value : true + }, + draggable : { + validator : Y.Lang.isBoolean, + value : false + } + } +}); + +var ALERT = function(config) { + config.closeButton = false; + ALERT.superclass.constructor.apply(this, [config]); +}; +Y.extend(ALERT, DIALOGUE, { + _enterKeypress : null, + initializer : function(config) { + this.publish('complete'); + var yes = C(''), + content = C('
') + .append(C('
'+this.get('message')+'
')) + .append(C('
') + .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(e, outcome) { + 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' + } + } +}); + +var CONFIRM = function(config) { + CONFIRM.superclass.constructor.apply(this, [config]); +}; +Y.extend(CONFIRM, DIALOGUE, { + _enterKeypress : null, + _escKeypress : null, + initializer : function(config) { + this.publish('complete'); + this.publish('complete-yes'); + this.publish('complete-no'); + var yes = C(''), + no = C(''), + content = C('
') + .append(C('
'+this.get(QUESTION)+'
')) + .append(C('
') + .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); + +var 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) { + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE); + var content = C('
') + .append(C('
'+this.get('message')+'
')) + .append(C('')) + .append(C('')) + .append(C('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + var self = this; + var delay = this.get('hideTimeoutDelay'); + 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"); + var pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$'); + for (var i in lines) { + lines[i] = lines[i].replace(pattern, "
ln: $4
$3
$1
"); + } + return lines.join(''); + }, + value : '' + }, + hideTimeoutDelay : { + validator : Y.Lang.isNumber, + value : null + } + } +}); + +var 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) { + this.get(BASE).addClass('moodle-dialogue-exception'); + this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE); + var content = C('
') + .append(C('
'+this.get('error')+'
')) + .append(C('')) + .append(C('')) + .append(C('')); + if (M.cfg.developerdebug) { + content.all('.moodle-exception-param').removeClass('hidden'); + } + this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE); + + var self = this; + var delay = this.get('hideTimeoutDelay'); + 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','overlay','event-key', 'moodle-core-notification-skin', 'dd-plugin']});