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 to extend the assignment deadline in the assignment grading page.
18
 *
19
 * @module     mod_assign/bulkactions/grading/extend
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 {getString} from 'core/str';
27
import SaveCancelModal from 'core/modal_save_cancel';
28
import ModalEvents from 'core/modal_events';
29
 
30
const Selectors = {
31
    selectBulkItemCheckbox: 'input[type="checkbox"][name="selectedusers"]:checked',
32
};
33
 
34
export default class extends BulkAction {
35
    /** @type {number} The course module ID. */
36
    #cmid;
37
 
38
    /** @type {string} The session key. */
39
    #sesskey;
40
 
41
    /**
42
     * The class constructor.
43
     *
44
     * @param {number} cmid The course module ID.
45
     * @param {string} sesskey The session key.
46
     */
47
    constructor(cmid, sesskey) {
48
        super();
49
        this.#cmid = cmid;
50
        this.#sesskey = sesskey;
51
    }
52
 
53
    getBulkActionTriggerSelector() {
54
        return '[data-type="bulkactions"] [data-action="grantextension"]';
55
    }
56
 
57
    async triggerBulkAction() {
58
        const selectedUsers = [...document.querySelectorAll(Selectors.selectBulkItemCheckbox)].map(checkbox => checkbox.value);
59
 
60
        const modal = await SaveCancelModal.create({
61
            title: await getString('grantextension', 'mod_assign'),
62
            buttons: {
63
                save: await getString('batchoperationgrantextension', 'mod_assign'),
64
            },
65
            body: Templates.render('mod_assign/bulkactions/grading/bulk_action_modal_body', {
66
                text: await getString('batchoperationconfirmgrantextension', 'mod_assign'),
67
                operation: 'grantextension',
68
                cmid: this.#cmid,
69
                selectedusers: selectedUsers.join(','),
70
                sesskey: this.#sesskey
71
            }),
72
            show: true,
73
            removeOnClose: true,
74
        });
75
 
76
        // Handle save event.
77
        modal.getRoot().on(ModalEvents.save, (e) => {
78
            e.preventDefault();
79
            modal.getRoot().find('form').submit();
80
        });
81
    }
82
 
83
    async renderBulkActionTrigger(showInDropdown, index) {
84
        return Templates.render('mod_assign/bulkactions/grading/bulk_extend_trigger', {
85
            showindropdown: showInDropdown,
86
            isfirst: index === 0,
87
        });
88
    }
89
}