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 * @copyright 2020 Shamim Rezaie <shamim@moodle.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 import $ from 'jquery';
25 import CustomEvents from 'core/custom_interaction_events';
26 import Modal from 'core/modal';
27 import ModalEvents from 'core/modal_events';
28 import PaymentEvents from 'core_payment/events';
29 import ModalRegistry from 'core/modal_registry';
31 let registered = false;
33 PROCEED_BUTTON: '[data-action="proceed"]',
34 CANCEL_BUTTON: '[data-action="cancel"]',
37 export default class ModalGateways extends Modal {
40 * Constructor for the Modal.
42 * @param {object} root The root jQuery element for the modal
49 * Set up all of the event handling for the modal.
51 * @method registerEventListeners
53 registerEventListeners() {
54 // Apply parent event listeners.
55 super.registerEventListeners();
57 this.getModal().on(CustomEvents.events.activate, SELECTORS.PROCEED_BUTTON, (e, data) => {
58 var proceedEvent = $.Event(PaymentEvents.proceed);
59 this.getRoot().trigger(proceedEvent, this);
61 if (!proceedEvent.isDefaultPrevented()) {
63 data.originalEvent.preventDefault();
67 this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, (e, data) => {
68 var cancelEvent = $.Event(ModalEvents.cancel);
69 this.getRoot().trigger(cancelEvent, this);
71 if (!cancelEvent.isDefaultPrevented()) {
73 data.originalEvent.preventDefault();
79 ModalGateways.TYPE = 'core_payment-modal_gateways';
81 // Automatically register with the modal registry the first time this module is imported so that you can create modals
82 // of this type using the modal factory.
84 ModalRegistry.register(ModalGateways.TYPE, ModalGateways, 'core_payment/modal_gateways');