From fd187060ad81dfe4b397990901bd3d2330a9afd6 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Thu, 16 Jan 2020 00:22:05 +1100 Subject: [PATCH] MDL-69166 core_payment: ES6-ifying modal_gateways --- payment/amd/build/modal_gateways.min.js | 2 +- payment/amd/build/modal_gateways.min.js.map | 2 +- payment/amd/src/modal_gateways.js | 76 +++++++++------------ 3 files changed, 33 insertions(+), 47 deletions(-) diff --git a/payment/amd/build/modal_gateways.min.js b/payment/amd/build/modal_gateways.min.js index cf50a3a847a..54d199f8694 100644 --- a/payment/amd/build/modal_gateways.min.js +++ b/payment/amd/build/modal_gateways.min.js @@ -1,2 +1,2 @@ -define ("core_payment/modal_gateways",["jquery","core/notification","core/custom_interaction_events","core/modal","core/modal_events","core_payment/events","core/modal_registry"],function(a,b,c,d,f,g,h){var i=!1,j={PROCEED_BUTTON:"[data-action=\"proceed\"]",CANCEL_BUTTON:"[data-action=\"cancel\"]"},k=function(a){d.call(this,a)};k.TYPE="core_payment-modal_gateways";k.prototype=Object.create(d.prototype);k.prototype.constructor=k;k.prototype.registerEventListeners=function(){d.prototype.registerEventListeners.call(this);this.getModal().on(c.events.activate,j.PROCEED_BUTTON,function(b,c){var d=a.Event(g.proceed);this.getRoot().trigger(d,this);if(!d.isDefaultPrevented()){this.hide();c.originalEvent.preventDefault()}}.bind(this));this.getModal().on(c.events.activate,j.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))};if(!i){h.register(k.TYPE,k,"core_payment/modal_gateways");i=!0}return k}); +define ("core_payment/modal_gateways",["exports","jquery","core/custom_interaction_events","core/modal","core/modal_events","core_payment/events","core/modal_registry"],function(a,b,c,d,f,g,h){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=i(b);c=i(c);d=i(d);f=i(f);g=i(g);h=i(h);function i(a){return a&&a.__esModule?a:{default:a}}function j(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){j=function(a){return typeof a}}else{j=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return j(a)}function k(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}function l(a,b){for(var c=0,d;c.\n\n/**\n * Contain the logic for the gateways modal: A modal with proceed and cancel buttons.\n *\n * @module core_payment/modal_gateways\n * @package core_payment\n * @copyright 2020 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine([\n 'jquery',\n 'core/notification',\n 'core/custom_interaction_events',\n 'core/modal',\n 'core/modal_events',\n 'core_payment/events',\n 'core/modal_registry'\n],\nfunction(\n $,\n Notification,\n CustomEvents,\n Modal,\n ModalEvents,\n PaymentEvents,\n ModalRegistry\n) {\n\n var registered = false;\n var SELECTORS = {\n PROCEED_BUTTON: '[data-action=\"proceed\"]',\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 ModalGateways = function(root) {\n Modal.call(this, root);\n };\n\n ModalGateways.TYPE = 'core_payment-modal_gateways';\n ModalGateways.prototype = Object.create(Modal.prototype);\n ModalGateways.prototype.constructor = ModalGateways;\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n ModalGateways.prototype.registerEventListeners = function() {\n // Apply parent event listeners.\n Modal.prototype.registerEventListeners.call(this);\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.PROCEED_BUTTON, function(e, data) {\n var proceedEvent = $.Event(PaymentEvents.proceed);\n this.getRoot().trigger(proceedEvent, this);\n\n if (!proceedEvent.isDefaultPrevented()) {\n this.hide();\n data.originalEvent.preventDefault();\n }\n }.bind(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 // Automatically register with the modal registry the first time this module is imported so that you can create modals\n // of this type using the modal factory.\n if (!registered) {\n ModalRegistry.register(ModalGateways.TYPE, ModalGateways, 'core_payment/modal_gateways');\n registered = true;\n }\n\n return ModalGateways;\n});\n"],"file":"modal_gateways.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/modal_gateways.js"],"names":["registered","SELECTORS","PROCEED_BUTTON","CANCEL_BUTTON","ModalGateways","root","getModal","on","CustomEvents","events","activate","e","data","proceedEvent","$","Event","PaymentEvents","proceed","getRoot","trigger","isDefaultPrevented","hide","originalEvent","preventDefault","cancelEvent","ModalEvents","cancel","Modal","TYPE","ModalRegistry","register"],"mappings":"gRAwBA,OACA,OACA,OACA,OACA,OACA,O,6kDAEIA,CAAAA,CAAU,G,CACRC,CAAS,CAAG,CACdC,cAAc,CAAE,2BADF,CAEdC,aAAa,CAAE,0BAFD,C,CAKGC,C,oBAOjB,WAAYC,CAAZ,CAAkB,wCACRA,CADQ,EAEjB,C,0EAOwB,YAErB,2DAEA,KAAKC,QAAL,GAAgBC,EAAhB,CAAmBC,UAAaC,MAAb,CAAoBC,QAAvC,CAAiDT,CAAS,CAACC,cAA3D,CAA2E,SAACS,CAAD,CAAIC,CAAJ,CAAa,CACpF,GAAIC,CAAAA,CAAY,CAAGC,UAAEC,KAAF,CAAQC,UAAcC,OAAtB,CAAnB,CACA,CAAI,CAACC,OAAL,GAAeC,OAAf,CAAuBN,CAAvB,CAAqC,CAArC,EAEA,GAAI,CAACA,CAAY,CAACO,kBAAb,EAAL,CAAwC,CACpC,CAAI,CAACC,IAAL,GACAT,CAAI,CAACU,aAAL,CAAmBC,cAAnB,EACH,CACJ,CARD,EAUA,KAAKjB,QAAL,GAAgBC,EAAhB,CAAmBC,UAAaC,MAAb,CAAoBC,QAAvC,CAAiDT,CAAS,CAACE,aAA3D,CAA0E,SAACQ,CAAD,CAAIC,CAAJ,CAAa,CACnF,GAAIY,CAAAA,CAAW,CAAGV,UAAEC,KAAF,CAAQU,UAAYC,MAApB,CAAlB,CACA,CAAI,CAACR,OAAL,GAAeC,OAAf,CAAuBK,CAAvB,CAAoC,CAApC,EAEA,GAAI,CAACA,CAAW,CAACJ,kBAAZ,EAAL,CAAuC,CACnC,CAAI,CAACC,IAAL,GACAT,CAAI,CAACU,aAAL,CAAmBC,cAAnB,EACH,CACJ,CARD,CASH,C,cAvCsCI,S,cA0C3CvB,CAAa,CAACwB,IAAd,CAAqB,6BAArB,CAIA,GAAI,CAAC5B,CAAL,CAAiB,CACb6B,UAAcC,QAAd,CAAuB1B,CAAa,CAACwB,IAArC,CAA2CxB,CAA3C,CAA0D,6BAA1D,EACAJ,CAAU,GACb,C","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 * Contain the logic for the gateways modal: A modal with proceed and cancel buttons.\n *\n * @module core_payment/modal_gateways\n * @package core_payment\n * @copyright 2020 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport CustomEvents from 'core/custom_interaction_events';\nimport Modal from 'core/modal';\nimport ModalEvents from 'core/modal_events';\nimport PaymentEvents from 'core_payment/events';\nimport ModalRegistry from 'core/modal_registry';\n\nlet registered = false;\nconst SELECTORS = {\n PROCEED_BUTTON: '[data-action=\"proceed\"]',\n CANCEL_BUTTON: '[data-action=\"cancel\"]',\n};\n\nexport default class ModalGateways extends Modal {\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n constructor(root) {\n super(root);\n }\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n registerEventListeners() {\n // Apply parent event listeners.\n super.registerEventListeners();\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.PROCEED_BUTTON, (e, data) => {\n var proceedEvent = $.Event(PaymentEvents.proceed);\n this.getRoot().trigger(proceedEvent, this);\n\n if (!proceedEvent.isDefaultPrevented()) {\n this.hide();\n data.originalEvent.preventDefault();\n }\n });\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, (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 });\n }\n}\n\nModalGateways.TYPE = 'core_payment-modal_gateways';\n\n// Automatically register with the modal registry the first time this module is imported so that you can create modals\n// of this type using the modal factory.\nif (!registered) {\n ModalRegistry.register(ModalGateways.TYPE, ModalGateways, 'core_payment/modal_gateways');\n registered = true;\n}\n"],"file":"modal_gateways.min.js"} \ No newline at end of file diff --git a/payment/amd/src/modal_gateways.js b/payment/amd/src/modal_gateways.js index d7d666187ec..533a33373a8 100644 --- a/payment/amd/src/modal_gateways.js +++ b/payment/amd/src/modal_gateways.js @@ -22,54 +22,40 @@ * @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', - 'core_payment/events', - 'core/modal_registry' -], -function( - $, - Notification, - CustomEvents, - Modal, - ModalEvents, - PaymentEvents, - ModalRegistry -) { +import $ from 'jquery'; +import CustomEvents from 'core/custom_interaction_events'; +import Modal from 'core/modal'; +import ModalEvents from 'core/modal_events'; +import PaymentEvents from 'core_payment/events'; +import ModalRegistry from 'core/modal_registry'; - var registered = false; - var SELECTORS = { - PROCEED_BUTTON: '[data-action="proceed"]', - CANCEL_BUTTON: '[data-action="cancel"]', - }; +let registered = false; +const SELECTORS = { + PROCEED_BUTTON: '[data-action="proceed"]', + CANCEL_BUTTON: '[data-action="cancel"]', +}; + +export default class ModalGateways extends Modal { /** * Constructor for the Modal. * * @param {object} root The root jQuery element for the modal */ - var ModalGateways = function(root) { - Modal.call(this, root); - }; - - ModalGateways.TYPE = 'core_payment-modal_gateways'; - ModalGateways.prototype = Object.create(Modal.prototype); - ModalGateways.prototype.constructor = ModalGateways; + constructor(root) { + super(root); + } /** * Set up all of the event handling for the modal. * * @method registerEventListeners */ - ModalGateways.prototype.registerEventListeners = function() { + registerEventListeners() { // Apply parent event listeners. - Modal.prototype.registerEventListeners.call(this); + super.registerEventListeners(); - this.getModal().on(CustomEvents.events.activate, SELECTORS.PROCEED_BUTTON, function(e, data) { + this.getModal().on(CustomEvents.events.activate, SELECTORS.PROCEED_BUTTON, (e, data) => { var proceedEvent = $.Event(PaymentEvents.proceed); this.getRoot().trigger(proceedEvent, this); @@ -77,9 +63,9 @@ function( this.hide(); data.originalEvent.preventDefault(); } - }.bind(this)); + }); - this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function(e, data) { + this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, (e, data) => { var cancelEvent = $.Event(ModalEvents.cancel); this.getRoot().trigger(cancelEvent, this); @@ -87,15 +73,15 @@ function( this.hide(); data.originalEvent.preventDefault(); } - }.bind(this)); - }; - - // Automatically register with the modal registry the first time this module is imported so that you can create modals - // of this type using the modal factory. - if (!registered) { - ModalRegistry.register(ModalGateways.TYPE, ModalGateways, 'core_payment/modal_gateways'); - registered = true; + }); } +} - return ModalGateways; -}); +ModalGateways.TYPE = 'core_payment-modal_gateways'; + +// Automatically register with the modal registry the first time this module is imported so that you can create modals +// of this type using the modal factory. +if (!registered) { + ModalRegistry.register(ModalGateways.TYPE, ModalGateways, 'core_payment/modal_gateways'); + registered = true; +}