From b810c84f2bf36255143bd4e49ada6f4d02a60e3a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 14 Apr 2020 09:03:46 +0800 Subject: [PATCH] MDL-68409 js: Add Alert modal --- lang/en/moodle.php | 1 + lib/amd/build/modal_factory.min.js | 2 +- lib/amd/build/modal_factory.min.js.map | 2 +- lib/amd/src/modal_factory.js | 7 ++-- lib/templates/local/modal/alert.mustache | 45 ++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 lib/templates/local/modal/alert.mustache diff --git a/lang/en/moodle.php b/lang/en/moodle.php index f0a53e98018..4885cc4598e 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1499,6 +1499,7 @@ $string['numwords'] = '{$a} words'; $string['numyear'] = '{$a} year'; $string['numyears'] = '{$a} years'; $string['ok'] = 'OK'; +$string['okay'] = 'Ok'; $string['oldpassword'] = 'Current password'; $string['olduserdirectory'] = 'This is the OLD users directory, and is no longer needed. You may safely delete it. The files it contains have been copied to the NEW user directory.'; $string['optional'] = 'optional'; diff --git a/lib/amd/build/modal_factory.min.js b/lib/amd/build/modal_factory.min.js index 7f1a73f9053..87e5370af77 100644 --- a/lib/amd/build/modal_factory.min.js +++ b/lib/amd/build/modal_factory.min.js @@ -1,2 +1,2 @@ -function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function _arrayWithHoles(a){if(Array.isArray(a))return a}define ("core/modal_factory",["jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events","core/pending"],function(a,b,c,d,e,f,g,h,i,j){var k={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CANCEL:"core/modal_cancel"},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CANCEL:"CANCEL"};c.register(l.DEFAULT,d,k.DEFAULT);c.register(l.SAVE_CANCEL,e,k.SAVE_CANCEL);c.register(l.CANCEL,f,k.CANCEL);var m=function(c,d,e){var f=null,g="function"==typeof e.preShowCallback,h=function(b,d){var h=new j("core/modal_factory:setUpTrigger:triggeredCallback");f=a(b.currentTarget);c.then(function(a){if(g){e.preShowCallback(f,a)}a.show();return a}).then(h.resolve);d.originalEvent.preventDefault()};if(Array.isArray(d)){var k=d[1];d=d[0];i.define(d,[i.events.activate]);d.on(i.events.activate,k,h)}else{i.define(d,[i.events.activate]);d.on(i.events.activate,h)}c.then(function(a){a.getRoot().on(b.hidden,function(){if(null!==f){f.focus()}});return a})},n=function(b,c){c=a(c);var d=b.module,e=new d(c);return e},o=function(b,c){var d=b.template,e=g.render(d,c).then(function(c){var d=a(c);return n(b,d)}).fail(h.exception);return e};return{create:function create(a,b){var d=a.type||l.DEFAULT,e=a.large?!0:!1,f=null,g={};f=c.get(d);if(!f){h.exception({message:"Unable to find modal of type: "+d})}if("undefined"!=typeof a.templateContext){g=a.templateContext}var i=o(f,g).then(function(b){if("undefined"!=typeof a.title){b.setTitle(a.title)}if("undefined"!=typeof a.body){b.setBody(a.body)}if("undefined"!=typeof a.footer){b.setFooter(a.footer)}if(a.buttons){Object.entries(a.buttons).forEach(function(a){var c=_slicedToArray(a,2),d=c[0],e=c[1];b.setButtonText(d,e)})}if(e){b.setLarge()}if("undefined"!=typeof a.removeOnClose){b.setRemoveOnClose(a.removeOnClose)}return b});if("undefined"!=typeof b){m(i,b,a)}return i},types:l}}); +function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function _arrayWithHoles(a){if(Array.isArray(a))return a}define ("core/modal_factory",["jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_cancel","core/local/modal/alert","core/templates","core/notification","core/custom_interaction_events","core/pending"],function(a,b,c,d,e,f,g,h,i,j,k){var l={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CANCEL:"core/modal_cancel",ALERT:"core/local/modal/alert"},m={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CANCEL:"CANCEL",ALERT:"ALERT"};c.register(m.DEFAULT,d,l.DEFAULT);c.register(m.SAVE_CANCEL,e,l.SAVE_CANCEL);c.register(m.CANCEL,f,l.CANCEL);c.register(m.ALERT,g,l.ALERT);var n=function(c,d,e){var f=null,g="function"==typeof e.preShowCallback,h=function(b,d){var h=new k("core/modal_factory:setUpTrigger:triggeredCallback");f=a(b.currentTarget);c.then(function(a){if(g){e.preShowCallback(f,a)}a.show();return a}).then(h.resolve);d.originalEvent.preventDefault()};if(Array.isArray(d)){var i=d[1];d=d[0];j.define(d,[j.events.activate]);d.on(j.events.activate,i,h)}else{j.define(d,[j.events.activate]);d.on(j.events.activate,h)}c.then(function(a){a.getRoot().on(b.hidden,function(){if(null!==f){f.focus()}});return a})},o=function(b,c){c=a(c);var d=b.module,e=new d(c);return e},p=function(b,c){var d=b.template,e=h.render(d,c).then(function(c){var d=a(c);return o(b,d)}).fail(i.exception);return e};return{create:function create(a,b){var d=a.type||m.DEFAULT,e=a.large?!0:!1,f=null,g={};f=c.get(d);if(!f){i.exception({message:"Unable to find modal of type: "+d})}if("undefined"!=typeof a.templateContext){g=a.templateContext}var h=p(f,g).then(function(b){if("undefined"!=typeof a.title){b.setTitle(a.title)}if("undefined"!=typeof a.body){b.setBody(a.body)}if("undefined"!=typeof a.footer){b.setFooter(a.footer)}if(a.buttons){Object.entries(a.buttons).forEach(function(a){var c=_slicedToArray(a,2),d=c[0],e=c[1];b.setButtonText(d,e)})}if(e){b.setLarge()}if("undefined"!=typeof a.removeOnClose){b.setRemoveOnClose(a.removeOnClose)}return b});if("undefined"!=typeof b){n(h,b,a)}return h},types:m}}); //# sourceMappingURL=modal_factory.min.js.map diff --git a/lib/amd/build/modal_factory.min.js.map b/lib/amd/build/modal_factory.min.js.map index 93f24aa60c3..5d1aafdf254 100644 --- a/lib/amd/build/modal_factory.min.js.map +++ b/lib/amd/build/modal_factory.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/modal_factory.js"],"names":["define","$","ModalEvents","ModalRegistry","Modal","ModalSaveCancel","ModalCancel","Templates","Notification","CustomEvents","Pending","TEMPLATES","DEFAULT","SAVE_CANCEL","CANCEL","TYPES","register","setUpTrigger","modalPromise","triggerElement","modalConfig","actualTriggerElement","hasPreShowCallback","preShowCallback","triggeredCallback","e","data","pendingPromise","currentTarget","then","modal","show","resolve","originalEvent","preventDefault","Array","isArray","selector","events","activate","on","getRoot","hidden","focus","createFromElement","registryConf","modalElement","module","createFromType","templateContext","templateName","template","render","html","fail","exception","create","type","isLarge","large","get","message","title","setTitle","body","setBody","footer","setFooter","buttons","Object","entries","forEach","key","value","setButtonText","setLarge","removeOnClose","setRemoveOnClose","types"],"mappings":"whBAwBAA,OAAM,sBAAC,CAAC,QAAD,CAAW,mBAAX,CAAgC,qBAAhC,CAAuD,YAAvD,CACC,wBADD,CAC2B,mBAD3B,CAEC,gBAFD,CAEmB,mBAFnB,CAEwC,gCAFxC,CAGC,cAHD,CAAD,CAIF,SAASC,CAAT,CAAYC,CAAZ,CAAyBC,CAAzB,CAAwCC,CAAxC,CAA+CC,CAA/C,CACIC,CADJ,CACiBC,CADjB,CAC4BC,CAD5B,C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C,MAAvB,CAA8C,CAC1CpC,CAAK,CAACqC,SAAN,CAAgB/C,CAAW,CAAC8C,MAA5B,CACH,CAED,GAAI9C,CAAW,CAACgD,OAAhB,CAAyB,CACrBC,MAAM,CAACC,OAAP,CAAelD,CAAW,CAACgD,OAA3B,EAAoCG,OAApC,CAA4C,WAAuB,2BAAbC,CAAa,MAARC,CAAQ,MAC/D3C,CAAK,CAAC4C,aAAN,CAAoBF,CAApB,CAAyBC,CAAzB,CACH,CAFD,CAGH,CAED,GAAIf,CAAJ,CAAa,CACT5B,CAAK,CAAC6C,QAAN,EACH,CAED,GAAyC,WAArC,QAAOvD,CAAAA,CAAW,CAACwD,aAAvB,CAAsD,CAElD9C,CAAK,CAAC+C,gBAAN,CAAuBzD,CAAW,CAACwD,aAAnC,CACH,CAED,MAAO9C,CAAAA,CACV,CA9Bc,CAAnB,CAgCA,GAA6B,WAAzB,QAAOX,CAAAA,CAAX,CAA0C,CACtCF,CAAY,CAACC,CAAD,CAAeC,CAAf,CAA+BC,CAA/B,CACf,CAED,MAAOF,CAAAA,CACV,CAEM,CAEH4D,KAAK,CAAE/D,CAFJ,CAIV,CAhMK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Create a modal.\n *\n * @module core/modal_factory\n * @class modal_factory\n * @package core\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',\n 'core/modal_save_cancel', 'core/modal_cancel',\n 'core/templates', 'core/notification', 'core/custom_interaction_events',\n 'core/pending'],\n function($, ModalEvents, ModalRegistry, Modal, ModalSaveCancel,\n ModalCancel, Templates, Notification, CustomEvents, Pending) {\n\n // The templates for each type of modal.\n var TEMPLATES = {\n DEFAULT: 'core/modal',\n SAVE_CANCEL: 'core/modal_save_cancel',\n CANCEL: 'core/modal_cancel',\n };\n\n // The available types of modals.\n var TYPES = {\n DEFAULT: 'DEFAULT',\n SAVE_CANCEL: 'SAVE_CANCEL',\n CANCEL: 'CANCEL',\n };\n\n // Register the common set of modals.\n ModalRegistry.register(TYPES.DEFAULT, Modal, TEMPLATES.DEFAULT);\n ModalRegistry.register(TYPES.SAVE_CANCEL, ModalSaveCancel, TEMPLATES.SAVE_CANCEL);\n ModalRegistry.register(TYPES.CANCEL, ModalCancel, TEMPLATES.CANCEL);\n\n /**\n * Set up the events required to show the modal and return focus when the modal\n * is closed.\n *\n * @method setUpTrigger\n * @param {Promise} modalPromise The modal instance\n * @param {object} triggerElement The jQuery element to open the modal\n * @param {object} modalConfig The modal configuration given to the factory\n */\n var setUpTrigger = function(modalPromise, triggerElement, modalConfig) {\n // The element that actually shows the modal.\n var actualTriggerElement = null;\n // Check if the client has provided a callback function to be called\n // before the modal is displayed.\n var hasPreShowCallback = (typeof modalConfig.preShowCallback == 'function');\n // Function to handle the trigger element being activated.\n var triggeredCallback = function(e, data) {\n var pendingPromise = new Pending('core/modal_factory:setUpTrigger:triggeredCallback');\n actualTriggerElement = $(e.currentTarget);\n modalPromise.then(function(modal) {\n if (hasPreShowCallback) {\n // If the client provided a pre-show callback then execute\n // it now before showing the modal.\n modalConfig.preShowCallback(actualTriggerElement, modal);\n }\n\n modal.show();\n\n return modal;\n })\n .then(pendingPromise.resolve);\n data.originalEvent.preventDefault();\n };\n\n // The trigger element can either be a single element or it can be an\n // element + selector pair to create a delegated event handler to trigger\n // the modal.\n if (Array.isArray(triggerElement)) {\n var selector = triggerElement[1];\n triggerElement = triggerElement[0];\n\n CustomEvents.define(triggerElement, [CustomEvents.events.activate]);\n triggerElement.on(CustomEvents.events.activate, selector, triggeredCallback);\n } else {\n CustomEvents.define(triggerElement, [CustomEvents.events.activate]);\n triggerElement.on(CustomEvents.events.activate, triggeredCallback);\n }\n\n modalPromise.then(function(modal) {\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Focus on the trigger element that actually launched the modal.\n if (actualTriggerElement !== null) {\n actualTriggerElement.focus();\n }\n });\n\n return modal;\n });\n };\n\n /**\n * Create the correct instance of a modal based on the givem type. Sets up\n * the trigger between the modal and the trigger element.\n *\n * @method createFromElement\n * @param {object} registryConf A config from the ModalRegistry\n * @param {object} modalElement The modal HTML jQuery object\n * @return {object} Modal instance\n */\n var createFromElement = function(registryConf, modalElement) {\n modalElement = $(modalElement);\n var module = registryConf.module;\n var modal = new module(modalElement);\n\n return modal;\n };\n\n /**\n * Create the correct modal instance for the given type, including loading\n * the correct template.\n *\n * @method createFromType\n * @param {object} registryConf A config from the ModalRegistry\n * @param {object} templateContext The context to render the template with\n * @return {promise} Resolved with a Modal instance\n */\n var createFromType = function(registryConf, templateContext) {\n var templateName = registryConf.template;\n\n var modalPromise = Templates.render(templateName, templateContext)\n .then(function(html) {\n var modalElement = $(html);\n return createFromElement(registryConf, modalElement);\n })\n .fail(Notification.exception);\n\n return modalPromise;\n };\n\n /**\n * Create a Modal instance.\n *\n * @method create\n * @param {object} modalConfig The configuration to create the modal instance\n * @param {object} triggerElement The trigger HTML jQuery object\n * @return {promise} Resolved with a Modal instance\n */\n var create = function(modalConfig, triggerElement) {\n var type = modalConfig.type || TYPES.DEFAULT;\n var isLarge = modalConfig.large ? true : false;\n var registryConf = null;\n var templateContext = {};\n\n registryConf = ModalRegistry.get(type);\n\n if (!registryConf) {\n Notification.exception({message: 'Unable to find modal of type: ' + type});\n }\n\n if (typeof modalConfig.templateContext != 'undefined') {\n templateContext = modalConfig.templateContext;\n }\n\n var modalPromise = createFromType(registryConf, templateContext)\n .then(function(modal) {\n if (typeof modalConfig.title != 'undefined') {\n modal.setTitle(modalConfig.title);\n }\n\n if (typeof modalConfig.body != 'undefined') {\n modal.setBody(modalConfig.body);\n }\n\n if (typeof modalConfig.footer != 'undefined') {\n modal.setFooter(modalConfig.footer);\n }\n\n if (modalConfig.buttons) {\n Object.entries(modalConfig.buttons).forEach(function([key, value]) {\n modal.setButtonText(key, value);\n });\n }\n\n if (isLarge) {\n modal.setLarge();\n }\n\n if (typeof modalConfig.removeOnClose !== 'undefined') {\n // If configured remove the modal when hiding it.\n modal.setRemoveOnClose(modalConfig.removeOnClose);\n }\n\n return modal;\n });\n\n if (typeof triggerElement != 'undefined') {\n setUpTrigger(modalPromise, triggerElement, modalConfig);\n }\n\n return modalPromise;\n };\n\n return {\n create: create,\n types: TYPES,\n };\n});\n"],"file":"modal_factory.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/modal_factory.js"],"names":["define","$","ModalEvents","ModalRegistry","Modal","ModalSaveCancel","ModalCancel","ModalAlert","Templates","Notification","CustomEvents","Pending","TEMPLATES","DEFAULT","SAVE_CANCEL","CANCEL","ALERT","TYPES","register","setUpTrigger","modalPromise","triggerElement","modalConfig","actualTriggerElement","hasPreShowCallback","preShowCallback","triggeredCallback","e","data","pendingPromise","currentTarget","then","modal","show","resolve","originalEvent","preventDefault","Array","isArray","selector","events","activate","on","getRoot","hidden","focus","createFromElement","registryConf","modalElement","module","createFromType","templateContext","templateName","template","render","html","fail","exception","create","type","isLarge","large","get","message","title","setTitle","body","setBody","footer","setFooter","buttons","Object","entries","forEach","key","value","setButtonText","setLarge","removeOnClose","setRemoveOnClose","types"],"mappings":"whBAwBAA,OAAM,sBAAC,CAAC,QAAD,CAAW,mBAAX,CAAgC,qBAAhC,CAAuD,YAAvD,CACC,wBADD,CAC2B,mBAD3B,CACgD,wBADhD,CAEC,gBAFD,CAEmB,mBAFnB,CAEwC,gCAFxC,CAGC,cAHD,CAAD,CAIF,SAASC,CAAT,CAAYC,CAAZ,CAAyBC,CAAzB,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AA6C,CACzChC,CAAK,CAACiC,QAAN,CAAe3C,CAAW,CAAC0C,KAA3B,CACH,CAED,GAA+B,WAA3B,QAAO1C,CAAAA,CAAW,CAAC4C,IAAvB,CAA4C,CACxClC,CAAK,CAACmC,OAAN,CAAc7C,CAAW,CAAC4C,IAA1B,CACH,CAED,GAAiC,WAA7B,QAAO5C,CAAAA,CAAW,CAAC8C,MAAvB,CAA8C,CAC1CpC,CAAK,CAACqC,SAAN,CAAgB/C,CAAW,CAAC8C,MAA5B,CACH,CAED,GAAI9C,CAAW,CAACgD,OAAhB,CAAyB,CACrBC,MAAM,CAACC,OAAP,CAAelD,CAAW,CAACgD,OAA3B,EAAoCG,OAApC,CAA4C,WAAuB,2BAAbC,CAAa,MAARC,CAAQ,MAC/D3C,CAAK,CAAC4C,aAAN,CAAoBF,CAApB,CAAyBC,CAAzB,CACH,CAFD,CAGH,CAED,GAAIf,CAAJ,CAAa,CACT5B,CAAK,CAAC6C,QAAN,EACH,CAED,GAAyC,WAArC,QAAOvD,CAAAA,CAAW,CAACwD,aAAvB,CAAsD,CAElD9C,CAAK,CAAC+C,gBAAN,CAAuBzD,CAAW,CAACwD,aAAnC,CACH,CAED,MAAO9C,CAAAA,CACV,CA9Bc,CAAnB,CAgCA,GAA6B,WAAzB,QAAOX,CAAAA,CAAX,CAA0C,CACtCF,CAAY,CAACC,CAAD,CAAeC,CAAf,CAA+BC,CAA/B,CACf,CAED,MAAOF,CAAAA,CACV,CAEM,CAEH4D,KAAK,CAAE/D,CAFJ,CAIV,CAnMK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Create a modal.\n *\n * @module core/modal_factory\n * @class modal_factory\n * @package core\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',\n 'core/modal_save_cancel', 'core/modal_cancel', 'core/local/modal/alert',\n 'core/templates', 'core/notification', 'core/custom_interaction_events',\n 'core/pending'],\n function($, ModalEvents, ModalRegistry, Modal, ModalSaveCancel,\n ModalCancel, ModalAlert, Templates, Notification, CustomEvents, Pending) {\n\n // The templates for each type of modal.\n var TEMPLATES = {\n DEFAULT: 'core/modal',\n SAVE_CANCEL: 'core/modal_save_cancel',\n CANCEL: 'core/modal_cancel',\n ALERT: 'core/local/modal/alert',\n };\n\n // The available types of modals.\n var TYPES = {\n DEFAULT: 'DEFAULT',\n SAVE_CANCEL: 'SAVE_CANCEL',\n CANCEL: 'CANCEL',\n ALERT: 'ALERT',\n };\n\n // Register the common set of modals.\n ModalRegistry.register(TYPES.DEFAULT, Modal, TEMPLATES.DEFAULT);\n ModalRegistry.register(TYPES.SAVE_CANCEL, ModalSaveCancel, TEMPLATES.SAVE_CANCEL);\n ModalRegistry.register(TYPES.CANCEL, ModalCancel, TEMPLATES.CANCEL);\n ModalRegistry.register(TYPES.ALERT, ModalAlert, TEMPLATES.ALERT);\n\n /**\n * Set up the events required to show the modal and return focus when the modal\n * is closed.\n *\n * @method setUpTrigger\n * @param {Promise} modalPromise The modal instance\n * @param {object} triggerElement The jQuery element to open the modal\n * @param {object} modalConfig The modal configuration given to the factory\n */\n var setUpTrigger = function(modalPromise, triggerElement, modalConfig) {\n // The element that actually shows the modal.\n var actualTriggerElement = null;\n // Check if the client has provided a callback function to be called\n // before the modal is displayed.\n var hasPreShowCallback = (typeof modalConfig.preShowCallback == 'function');\n // Function to handle the trigger element being activated.\n var triggeredCallback = function(e, data) {\n var pendingPromise = new Pending('core/modal_factory:setUpTrigger:triggeredCallback');\n actualTriggerElement = $(e.currentTarget);\n modalPromise.then(function(modal) {\n if (hasPreShowCallback) {\n // If the client provided a pre-show callback then execute\n // it now before showing the modal.\n modalConfig.preShowCallback(actualTriggerElement, modal);\n }\n\n modal.show();\n\n return modal;\n })\n .then(pendingPromise.resolve);\n data.originalEvent.preventDefault();\n };\n\n // The trigger element can either be a single element or it can be an\n // element + selector pair to create a delegated event handler to trigger\n // the modal.\n if (Array.isArray(triggerElement)) {\n var selector = triggerElement[1];\n triggerElement = triggerElement[0];\n\n CustomEvents.define(triggerElement, [CustomEvents.events.activate]);\n triggerElement.on(CustomEvents.events.activate, selector, triggeredCallback);\n } else {\n CustomEvents.define(triggerElement, [CustomEvents.events.activate]);\n triggerElement.on(CustomEvents.events.activate, triggeredCallback);\n }\n\n modalPromise.then(function(modal) {\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Focus on the trigger element that actually launched the modal.\n if (actualTriggerElement !== null) {\n actualTriggerElement.focus();\n }\n });\n\n return modal;\n });\n };\n\n /**\n * Create the correct instance of a modal based on the givem type. Sets up\n * the trigger between the modal and the trigger element.\n *\n * @method createFromElement\n * @param {object} registryConf A config from the ModalRegistry\n * @param {object} modalElement The modal HTML jQuery object\n * @return {object} Modal instance\n */\n var createFromElement = function(registryConf, modalElement) {\n modalElement = $(modalElement);\n var module = registryConf.module;\n var modal = new module(modalElement);\n\n return modal;\n };\n\n /**\n * Create the correct modal instance for the given type, including loading\n * the correct template.\n *\n * @method createFromType\n * @param {object} registryConf A config from the ModalRegistry\n * @param {object} templateContext The context to render the template with\n * @return {promise} Resolved with a Modal instance\n */\n var createFromType = function(registryConf, templateContext) {\n var templateName = registryConf.template;\n\n var modalPromise = Templates.render(templateName, templateContext)\n .then(function(html) {\n var modalElement = $(html);\n return createFromElement(registryConf, modalElement);\n })\n .fail(Notification.exception);\n\n return modalPromise;\n };\n\n /**\n * Create a Modal instance.\n *\n * @method create\n * @param {object} modalConfig The configuration to create the modal instance\n * @param {object} triggerElement The trigger HTML jQuery object\n * @return {promise} Resolved with a Modal instance\n */\n var create = function(modalConfig, triggerElement) {\n var type = modalConfig.type || TYPES.DEFAULT;\n var isLarge = modalConfig.large ? true : false;\n var registryConf = null;\n var templateContext = {};\n\n registryConf = ModalRegistry.get(type);\n\n if (!registryConf) {\n Notification.exception({message: 'Unable to find modal of type: ' + type});\n }\n\n if (typeof modalConfig.templateContext != 'undefined') {\n templateContext = modalConfig.templateContext;\n }\n\n var modalPromise = createFromType(registryConf, templateContext)\n .then(function(modal) {\n if (typeof modalConfig.title != 'undefined') {\n modal.setTitle(modalConfig.title);\n }\n\n if (typeof modalConfig.body != 'undefined') {\n modal.setBody(modalConfig.body);\n }\n\n if (typeof modalConfig.footer != 'undefined') {\n modal.setFooter(modalConfig.footer);\n }\n\n if (modalConfig.buttons) {\n Object.entries(modalConfig.buttons).forEach(function([key, value]) {\n modal.setButtonText(key, value);\n });\n }\n\n if (isLarge) {\n modal.setLarge();\n }\n\n if (typeof modalConfig.removeOnClose !== 'undefined') {\n // If configured remove the modal when hiding it.\n modal.setRemoveOnClose(modalConfig.removeOnClose);\n }\n\n return modal;\n });\n\n if (typeof triggerElement != 'undefined') {\n setUpTrigger(modalPromise, triggerElement, modalConfig);\n }\n\n return modalPromise;\n };\n\n return {\n create: create,\n types: TYPES,\n };\n});\n"],"file":"modal_factory.min.js"} \ No newline at end of file diff --git a/lib/amd/src/modal_factory.js b/lib/amd/src/modal_factory.js index a7d070d6e8d..1e27c2f1d89 100644 --- a/lib/amd/src/modal_factory.js +++ b/lib/amd/src/modal_factory.js @@ -23,17 +23,18 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal', - 'core/modal_save_cancel', 'core/modal_cancel', + 'core/modal_save_cancel', 'core/modal_cancel', 'core/local/modal/alert', 'core/templates', 'core/notification', 'core/custom_interaction_events', 'core/pending'], function($, ModalEvents, ModalRegistry, Modal, ModalSaveCancel, - ModalCancel, Templates, Notification, CustomEvents, Pending) { + ModalCancel, ModalAlert, Templates, Notification, CustomEvents, Pending) { // The templates for each type of modal. var TEMPLATES = { DEFAULT: 'core/modal', SAVE_CANCEL: 'core/modal_save_cancel', CANCEL: 'core/modal_cancel', + ALERT: 'core/local/modal/alert', }; // The available types of modals. @@ -41,12 +42,14 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal', DEFAULT: 'DEFAULT', SAVE_CANCEL: 'SAVE_CANCEL', CANCEL: 'CANCEL', + ALERT: 'ALERT', }; // Register the common set of modals. ModalRegistry.register(TYPES.DEFAULT, Modal, TEMPLATES.DEFAULT); ModalRegistry.register(TYPES.SAVE_CANCEL, ModalSaveCancel, TEMPLATES.SAVE_CANCEL); ModalRegistry.register(TYPES.CANCEL, ModalCancel, TEMPLATES.CANCEL); + ModalRegistry.register(TYPES.ALERT, ModalAlert, TEMPLATES.ALERT); /** * Set up the events required to show the modal and return focus when the modal diff --git a/lib/templates/local/modal/alert.mustache b/lib/templates/local/modal/alert.mustache new file mode 100644 index 00000000000..78ce7cd79cb --- /dev/null +++ b/lib/templates/local/modal/alert.mustache @@ -0,0 +1,45 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core/local/modal/alert + + Moodle modal template with one oaky button. + + The purpose of this template is to render an alert modal with an acceptance option. + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * title A cleaned string (use clean_text()) to display. + * body HTML content for the boday + + Example context (json): + { + "title": "Example cancel modal", + "body": "Some example content for the body" + } +}} + +{{< core/modal }} + {{$footer}} + + {{/footer}} +{{/ core/modal }}