| 1441 |
ariadna |
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 |
* Modal for deleting an override with the option to recalculate penalties.
|
|
|
18 |
*
|
|
|
19 |
* @module `mod_assign/override_delete_modal
|
|
|
20 |
* @copyright 2025 Catalyst IT Australia Pty Ltd
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import * as CustomEvents from 'core/custom_interaction_events';
|
|
|
25 |
import Config from 'core/config';
|
|
|
26 |
import Modal from 'core/modal';
|
|
|
27 |
|
|
|
28 |
const SELECTORS = {
|
|
|
29 |
DELETE_BUTTONS: '.delete-override',
|
|
|
30 |
RECACULATION_CHECKBOX: '#recalculatepenalties',
|
|
|
31 |
};
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Custom Modal
|
|
|
35 |
*/
|
|
|
36 |
export default class OverrideDeleteModal extends Modal {
|
|
|
37 |
static TYPE = "mod_assign/override_delete_modal";
|
|
|
38 |
static TEMPLATE = "mod_assign/override_delete_modal";
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Configure the modal.
|
|
|
42 |
*
|
|
|
43 |
* @param {Object} modalConfig
|
|
|
44 |
*/
|
|
|
45 |
configure(modalConfig) {
|
|
|
46 |
// Add question modals are always large.
|
|
|
47 |
modalConfig.large = true;
|
|
|
48 |
|
|
|
49 |
// Always show on creation.
|
|
|
50 |
modalConfig.show = true;
|
|
|
51 |
modalConfig.removeOnClose = true;
|
|
|
52 |
|
|
|
53 |
// Apply standard configuration.
|
|
|
54 |
super.configure(modalConfig);
|
|
|
55 |
|
|
|
56 |
this.setOverrideId(modalConfig.overrideId);
|
|
|
57 |
this.setSessionKey(modalConfig.sessionKey);
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Constructor.
|
|
|
62 |
* Set required data to null.
|
|
|
63 |
*
|
|
|
64 |
* @param {HTMLElement} root
|
|
|
65 |
*/
|
|
|
66 |
constructor(root) {
|
|
|
67 |
super(root);
|
|
|
68 |
|
|
|
69 |
// Recalculate penalties checkbox.
|
|
|
70 |
this.recalculationCheckbox = this.getModal().find(SELECTORS.RECACULATION_CHECKBOX);
|
|
|
71 |
|
|
|
72 |
// Data.
|
|
|
73 |
this.setOverrideId(null);
|
|
|
74 |
this.setSessionKey(null);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Set the override id.
|
|
|
79 |
*
|
|
|
80 |
* @param {number} id The override id.
|
|
|
81 |
*/
|
|
|
82 |
setOverrideId(id) {
|
|
|
83 |
this.overrideId = id;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* Get the override id.
|
|
|
88 |
*
|
|
|
89 |
* @returns {*}
|
|
|
90 |
*/
|
|
|
91 |
getOverrideId() {
|
|
|
92 |
return this.overrideId;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Set the session key.
|
|
|
97 |
*
|
|
|
98 |
* @param {string} key
|
|
|
99 |
*/
|
|
|
100 |
setSessionKey(key) {
|
|
|
101 |
this.sessionKey = key;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Get the session key.
|
|
|
106 |
*
|
|
|
107 |
* @returns {*}
|
|
|
108 |
*/
|
|
|
109 |
getSessionKey() {
|
|
|
110 |
return this.sessionKey;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* Register events.
|
|
|
115 |
*
|
|
|
116 |
*/
|
|
|
117 |
registerEventListeners() {
|
|
|
118 |
// Apply parent event listeners.
|
|
|
119 |
super.registerEventListeners(this);
|
|
|
120 |
|
|
|
121 |
// Register to close on cancel.
|
|
|
122 |
this.registerCloseOnCancel();
|
|
|
123 |
|
|
|
124 |
// Register the delete action.
|
|
|
125 |
this.getModal().on(CustomEvents.events.activate, this.getActionSelector('delete'), () => {
|
|
|
126 |
this.deleteOverride();
|
|
|
127 |
});
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
* Delete a override.
|
|
|
132 |
*
|
|
|
133 |
*/
|
|
|
134 |
deleteOverride() {
|
|
|
135 |
// Check if the recalculation checkbox is checked.
|
|
|
136 |
const recalculate = this.recalculationCheckbox.prop('checked');
|
|
|
137 |
|
|
|
138 |
// Redirect to the delete URL.
|
|
|
139 |
const targetUrl = new URL(`${Config.wwwroot}/mod/assign/overridedelete.php`);
|
|
|
140 |
targetUrl.searchParams.append('id', this.getOverrideId());
|
|
|
141 |
targetUrl.searchParams.append('sesskey', this.getSessionKey());
|
|
|
142 |
targetUrl.searchParams.append('confirm', 1);
|
|
|
143 |
|
|
|
144 |
if (recalculate) {
|
|
|
145 |
targetUrl.searchParams.append('recalculate', 1);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
window.location.href = targetUrl.href;
|
|
|
149 |
}
|
|
|
150 |
}
|