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 delete modal.
|
|
|
18 |
*
|
|
|
19 |
* @module core_calendar/modal_delete
|
|
|
20 |
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
|
|
|
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 ModalEvents from 'core/modal_events';
|
|
|
28 |
import CalendarEvents from './events';
|
|
|
29 |
|
|
|
30 |
const SELECTORS = {
|
|
|
31 |
DELETE_ONE_BUTTON: '[data-action="deleteone"]',
|
|
|
32 |
DELETE_ALL_BUTTON: '[data-action="deleteall"]',
|
|
|
33 |
CANCEL_BUTTON: '[data-action="cancel"]',
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Constructor for the Modal.
|
|
|
38 |
*
|
|
|
39 |
* @class
|
|
|
40 |
* @param {object} root The root jQuery element for the modal
|
|
|
41 |
*/
|
|
|
42 |
export default class ModalDelete extends Modal {
|
|
|
43 |
static TYPE = 'core_calendar-modal_delete';
|
|
|
44 |
static TEMPLATE = 'calendar/event_delete_modal';
|
|
|
45 |
|
|
|
46 |
constructor(root) {
|
|
|
47 |
super(root);
|
|
|
48 |
this.setRemoveOnClose(true);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Set up all of the event handling for the modal.
|
|
|
53 |
*
|
|
|
54 |
* @method registerEventListeners
|
|
|
55 |
*/
|
|
|
56 |
registerEventListeners() {
|
|
|
57 |
// Apply parent event listeners.
|
|
|
58 |
super.registerEventListeners(this);
|
|
|
59 |
|
|
|
60 |
this.getModal().on(CustomEvents.events.activate, SELECTORS.DELETE_ONE_BUTTON, (e, data) => {
|
|
|
61 |
const saveEvent = $.Event(ModalEvents.save);
|
|
|
62 |
this.getRoot().trigger(saveEvent, this);
|
|
|
63 |
|
|
|
64 |
if (!saveEvent.isDefaultPrevented()) {
|
|
|
65 |
this.hide();
|
|
|
66 |
data.originalEvent.preventDefault();
|
|
|
67 |
}
|
|
|
68 |
});
|
|
|
69 |
|
|
|
70 |
this.getModal().on(CustomEvents.events.activate, SELECTORS.DELETE_ALL_BUTTON, (e, data) => {
|
|
|
71 |
const saveEvent = $.Event(CalendarEvents.deleteAll);
|
|
|
72 |
this.getRoot().trigger(saveEvent, this);
|
|
|
73 |
|
|
|
74 |
if (!saveEvent.isDefaultPrevented()) {
|
|
|
75 |
this.hide();
|
|
|
76 |
data.originalEvent.preventDefault();
|
|
|
77 |
}
|
|
|
78 |
});
|
|
|
79 |
|
|
|
80 |
this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, (e, data) => {
|
|
|
81 |
const cancelEvent = $.Event(ModalEvents.cancel);
|
|
|
82 |
this.getRoot().trigger(cancelEvent, this);
|
|
|
83 |
|
|
|
84 |
if (!cancelEvent.isDefaultPrevented()) {
|
|
|
85 |
this.hide();
|
|
|
86 |
data.originalEvent.preventDefault();
|
|
|
87 |
}
|
|
|
88 |
});
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
ModalDelete.registerModalType();
|