| 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 | 
            * Request actions.
  | 
        
        
            | 
            | 
           18 | 
            *
  | 
        
        
            | 
            | 
           19 | 
            * @module     tool_dataprivacy/data_request_modal
  | 
        
        
            | 
            | 
           20 | 
            * @copyright  2018 Jun Pataleta
  | 
        
        
            | 
            | 
           21 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           22 | 
            */
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           import $ from 'jquery';
  | 
        
        
            | 
            | 
           25 | 
           import * as CustomEvents from 'core/custom_interaction_events';
  | 
        
        
            | 
            | 
           26 | 
           import Modal from 'core/modal';
  | 
        
        
            | 
            | 
           27 | 
           import DataPrivacyEvents from './events';
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           const SELECTORS = {
  | 
        
        
            | 
            | 
           30 | 
               APPROVE_BUTTON: '[data-action="approve"]',
  | 
        
        
            | 
            | 
           31 | 
               DENY_BUTTON: '[data-action="deny"]',
  | 
        
        
            | 
            | 
           32 | 
               COMPLETE_BUTTON: '[data-action="complete"]',
  | 
        
        
            | 
            | 
           33 | 
               APPROVE_REQUEST_SELECT_COURSE: '[data-action="approve-selected-courses"]',
  | 
        
        
            | 
            | 
           34 | 
           };
  | 
        
        
            | 
            | 
           35 | 
              | 
        
        
            | 
            | 
           36 | 
           export default class ModalDataRequest extends Modal {
  | 
        
        
            | 
            | 
           37 | 
               static TYPE = 'tool_dataprivacy-data_request';
  | 
        
        
            | 
            | 
           38 | 
               static TEMPLATE = 'tool_dataprivacy/data_request_modal';
  | 
        
        
            | 
            | 
           39 | 
              | 
        
        
            | 
            | 
           40 | 
               /**
  | 
        
        
            | 
            | 
           41 | 
                * Set up all of the event handling for the modal.
  | 
        
        
            | 
            | 
           42 | 
                */
  | 
        
        
            | 
            | 
           43 | 
               registerEventListeners() {
  | 
        
        
            | 
            | 
           44 | 
                   // Apply parent event listeners.
  | 
        
        
            | 
            | 
           45 | 
                   super.registerEventListeners(this);
  | 
        
        
            | 
            | 
           46 | 
              | 
        
        
            | 
            | 
           47 | 
                   this.getModal().on(CustomEvents.events.activate, SELECTORS.APPROVE_BUTTON, (e, data) => {
  | 
        
        
            | 
            | 
           48 | 
                       const approveEvent = $.Event(DataPrivacyEvents.approve);
  | 
        
        
            | 
            | 
           49 | 
                       this.getRoot().trigger(approveEvent, this);
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
                       if (!approveEvent.isDefaultPrevented()) {
  | 
        
        
            | 
            | 
           52 | 
                           this.hide();
  | 
        
        
            | 
            | 
           53 | 
                           data.originalEvent.preventDefault();
  | 
        
        
            | 
            | 
           54 | 
                       }
  | 
        
        
            | 
            | 
           55 | 
                   });
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
            | 
            | 
           57 | 
                   this.getModal().on(CustomEvents.events.activate, SELECTORS.DENY_BUTTON, (e, data) => {
  | 
        
        
            | 
            | 
           58 | 
                       const denyEvent = $.Event(DataPrivacyEvents.deny);
  | 
        
        
            | 
            | 
           59 | 
                       this.getRoot().trigger(denyEvent, this);
  | 
        
        
            | 
            | 
           60 | 
              | 
        
        
            | 
            | 
           61 | 
                       if (!denyEvent.isDefaultPrevented()) {
  | 
        
        
            | 
            | 
           62 | 
                           this.hide();
  | 
        
        
            | 
            | 
           63 | 
                           data.originalEvent.preventDefault();
  | 
        
        
            | 
            | 
           64 | 
                       }
  | 
        
        
            | 
            | 
           65 | 
                   });
  | 
        
        
            | 
            | 
           66 | 
              | 
        
        
            | 
            | 
           67 | 
                   this.getModal().on(CustomEvents.events.activate, SELECTORS.COMPLETE_BUTTON, (e, data) => {
  | 
        
        
            | 
            | 
           68 | 
                       const completeEvent = $.Event(DataPrivacyEvents.complete);
  | 
        
        
            | 
            | 
           69 | 
                       this.getRoot().trigger(completeEvent, this);
  | 
        
        
            | 
            | 
           70 | 
              | 
        
        
            | 
            | 
           71 | 
                       if (!completeEvent.isDefaultPrevented()) {
  | 
        
        
            | 
            | 
           72 | 
                           this.hide();
  | 
        
        
            | 
            | 
           73 | 
                           data.originalEvent.preventDefault();
  | 
        
        
            | 
            | 
           74 | 
                       }
  | 
        
        
            | 
            | 
           75 | 
                   });
  | 
        
        
            | 
            | 
           76 | 
              | 
        
        
            | 
            | 
           77 | 
                   this.getModal().on(CustomEvents.events.activate, SELECTORS.APPROVE_REQUEST_SELECT_COURSE, (e, data) => {
  | 
        
        
            | 
            | 
           78 | 
                       let approveSelectCoursesEvent = $.Event(DataPrivacyEvents.approveSelectCourses);
  | 
        
        
            | 
            | 
           79 | 
                       this.getRoot().trigger(approveSelectCoursesEvent, this);
  | 
        
        
            | 
            | 
           80 | 
              | 
        
        
            | 
            | 
           81 | 
                       if (!approveSelectCoursesEvent.isDefaultPrevented()) {
  | 
        
        
            | 
            | 
           82 | 
                           this.hide();
  | 
        
        
            | 
            | 
           83 | 
                           data.originalEvent.preventDefault();
  | 
        
        
            | 
            | 
           84 | 
                       }
  | 
        
        
            | 
            | 
           85 | 
                   });
  | 
        
        
            | 
            | 
           86 | 
              | 
        
        
            | 
            | 
           87 | 
               }
  | 
        
        
            | 
            | 
           88 | 
           }
  | 
        
        
            | 
            | 
           89 | 
              | 
        
        
            | 
            | 
           90 | 
           ModalDataRequest.registerModalType();
  |