payment/amd/src/modal_gateways.js

  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. * Contain the logic for the gateways modal: A modal with proceed and cancel buttons.
  17. *
  18. * @module core_payment/modal_gateways
  19. * @copyright 2020 Shamim Rezaie <shamim@moodle.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import $ from 'jquery';
  23. import CustomEvents from 'core/custom_interaction_events';
  24. import Modal from 'core/modal';
  25. import ModalEvents from 'core/modal_events';
  26. import PaymentEvents from 'core_payment/events';
  27. const SELECTORS = {
  28. PROCEED_BUTTON: '[data-action="proceed"]',
  29. CANCEL_BUTTON: '[data-action="cancel"]',
  30. };
  31. export default class ModalGateways extends Modal {
  32. static TYPE = 'core_payment-modal_gateways';
  33. static TEMPLATE = 'core_payment/modal_gateways';
  34. /**
  35. * Constructor for the Modal.
  36. *
  37. * @param {object} root The root jQuery element for the modal
  38. */
  39. constructor(root) {
  40. super(root);
  41. }
  42. /**
  43. * Set up all of the event handling for the modal.
  44. *
  45. * @method registerEventListeners
  46. */
  47. registerEventListeners() {
  48. // Apply parent event listeners.
  49. super.registerEventListeners();
  50. this.getModal().on(CustomEvents.events.activate, SELECTORS.PROCEED_BUTTON, (e, data) => {
  51. var proceedEvent = $.Event(PaymentEvents.proceed);
  52. this.getRoot().trigger(proceedEvent, this);
  53. if (!proceedEvent.isDefaultPrevented()) {
  54. this.hide();
  55. data.originalEvent.preventDefault();
  56. }
  57. });
  58. this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, (e, data) => {
  59. var cancelEvent = $.Event(ModalEvents.cancel);
  60. this.getRoot().trigger(cancelEvent, this);
  61. if (!cancelEvent.isDefaultPrevented()) {
  62. this.hide();
  63. data.originalEvent.preventDefault();
  64. }
  65. });
  66. }
  67. }
  68. ModalGateways.registerModalType();