MDL-59759 core_amd: Deprecate core/modal_confirm

This commit is contained in:
Jun Pataleta
2017-09-04 10:44:46 +08:00
parent b3cfb01316
commit 237efd4f0d
8 changed files with 25 additions and 110 deletions
+1 -1
View File
@@ -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});
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});
+1 -1
View File
@@ -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"}});
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"}});
+1 -1
View File
@@ -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}});
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}});
+12 -58
View File
@@ -14,21 +14,19 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 <[email protected]>
* @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;
});
+4 -3
View File
@@ -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',
};
});
+4 -1
View File
@@ -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);
-45
View File
@@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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}}
<button type="button" class="btn btn-primary" data-action="yes">{{#str}} yes {{/str}}</button>
<button type="button" class="btn btn-secondary" data-action="no">{{#str}} no {{/str}}</button>
{{/footer}}
{{/ core/modal }}
+2
View File
@@ -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 ===