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
 * Class that defines the bulk action for general actions in the assignment grading page.
18
 *
19
 * @module     mod_assign/bulkactions/grading/general_action
20
 * @copyright  2024 Shamim Rezaie <shamim@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
import BulkAction from 'core/bulkactions/bulk_action';
25
import Templates from 'core/templates';
26
import SaveCancelModal from 'core/modal_save_cancel';
27
import ModalEvents from 'core/modal_events';
28
 
29
const Selectors = {
30
    selectBulkItemCheckbox: 'input[type="checkbox"][name="selectedusers"]:checked',
31
};
32
 
33
export default class extends BulkAction {
34
 
35
    /** @type {string} The action key. */
36
    actionKey;
37
 
38
    /** @type {number} The course module ID. */
39
    #cmid;
40
 
41
    /** @type {Promise<string>} The action button's icon. */
42
    #buttonIcon;
43
 
44
    /** @type {Promise<string>} The action button's label. */
45
    #buttonLabel;
46
 
47
    /** @type {Promise<string>} Title of the confirmation dialog. */
48
    #confirmationTitle;
49
 
50
    /** @type {Promise<string>} Question of the confirmation dialog. */
51
    #confirmationQuestion;
52
 
53
    /** @type {Promise<string>} Text for the confirmation yes button. */
54
    #confirmationYes;
55
 
56
    /** @type {string} The session key. */
57
    #sesskey;
58
 
59
    /**
60
     * The class constructor.
61
     *
62
     * @param {int} cmid The course module ID.
63
     * @param {string} sesskey The session key.
64
     * @param {string} actionKey The action key.
65
     * @param {Promise<string>} buttonLabel The action button's label.
66
     * @param {Promise<string>} buttonIcon The action button's icon.
67
     * @param {Promise<string>} confirmationTitle Title of the confirmation dialog.
68
     * @param {Promise<string>} confirmationQuestion Question of the confirmation dialog.
69
     * @param {Promise<string>} confirmationYes Text for the confirmation yes button.
70
     */
71
    constructor(cmid, sesskey, actionKey, buttonLabel, buttonIcon, confirmationTitle, confirmationQuestion, confirmationYes) {
72
        super();
73
        this.#cmid = cmid;
74
        this.#sesskey = sesskey;
75
        this.actionKey = actionKey;
76
        this.#buttonLabel = buttonLabel;
77
        this.#buttonIcon = buttonIcon;
78
        this.#confirmationTitle = confirmationTitle;
79
        this.#confirmationQuestion = confirmationQuestion;
80
        this.#confirmationYes = confirmationYes;
81
    }
82
 
83
    getBulkActionTriggerSelector() {
84
        return `[data-type="bulkactions"] [data-action="${this.actionKey}"]`;
85
    }
86
 
87
    async triggerBulkAction() {
88
        const selectedUsers = [...document.querySelectorAll(Selectors.selectBulkItemCheckbox)].map(checkbox => checkbox.value);
89
 
90
        const modal = await SaveCancelModal.create({
91
            title: await this.#confirmationTitle,
92
            buttons: {
93
                save: await this.#confirmationYes,
94
            },
95
            body: Templates.render('mod_assign/bulkactions/grading/bulk_action_modal_body', {
96
                text: await this.#confirmationQuestion,
97
                operation: this.actionKey,
98
                cmid: this.#cmid,
99
                selectedusers: selectedUsers.join(','),
100
                sesskey: this.#sesskey
101
            }),
102
            show: true,
103
            removeOnClose: true,
104
        });
105
 
106
        // Handle save event.
107
        modal.getRoot().on(ModalEvents.save, () => {
108
            modal.getRoot().find('form').submit();
109
        });
110
    }
111
 
112
    async renderBulkActionTrigger(showInDropdown, index) {
113
        return Templates.render('mod_assign/bulkactions/grading/bulk_general_action_trigger', {
114
            action: this.actionKey,
115
            title: await this.#buttonLabel,
116
            icon: await this.#buttonIcon,
117
            showindropdown: showInDropdown,
118
            isfirst: index === 0,
119
        });
120
    }
121
}