diff --git a/lib/amd/build/modal_confirm.min.js b/lib/amd/build/modal_confirm.min.js index 905b62159ca..68df0319578 100644 --- a/lib/amd/build/modal_confirm.min.js +++ b/lib/amd/build/modal_confirm.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/custom_interaction_events","core/modal","core/modal_events"],function(a,b,c,d,e){var f={YES_BUTTON:'[data-action="yes"]',NO_BUTTON:'[data-action="no"]'},g=function(a){d.call(this,a),this.getFooter().find(f.YES_BUTTON).length||b.exception({message:'No "yes" button found'}),this.getFooter().find(f.NO_BUTTON).length||b.exception({message:'No "no" button found'})};return g.prototype=Object.create(d.prototype),g.prototype.constructor=g,g.prototype.setFooter=function(){b.exception({message:"Can not change the footer of a confirm modal"})},g.prototype.registerEventListeners=function(){d.prototype.registerEventListeners.call(this),this.getModal().on(c.events.activate,f.YES_BUTTON,function(b,c){var d=a.Event(e.yes);this.getRoot().trigger(d,this),d.isDefaultPrevented()||(this.hide(),c.originalEvent.preventDefault())}.bind(this)),this.getModal().on(c.events.activate,f.NO_BUTTON,function(b,c){var d=a.Event(e.no);this.getRoot().trigger(d,this),d.isDefaultPrevented()||(this.hide(),c.originalEvent.preventDefault())}.bind(this))},g}); \ No newline at end of file +define(["jquery","core/custom_interaction_events","core/modal_events","core/modal_save_cancel","core/log"],function(a,b,c,d,e){var f=function(a){e.warn("The CONFIRM modal type has been deprecated and should not be used anymore. Please use the SAVE_CANCEL modal type instead."),d.call(this,a)};return f.prototype=Object.create(d.prototype),f.prototype.constructor=f,f}); \ No newline at end of file diff --git a/lib/amd/build/modal_events.min.js b/lib/amd/build/modal_events.min.js index 9b2eaab754b..5fc8341f154 100644 --- a/lib/amd/build/modal_events.min.js +++ b/lib/amd/build/modal_events.min.js @@ -1 +1 @@ -define([],function(){return{shown:"modal:shown",hidden:"modal:hidden",destroyed:"modal:destroyed",bodyRendered:"modal:bodyRendered",save:"modal-save-cancel:save",cancel:"modal-save-cancel:cancel",yes:"modal-confirm:yes",no:"modal-confirm:no"}}); \ No newline at end of file +define([],function(){return{shown:"modal:shown",hidden:"modal:hidden",destroyed:"modal:destroyed",bodyRendered:"modal:bodyRendered",save:"modal-save-cancel:save",cancel:"modal-save-cancel:cancel",yes:"modal-save-cancel:save",no:"modal-save-cancel:cancel"}}); \ No newline at end of file diff --git a/lib/amd/build/modal_factory.min.js b/lib/amd/build/modal_factory.min.js index 02e0604bfb3..04cb7e12c29 100644 --- a/lib/amd/build/modal_factory.min.js +++ b/lib/amd/build/modal_factory.min.js @@ -1 +1 @@ -define(["jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_confirm","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i,j){var k={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CONFIRM:"core/modal_confirm",CANCEL:"core/modal_cancel"},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CONFIRM:"CONFIRM",CANCEL:"CANCEL"};c.register(l.DEFAULT,d,k.DEFAULT),c.register(l.SAVE_CANCEL,e,k.SAVE_CANCEL),c.register(l.CONFIRM,f,k.CONFIRM),c.register(l.CANCEL,g,k.CANCEL);var m=function(a,c){if("undefined"!=typeof c){if(Array.isArray(c)){var d=c[1];c=c[0],j.define(c,[j.events.activate]),c.on(j.events.activate,d,function(b,c){a.then(function(a){return a.show(),a}),c.originalEvent.preventDefault()})}else j.define(c,[j.events.activate]),c.on(j.events.activate,function(b,c){a.then(function(a){return a.show(),a}),c.originalEvent.preventDefault()});a.then(function(a){return a.getRoot().on(b.hidden,function(){c.focus()}),a})}},n=function(b,c){c=a(c);var d=b.module,e=new d(c);return e},o=function(b,c,d){var e=b.template,f=h.render(e,c).then(function(c){var d=a(c);return n(b,d)}).fail(i.exception);return m(f,d),f},p=function(a,b){var d=a.type||l.DEFAULT,e=!!a.large,f=null,g={};return f=c.get(d),f||i.exception({message:"Unable to find modal of type: "+d}),"undefined"!=typeof a.templateContext&&(g=a.templateContext),o(f,g,b).then(function(b){return"undefined"!=typeof a.title&&b.setTitle(a.title),"undefined"!=typeof a.body&&b.setBody(a.body),"undefined"!=typeof a.footer&&b.setFooter(a.footer),e&&b.setLarge(),b})};return{create:p,types:l}}); \ No newline at end of file +define(["jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_confirm","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i,j){var k={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CONFIRM:"core/modal_save_cancel",CANCEL:"core/modal_cancel"},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CONFIRM:"CONFIRM",CANCEL:"CANCEL"};c.register(l.DEFAULT,d,k.DEFAULT),c.register(l.SAVE_CANCEL,e,k.SAVE_CANCEL),c.register(l.CONFIRM,f,k.CONFIRM),c.register(l.CANCEL,g,k.CANCEL);var m=function(a,c){if("undefined"!=typeof c){if(Array.isArray(c)){var d=c[1];c=c[0],j.define(c,[j.events.activate]),c.on(j.events.activate,d,function(b,c){a.then(function(a){return a.show(),a}),c.originalEvent.preventDefault()})}else j.define(c,[j.events.activate]),c.on(j.events.activate,function(b,c){a.then(function(a){return a.show(),a}),c.originalEvent.preventDefault()});a.then(function(a){return a.getRoot().on(b.hidden,function(){c.focus()}),a})}},n=function(b,c){c=a(c);var d=b.module,e=new d(c);return e},o=function(b,c,d){var e=b.template,f=h.render(e,c).then(function(c){var d=a(c);return n(b,d)}).fail(i.exception);return m(f,d),f},p=function(a,b){var d=a.type||l.DEFAULT,e=!!a.large,f=null,g={};return f=c.get(d),f||i.exception({message:"Unable to find modal of type: "+d}),"undefined"!=typeof a.templateContext&&(g=a.templateContext),o(f,g,b).then(function(b){return"undefined"!=typeof a.title&&b.setTitle(a.title),"undefined"!=typeof a.body&&b.setBody(a.body),"undefined"!=typeof a.footer&&b.setFooter(a.footer),e&&b.setLarge(),b})};return{create:p,types:l}}); \ No newline at end of file diff --git a/lib/amd/src/modal_confirm.js b/lib/amd/src/modal_confirm.js index 171c43357b5..f396c8e18c2 100644 --- a/lib/amd/src/modal_confirm.js +++ b/lib/amd/src/modal_confirm.js @@ -14,21 +14,19 @@ // along with Moodle. If not, see . /** - * Contain the logic for the save/cancel modal. + * Contain the logic for the yes/no confirmation modal. + * This has been deprecated and should not be used anymore. Please use core/modal_save_cancel instead. + * See MDL-59759. * - * @module core/modal_save_cancel - * @class modal_save_cancel + * @deprecated Since Moodle 3.4 + * @module core/modal_confirm + * @class modal_confirm * @package core * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/modal', 'core/modal_events'], - function($, Notification, CustomEvents, Modal, ModalEvents) { - - var SELECTORS = { - YES_BUTTON: '[data-action="yes"]', - NO_BUTTON: '[data-action="no"]', - }; +define(['jquery', 'core/custom_interaction_events', 'core/modal_events', 'core/modal_save_cancel', 'core/log'], + function($, CustomEvents, ModalEvents, ModalSaveCancel, Log) { /** * Constructor for the Modal. @@ -36,57 +34,13 @@ define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/m * @param {object} root The root jQuery element for the modal */ var ModalConfirm = function(root) { - Modal.call(this, root); - - if (!this.getFooter().find(SELECTORS.YES_BUTTON).length) { - Notification.exception({message: 'No "yes" button found'}); - } - - if (!this.getFooter().find(SELECTORS.NO_BUTTON).length) { - Notification.exception({message: 'No "no" button found'}); - } + Log.warn("The CONFIRM modal type has been deprecated and should not be used anymore." + + " Please use the SAVE_CANCEL modal type instead."); + ModalSaveCancel.call(this, root); }; - ModalConfirm.prototype = Object.create(Modal.prototype); + ModalConfirm.prototype = Object.create(ModalSaveCancel.prototype); ModalConfirm.prototype.constructor = ModalConfirm; - /** - * Override parent implementation to prevent changing the footer content. - */ - ModalConfirm.prototype.setFooter = function() { - Notification.exception({message: 'Can not change the footer of a confirm modal'}); - return; - }; - - /** - * Set up all of the event handling for the modal. - * - * @method registerEventListeners - */ - ModalConfirm.prototype.registerEventListeners = function() { - // Apply parent event listeners. - Modal.prototype.registerEventListeners.call(this); - - this.getModal().on(CustomEvents.events.activate, SELECTORS.YES_BUTTON, function(e, data) { - var yesEvent = $.Event(ModalEvents.yes); - this.getRoot().trigger(yesEvent, this); - - if (!yesEvent.isDefaultPrevented()) { - this.hide(); - data.originalEvent.preventDefault(); - } - }.bind(this)); - - this.getModal().on(CustomEvents.events.activate, SELECTORS.NO_BUTTON, function(e, data) { - var noEvent = $.Event(ModalEvents.no); - this.getRoot().trigger(noEvent, this); - - if (!noEvent.isDefaultPrevented()) { - this.hide(); - data.originalEvent.preventDefault(); - } - }.bind(this)); - }; - return ModalConfirm; }); diff --git a/lib/amd/src/modal_events.js b/lib/amd/src/modal_events.js index bbd3979259b..9c261795314 100644 --- a/lib/amd/src/modal_events.js +++ b/lib/amd/src/modal_events.js @@ -32,8 +32,9 @@ define([], function() { // ModalSaveCancel events. save: 'modal-save-cancel:save', cancel: 'modal-save-cancel:cancel', - // ModalConfirm events. - yes: 'modal-confirm:yes', - no: 'modal-confirm:no', + // ModalConfirm events. Deprecated since Moodle 3.4. See MDL-59759. + // Point core/modal_confirm events to save/cancel events of core/modal_save_cancel. + yes: 'modal-save-cancel:save', + no: 'modal-save-cancel:cancel', }; }); diff --git a/lib/amd/src/modal_factory.js b/lib/amd/src/modal_factory.js index f9db208d054..770ecdf9bdd 100644 --- a/lib/amd/src/modal_factory.js +++ b/lib/amd/src/modal_factory.js @@ -32,7 +32,8 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal', var TEMPLATES = { DEFAULT: 'core/modal', SAVE_CANCEL: 'core/modal_save_cancel', - CONFIRM: 'core/modal_confirm', + // Deprecated since Moodle 3.4. Point template to core/modal_save_cancel instead. See MDL-59759. + CONFIRM: 'core/modal_save_cancel', CANCEL: 'core/modal_cancel', }; @@ -40,6 +41,7 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal', var TYPES = { DEFAULT: 'DEFAULT', SAVE_CANCEL: 'SAVE_CANCEL', + // Deprecated since Moodle 3.4. See MDL-59759. CONFIRM: 'CONFIRM', CANCEL: 'CANCEL', }; @@ -47,6 +49,7 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal', // Register the common set of modals. ModalRegistry.register(TYPES.DEFAULT, Modal, TEMPLATES.DEFAULT); ModalRegistry.register(TYPES.SAVE_CANCEL, ModalSaveCancel, TEMPLATES.SAVE_CANCEL); + // Deprecated since Moodle 3.4. See MDL-59759. ModalRegistry.register(TYPES.CONFIRM, ModalConfirm, TEMPLATES.CONFIRM); ModalRegistry.register(TYPES.CANCEL, ModalCancel, TEMPLATES.CANCEL); diff --git a/lib/templates/modal_confirm.mustache b/lib/templates/modal_confirm.mustache deleted file mode 100644 index 549a3c657a9..00000000000 --- a/lib/templates/modal_confirm.mustache +++ /dev/null @@ -1,45 +0,0 @@ -{{! - 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/modal_confirm - - Moodle template for a confirmation modal. - - The purpose of this template is to render a modal. - - Classes required for JS: - * none - - Data attributes required for JS: - * none - - Context variables required for this template: - * body HTML content for the boday - - Example context (json): - { - } -}} - -{{< core/modal }} - {{$title}}{{#str}} confirm {{/str}}{{/title}} - {{$body}}{{#str}} areyousure {{/str}}{{/body}} - {{$footer}} - - - {{/footer}} -{{/ core/modal }} diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 77e180ad5ba..cd4d742fe55 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -42,6 +42,8 @@ information provided here is intended especially for developers. close the suggestions popup immediately after an option has been selected. If not specified, it defaults to true for single-select elements and false for multiple-select elements. * user_can_view_profile() now also checks the moodle/user:viewalldetails capability. +* The core/modal_confirm dialogue has been deprecated. Please use the core/modal_save_cancel dialogue instead. Please ensure you + update to use the ModalEvents.save and ModalEvents.cancel events instead of their yes/no counterparts. === 3.3.1 ===