1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * Contain the logic for the gateways modal: A modal with proceed and cancel buttons.
19 * @module core_payment/modal_gateways
20 * @package core_payment
21 * @copyright 2020 Shamim Rezaie <shamim@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 'core/custom_interaction_events',
31 'core_payment/events',
44 var registered = false;
46 PROCEED_BUTTON: '[data-action="proceed"]',
47 CANCEL_BUTTON: '[data-action="cancel"]',
51 * Constructor for the Modal.
53 * @param {object} root The root jQuery element for the modal
55 var ModalGateways = function(root) {
56 Modal.call(this, root);
59 ModalGateways.TYPE = 'core_payment-modal_gateways';
60 ModalGateways.prototype = Object.create(Modal.prototype);
61 ModalGateways.prototype.constructor = ModalGateways;
64 * Set up all of the event handling for the modal.
66 * @method registerEventListeners
68 ModalGateways.prototype.registerEventListeners = function() {
69 // Apply parent event listeners.
70 Modal.prototype.registerEventListeners.call(this);
72 this.getModal().on(CustomEvents.events.activate, SELECTORS.PROCEED_BUTTON, function(e, data) {
73 var proceedEvent = $.Event(PaymentEvents.proceed);
74 this.getRoot().trigger(proceedEvent, this);
76 if (!proceedEvent.isDefaultPrevented()) {
78 data.originalEvent.preventDefault();
82 this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function(e, data) {
83 var cancelEvent = $.Event(ModalEvents.cancel);
84 this.getRoot().trigger(cancelEvent, this);
86 if (!cancelEvent.isDefaultPrevented()) {
88 data.originalEvent.preventDefault();
93 // Automatically register with the modal registry the first time this module is imported so that you can create modals
94 // of this type using the modal factory.
96 ModalRegistry.register(ModalGateways.TYPE, ModalGateways, 'core_payment/modal_gateways');
100 return ModalGateways;