mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-68409 js: Convert cancel modals to ES6
This commit is contained in:
parent
9050f3f17e
commit
67774a9567
6 changed files with 45 additions and 105 deletions
2
lib/amd/build/modal_cancel.min.js
vendored
2
lib/amd/build/modal_cancel.min.js
vendored
|
@ -1,2 +1,2 @@
|
|||
define ("core/modal_cancel",["jquery","core/notification","core/custom_interaction_events","core/modal","core/modal_events"],function(a,b,c,d,f){var g={CANCEL_BUTTON:"[data-action=\"cancel\"]"},h=function(a){d.call(this,a);if(!this.getFooter().find(g.CANCEL_BUTTON).length){b.exception({message:"No cancel button found"})}};h.prototype=Object.create(d.prototype);h.prototype.constructor=h;h.prototype.setFooter=function(){b.exception({message:"Can not change the footer of a cancel modal"})};h.prototype.registerEventListeners=function(){d.prototype.registerEventListeners.call(this);this.getModal().on(c.events.activate,g.CANCEL_BUTTON,function(b,c){var d=a.Event(f.cancel);this.getRoot().trigger(d,this);if(!d.isDefaultPrevented()){this.hide();c.originalEvent.preventDefault()}}.bind(this))};return h});
|
||||
define ("core/modal_cancel",["exports","core/modal"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);function c(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){c=function(a){return typeof a}}else{c=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return c(a)}function d(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}function e(a,b){for(var c=0,d;c<b.length;c++){d=b[c];d.enumerable=d.enumerable||!1;d.configurable=!0;if("value"in d)d.writable=!0;Object.defineProperty(a,d.key,d)}}function f(a,b,c){if(b)e(a.prototype,b);if(c)e(a,c);return a}function g(a,b){if(b&&("object"===c(b)||"function"==typeof b)){return b}return h(a)}function h(a){if(void 0===a){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return a}function i(a,b,c){if("undefined"!=typeof Reflect&&Reflect.get){i=Reflect.get}else{i=function(a,b,c){var d=j(a,b);if(!d)return;var e=Object.getOwnPropertyDescriptor(d,b);if(e.get){return e.get.call(c)}return e.value}}return i(a,b,c||a)}function j(a,b){while(!Object.prototype.hasOwnProperty.call(a,b)){a=k(a);if(null===a)break}return a}function k(a){k=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)};return k(a)}function l(a,b){if("function"!=typeof b&&null!==b){throw new TypeError("Super expression must either be null or a function")}a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}});if(b)m(a,b)}function m(a,b){m=Object.setPrototypeOf||function(a,b){a.__proto__=b;return a};return m(a,b)}var n=function(a){l(b,a);function b(a){var c;d(this,b);c=g(this,k(b).call(this,a));if(!c.getFooter().find(c.getActionSelector("cancel")).length){Notification.exception({message:"No cancel button found"})}return c}f(b,[{key:"registerEventListeners",value:function registerEventListeners(){i(k(b.prototype),"registerEventListeners",this).call(this);this.registerCloseOnCancel()}}]);return b}(b.default);a.default=n;return a.default});
|
||||
//# sourceMappingURL=modal_cancel.min.js.map
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../src/modal_cancel.js"],"names":["define","$","Notification","CustomEvents","Modal","ModalEvents","SELECTORS","CANCEL_BUTTON","ModalCancel","root","call","getFooter","find","length","exception","message","prototype","Object","create","constructor","setFooter","registerEventListeners","getModal","on","events","activate","e","data","cancelEvent","Event","cancel","getRoot","trigger","isDefaultPrevented","hide","originalEvent","preventDefault","bind"],"mappings":"AAwBAA,OAAM,qBAAC,CAAC,QAAD,CAAW,mBAAX,CAAgC,gCAAhC,CAAkE,YAAlE,CAAgF,mBAAhF,CAAD,CACE,SAASC,CAAT,CAAYC,CAAZ,CAA0BC,CAA1B,CAAwCC,CAAxC,CAA+CC,CAA/C,CAA4D,IAE5DC,CAAAA,CAAS,CAAG,CACZC,aAAa,CAAE,0BADH,CAFgD,CAW5DC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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 <http://www.gnu.org/licenses/>.\n\n/**\n * Contain the logic for the cancel modal.\n *\n * @module core/modal_cancel\n * @class modal_cancel\n * @package core\n * @copyright 2016 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/modal', 'core/modal_events'],\n function($, Notification, CustomEvents, Modal, ModalEvents) {\n\n var SELECTORS = {\n CANCEL_BUTTON: '[data-action=\"cancel\"]',\n };\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n var ModalCancel = function(root) {\n Modal.call(this, root);\n\n if (!this.getFooter().find(SELECTORS.CANCEL_BUTTON).length) {\n Notification.exception({message: 'No cancel button found'});\n }\n };\n\n ModalCancel.prototype = Object.create(Modal.prototype);\n ModalCancel.prototype.constructor = ModalCancel;\n\n /**\n * Override parent implementation to prevent changing the footer content.\n */\n ModalCancel.prototype.setFooter = function() {\n Notification.exception({message: 'Can not change the footer of a cancel modal'});\n return;\n };\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n ModalCancel.prototype.registerEventListeners = function() {\n // Apply parent event listeners.\n Modal.prototype.registerEventListeners.call(this);\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function(e, data) {\n var cancelEvent = $.Event(ModalEvents.cancel);\n this.getRoot().trigger(cancelEvent, this);\n\n if (!cancelEvent.isDefaultPrevented()) {\n this.hide();\n data.originalEvent.preventDefault();\n }\n }.bind(this));\n };\n\n return ModalCancel;\n});\n"],"file":"modal_cancel.min.js"}
|
||||
{"version":3,"sources":["../src/modal_cancel.js"],"names":["root","getFooter","find","getActionSelector","length","Notification","exception","message","registerCloseOnCancel","Modal"],"mappings":"kJAwBA,uD,gjDAGI,WAAYA,CAAZ,CAAkB,iBACd,wBAAMA,CAAN,GAEA,GAAI,CAAC,EAAKC,SAAL,GAAiBC,IAAjB,CAAsB,EAAKC,iBAAL,CAAuB,QAAvB,CAAtB,EAAwDC,MAA7D,CAAqE,CACjEC,YAAY,CAACC,SAAb,CAAuB,CAACC,OAAO,CAAE,wBAAV,CAAvB,CACH,CALa,QAMjB,C,0EAKwB,CAErB,2DAGA,KAAKC,qBAAL,EACH,C,cAlBwBC,S","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 <http://www.gnu.org/licenses/>.\n\n/**\n * Contain the logic for the cancel modal.\n *\n * @module core/modal_cancel\n * @class modal_cancel\n * @package core\n * @copyright 2016 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport Modal from 'core/modal';\n\nexport default class extends Modal {\n constructor(root) {\n super(root);\n\n if (!this.getFooter().find(this.getActionSelector('cancel')).length) {\n Notification.exception({message: 'No cancel button found'});\n }\n }\n\n /**\n * Register all event listeners.\n */\n registerEventListeners() {\n // Call the parent registration.\n super.registerEventListeners();\n\n // Register to close on cancel.\n this.registerCloseOnCancel();\n }\n}\n"],"file":"modal_cancel.min.js"}
|
2
lib/amd/build/modal_save_cancel.min.js
vendored
2
lib/amd/build/modal_save_cancel.min.js
vendored
|
@ -1,2 +1,2 @@
|
|||
define ("core/modal_save_cancel",["jquery","core/notification","core/custom_interaction_events","core/modal","core/modal_events"],function(a,b,c,d,f){var g={SAVE_BUTTON:"[data-action=\"save\"]",CANCEL_BUTTON:"[data-action=\"cancel\"]"},h=function(a){d.call(this,a);if(!this.getFooter().find(g.SAVE_BUTTON).length){b.exception({message:"No save button found"})}if(!this.getFooter().find(g.CANCEL_BUTTON).length){b.exception({message:"No cancel button found"})}};h.prototype=Object.create(d.prototype);h.prototype.constructor=h;h.prototype.setFooter=function(){b.exception({message:"Can not change the footer of a save cancel modal"})};h.prototype.registerEventListeners=function(){d.prototype.registerEventListeners.call(this);this.getModal().on(c.events.activate,g.SAVE_BUTTON,function(b,c){var d=a.Event(f.save);this.getRoot().trigger(d,this);if(!d.isDefaultPrevented()){this.hide();c.originalEvent.preventDefault()}}.bind(this));this.registerCloseOnCancel()};h.prototype.setSaveButtonText=function(a){var b=this.getFooter().find(g.SAVE_BUTTON);this.asyncSet(a,b.text.bind(b))};return h});
|
||||
define ("core/modal_save_cancel",["exports","core/modal"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);function c(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){c=function(a){return typeof a}}else{c=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return c(a)}function d(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}function e(a,b){for(var c=0,d;c<b.length;c++){d=b[c];d.enumerable=d.enumerable||!1;d.configurable=!0;if("value"in d)d.writable=!0;Object.defineProperty(a,d.key,d)}}function f(a,b,c){if(b)e(a.prototype,b);if(c)e(a,c);return a}function g(a,b){if(b&&("object"===c(b)||"function"==typeof b)){return b}return h(a)}function h(a){if(void 0===a){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return a}function i(a,b,c){if("undefined"!=typeof Reflect&&Reflect.get){i=Reflect.get}else{i=function(a,b,c){var d=j(a,b);if(!d)return;var e=Object.getOwnPropertyDescriptor(d,b);if(e.get){return e.get.call(c)}return e.value}}return i(a,b,c||a)}function j(a,b){while(!Object.prototype.hasOwnProperty.call(a,b)){a=k(a);if(null===a)break}return a}function k(a){k=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)};return k(a)}function l(a,b){if("function"!=typeof b&&null!==b){throw new TypeError("Super expression must either be null or a function")}a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}});if(b)m(a,b)}function m(a,b){m=Object.setPrototypeOf||function(a,b){a.__proto__=b;return a};return m(a,b)}var n=function(a){l(b,a);function b(a){var c;d(this,b);c=g(this,k(b).call(this,a));if(!c.getFooter().find(c.getActionSelector("save")).length){Notification.exception({message:"No save button found"})}if(!c.getFooter().find(c.getActionSelector("cancel")).length){Notification.exception({message:"No cancel button found"})}return c}f(b,[{key:"registerEventListeners",value:function registerEventListeners(){i(k(b.prototype),"registerEventListeners",this).call(this);this.registerCloseOnSave();this.registerCloseOnCancel()}},{key:"setFooter",value:function setFooter(){Notification.exception({message:"Can not change the footer of a save cancel modal"})}},{key:"setSaveButtonText",value:function setSaveButtonText(a){return this.setButtonText("save",a)}}]);return b}(b.default);a.default=n;return a.default});
|
||||
//# sourceMappingURL=modal_save_cancel.min.js.map
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -22,56 +22,25 @@
|
|||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @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) {
|
||||
import Modal from 'core/modal';
|
||||
|
||||
var SELECTORS = {
|
||||
CANCEL_BUTTON: '[data-action="cancel"]',
|
||||
};
|
||||
export default class extends Modal {
|
||||
constructor(root) {
|
||||
super(root);
|
||||
|
||||
/**
|
||||
* Constructor for the Modal.
|
||||
*
|
||||
* @param {object} root The root jQuery element for the modal
|
||||
*/
|
||||
var ModalCancel = function(root) {
|
||||
Modal.call(this, root);
|
||||
|
||||
if (!this.getFooter().find(SELECTORS.CANCEL_BUTTON).length) {
|
||||
if (!this.getFooter().find(this.getActionSelector('cancel')).length) {
|
||||
Notification.exception({message: 'No cancel button found'});
|
||||
}
|
||||
};
|
||||
|
||||
ModalCancel.prototype = Object.create(Modal.prototype);
|
||||
ModalCancel.prototype.constructor = ModalCancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent implementation to prevent changing the footer content.
|
||||
* Register all event listeners.
|
||||
*/
|
||||
ModalCancel.prototype.setFooter = function() {
|
||||
Notification.exception({message: 'Can not change the footer of a cancel modal'});
|
||||
return;
|
||||
};
|
||||
registerEventListeners() {
|
||||
// Call the parent registration.
|
||||
super.registerEventListeners();
|
||||
|
||||
/**
|
||||
* Set up all of the event handling for the modal.
|
||||
*
|
||||
* @method registerEventListeners
|
||||
*/
|
||||
ModalCancel.prototype.registerEventListeners = function() {
|
||||
// Apply parent event listeners.
|
||||
Modal.prototype.registerEventListeners.call(this);
|
||||
|
||||
this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function(e, data) {
|
||||
var cancelEvent = $.Event(ModalEvents.cancel);
|
||||
this.getRoot().trigger(cancelEvent, this);
|
||||
|
||||
if (!cancelEvent.isDefaultPrevented()) {
|
||||
this.hide();
|
||||
data.originalEvent.preventDefault();
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
return ModalCancel;
|
||||
});
|
||||
// Register to close on cancel.
|
||||
this.registerCloseOnCancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,77 +22,48 @@
|
|||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @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) {
|
||||
import Modal from 'core/modal';
|
||||
|
||||
var SELECTORS = {
|
||||
SAVE_BUTTON: '[data-action="save"]',
|
||||
CANCEL_BUTTON: '[data-action="cancel"]',
|
||||
};
|
||||
export default class extends Modal {
|
||||
constructor(root) {
|
||||
super(root);
|
||||
|
||||
/**
|
||||
* Constructor for the Modal.
|
||||
*
|
||||
* @param {object} root The root jQuery element for the modal
|
||||
*/
|
||||
var ModalSaveCancel = function(root) {
|
||||
Modal.call(this, root);
|
||||
|
||||
if (!this.getFooter().find(SELECTORS.SAVE_BUTTON).length) {
|
||||
if (!this.getFooter().find(this.getActionSelector('save')).length) {
|
||||
Notification.exception({message: 'No save button found'});
|
||||
}
|
||||
|
||||
if (!this.getFooter().find(SELECTORS.CANCEL_BUTTON).length) {
|
||||
if (!this.getFooter().find(this.getActionSelector('cancel')).length) {
|
||||
Notification.exception({message: 'No cancel button found'});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ModalSaveCancel.prototype = Object.create(Modal.prototype);
|
||||
ModalSaveCancel.prototype.constructor = ModalSaveCancel;
|
||||
/**
|
||||
* Register all event listeners.
|
||||
*/
|
||||
registerEventListeners() {
|
||||
// Call the parent registration.
|
||||
super.registerEventListeners();
|
||||
|
||||
// Register to close on save/cancel.
|
||||
this.registerCloseOnSave();
|
||||
this.registerCloseOnCancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent implementation to prevent changing the footer content.
|
||||
*/
|
||||
ModalSaveCancel.prototype.setFooter = function() {
|
||||
setFooter() {
|
||||
Notification.exception({message: 'Can not change the footer of a save cancel modal'});
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up all of the event handling for the modal.
|
||||
* Set the title of the save button.
|
||||
*
|
||||
* @method registerEventListeners
|
||||
* @param {String|Promise} value The button text, or a Promise which will resolve it
|
||||
* @returns{Promise}
|
||||
*/
|
||||
ModalSaveCancel.prototype.registerEventListeners = function() {
|
||||
// Apply parent event listeners.
|
||||
Modal.prototype.registerEventListeners.call(this);
|
||||
|
||||
this.getModal().on(CustomEvents.events.activate, SELECTORS.SAVE_BUTTON, function(e, data) {
|
||||
var saveEvent = $.Event(ModalEvents.save);
|
||||
this.getRoot().trigger(saveEvent, this);
|
||||
|
||||
if (!saveEvent.isDefaultPrevented()) {
|
||||
this.hide();
|
||||
data.originalEvent.preventDefault();
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
this.registerCloseOnCancel();
|
||||
};
|
||||
|
||||
/**
|
||||
* Allows to overwrite the text of "Save changes" button.
|
||||
*
|
||||
* This method is overloaded to take either a string value for the button title or a jQuery promise that is resolved with
|
||||
* text most commonly from a Str.get_string call.
|
||||
*
|
||||
* @param {(String|object)} value The button text, or a jQuery promise which will resolve it
|
||||
*/
|
||||
ModalSaveCancel.prototype.setSaveButtonText = function(value) {
|
||||
var button = this.getFooter().find(SELECTORS.SAVE_BUTTON);
|
||||
|
||||
this.asyncSet(value, button.text.bind(button));
|
||||
};
|
||||
|
||||
return ModalSaveCancel;
|
||||
});
|
||||
setSaveButtonText(value) {
|
||||
return this.setButtonText('save', value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue