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 |
* Javascript module for resetting a course
|
|
|
18 |
*
|
|
|
19 |
* @module core_course/resetcourse
|
|
|
20 |
* @copyright 2024 Sara Arjona <sara@moodle.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import Notification from 'core/notification';
|
|
|
25 |
import {prefetchStrings} from 'core/prefetch';
|
|
|
26 |
import {getString} from 'core/str';
|
|
|
27 |
import * as FormChangeChecker from 'core_form/changechecker';
|
|
|
28 |
|
|
|
29 |
const selectors = {
|
|
|
30 |
resetCoursetButton: '[data-action="resetcourse"]',
|
|
|
31 |
};
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Initialize module
|
|
|
35 |
*/
|
|
|
36 |
export const init = () => {
|
|
|
37 |
prefetchStrings('core', [
|
|
|
38 |
'resetcourseconfirm',
|
|
|
39 |
'resetcoursewarning',
|
|
|
40 |
'resetcourse',
|
|
|
41 |
]);
|
|
|
42 |
|
|
|
43 |
registerEventListeners();
|
|
|
44 |
};
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Register events for course reset button.
|
|
|
48 |
*/
|
|
|
49 |
const registerEventListeners = () => {
|
|
|
50 |
document.addEventListener('click', (event) => {
|
|
|
51 |
const resetButton = event.target.closest(selectors.resetCoursetButton);
|
|
|
52 |
if (resetButton) {
|
|
|
53 |
event.preventDefault();
|
|
|
54 |
resetCourseConfirm(resetButton);
|
|
|
55 |
}
|
|
|
56 |
});
|
|
|
57 |
};
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Show the confirmation modal to reset the course.
|
|
|
61 |
*
|
|
|
62 |
* @param {HTMLElement} resetButton the element to delete.
|
|
|
63 |
*
|
|
|
64 |
*/
|
|
|
65 |
const resetCourseConfirm = async(resetButton) => {
|
|
|
66 |
const courseName = resetButton.dataset.coursename;
|
|
|
67 |
|
|
|
68 |
Notification.deleteCancelPromise(
|
|
|
69 |
getString('resetcourseconfirm'),
|
|
|
70 |
getString('resetcoursewarning', 'core', courseName),
|
|
|
71 |
getString('resetcourse'),
|
|
|
72 |
).then(() => {
|
|
|
73 |
FormChangeChecker.markFormSubmitted(resetButton.closest('form'));
|
|
|
74 |
resetButton.closest('form').submit();
|
|
|
75 |
return;
|
|
|
76 |
}).catch(() => {
|
|
|
77 |
return;
|
|
|
78 |
});
|
|
|
79 |
};
|