Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * Javascript module for reseting all templates.
18
 *
19
 * @module      mod_data/resetalltemplates
20
 * @copyright   2022 Ferran Recio <ferran@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
 
28
const selectors = {
29
    resetAllTemplatesAction: '[data-action="resetalltemplates"]',
30
};
31
 
32
/**
33
 * Initialize module
34
 */
35
export const init = () => {
36
    prefetchStrings('mod_data', [
37
        'resetalltemplatesconfirmtitle',
38
        'resetalltemplatesconfirm',
39
    ]);
40
    prefetchStrings('core', [
41
        'reset',
42
    ]);
43
    registerEventListeners();
44
};
45
 
46
/**
47
 * Register events for option in action menu.
48
 */
49
const registerEventListeners = () => {
50
    document.addEventListener('click', (event) => {
51
        const actionLink = event.target.closest(selectors.resetAllTemplatesAction);
52
        if (actionLink) {
53
            event.preventDefault();
54
            resetAllTemplatesConfirm(actionLink);
55
        }
56
    });
57
};
58
 
59
/**
60
 * Show the confirmation modal to reset all the templates.
61
 *
62
 * @param {HTMLElement} actionLink the element that triggers the action.
63
 */
64
const resetAllTemplatesConfirm = async(actionLink) => {
65
    try {
66
        await Notification.saveCancelPromise(
67
            getString('resetalltemplatesconfirmtitle', 'mod_data'),
68
            getString('resetalltemplatesconfirm', 'mod_data'),
69
            getString('reset', 'core'),
70
        );
71
        window.location = actionLink.href;
72
    } catch (error) {
73
        return;
74
    }
75
};