Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
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.
7
//
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.
12
//
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/>.
15
 
16
/**
17
 * Contain the logic for the gateways modal: A modal with proceed and cancel buttons.
18
 *
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
22
 */
23
 
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
 
30
const SELECTORS = {
31
    PROCEED_BUTTON: '[data-action="proceed"]',
32
    CANCEL_BUTTON: '[data-action="cancel"]',
33
};
34
 
35
export default class ModalGateways extends Modal {
36
    static TYPE = 'core_payment-modal_gateways';
37
    static TEMPLATE = 'core_payment/modal_gateways';
38
 
39
    /**
40
     * Constructor for the Modal.
41
     *
42
     * @param {object} root The root jQuery element for the modal
43
     */
44
    constructor(root) {
45
        super(root);
46
    }
47
 
48
    /**
49
     * Set up all of the event handling for the modal.
50
     *
51
     * @method registerEventListeners
52
     */
53
    registerEventListeners() {
54
        // Apply parent event listeners.
55
        super.registerEventListeners();
56
 
57
        this.getModal().on(CustomEvents.events.activate, SELECTORS.PROCEED_BUTTON, (e, data) => {
58
            var proceedEvent = $.Event(PaymentEvents.proceed);
59
            this.getRoot().trigger(proceedEvent, this);
60
 
61
            if (!proceedEvent.isDefaultPrevented()) {
62
                this.hide();
63
                data.originalEvent.preventDefault();
64
            }
65
        });
66
 
67
        this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, (e, data) => {
68
            var cancelEvent = $.Event(ModalEvents.cancel);
69
            this.getRoot().trigger(cancelEvent, this);
70
 
71
            if (!cancelEvent.isDefaultPrevented()) {
72
                this.hide();
73
                data.originalEvent.preventDefault();
74
            }
75
        });
76
    }
77
}
78
 
79
ModalGateways.registerModalType();