Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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 manager for the override delete modal.
18
 *
19
 * @module     mod_assign/override_modal_manager
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 {get_string as getString} from 'core/str';
25
import OverrideDeleteModal from 'mod_assign/override_delete_modal';
26
 
27
const SELECTORS = {
28
    DELETE_BUTTONS: '.delete-override',
29
    PARENT_CONTAINER: '#assignoverrides',
30
    USER_GROUP_NAME: '.usergroupname',
31
};
32
 
33
/**
34
 * Initialise the modal manager.
35
 *
36
 * @param {string} mode The override mode.
37
 * @param {boolean} showRecalculationCheckBox Whether to show the recalculation checkbox.
38
 */
39
export const init = (mode, showRecalculationCheckBox) => {
40
    document.querySelector(SELECTORS.PARENT_CONTAINER).addEventListener('click', async(event) => {
41
        const button = event.target.closest(SELECTORS.DELETE_BUTTONS);
42
 
43
        if (!button) {
44
            return;
45
        }
46
 
47
        event.preventDefault();
48
 
49
        // Get the name of the user or group from the first column of the row.
50
        const name = event.target.closest('tr').querySelector(SELECTORS.USER_GROUP_NAME).innerText;
51
 
52
        // Get the confirm message for the modal.
53
        const confirmMessage = await getConfirmMessage(mode, name);
54
 
55
        // Create and show the modal.
56
        OverrideDeleteModal.create({
57
            templateContext: {
58
                confirmmessage: confirmMessage,
59
                showpenaltyrecalculation: showRecalculationCheckBox,
60
            },
61
            overrideId: button.getAttribute('data-overrideid'),
62
            sessionKey: button.getAttribute('data-sesskey'),
63
        });
64
    });
65
};
66
 
67
/**
68
 * Get the confirm message for the modal.
69
 *
70
 * @param {string} mode The override mode.
71
 * @param {boolean} name The name of the user or group.
72
 * @returns {Promise<string>} The confirm message.
73
 */
74
const getConfirmMessage = (mode, name) => {
75
    switch (mode) {
76
        case "group":
77
            return getString('overridedeletegroupsure', 'assign', name);
78
        case "user":
79
            return getString('overridedeleteusersure', 'assign', name);
80
        default:
81
            return "";
82
    }
83
};