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 |
import * as formSubmit from 'core_form/submit';
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* Module for the quick grading functionality on the submissions page.
|
|
|
20 |
*
|
|
|
21 |
* @module mod_assign/quick_grading
|
|
|
22 |
* @copyright 2024 Mihail Geshoski <mihail@moodle.com>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
/** @constant {Object} The object containing the relevant selectors. */
|
|
|
27 |
const Selectors = {
|
|
|
28 |
quickGradingSaveRegion: '[data-region="quick-grading-save"]',
|
|
|
29 |
notifyStudentsCheckbox: 'input[type="checkbox"][name="sendstudentnotifications"]',
|
|
|
30 |
notifyStudentsHidden: 'input[type="hidden"][name="sendstudentnotifications"]',
|
|
|
31 |
saveButton: 'button[type="submit"]'
|
|
|
32 |
};
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Initialize module.
|
|
|
36 |
*/
|
|
|
37 |
export const init = () => {
|
|
|
38 |
const quickGradingSaveRegion = document.querySelector(Selectors.quickGradingSaveRegion);
|
|
|
39 |
if (quickGradingSaveRegion) {
|
|
|
40 |
const quickGradingSaveButton = quickGradingSaveRegion.querySelector(Selectors.saveButton);
|
|
|
41 |
// Initialize the submit button.
|
|
|
42 |
formSubmit.init(quickGradingSaveButton);
|
|
|
43 |
// Add 'change' event listener to the quick grading save region.
|
|
|
44 |
quickGradingSaveRegion.addEventListener('change', e => {
|
|
|
45 |
const notifyStudentsCheckbox = e.target.closest(Selectors.notifyStudentsCheckbox);
|
|
|
46 |
// The target is the 'Notify student' checkbox.
|
|
|
47 |
if (notifyStudentsCheckbox) {
|
|
|
48 |
// The 'Notify student' option uses a hidden input and a checkbox. The hidden input is used to submit '0'
|
|
|
49 |
// as a workaround when the checkbox is unchecked since unchecked checkboxes are not submitted with the
|
|
|
50 |
// form. Therefore, we need to enable or disable the hidden input based on the checkbox state.
|
|
|
51 |
const notifyStudentsHidden = notifyStudentsCheckbox.parentNode.querySelector(Selectors.notifyStudentsHidden);
|
|
|
52 |
notifyStudentsHidden.disabled = notifyStudentsCheckbox.checked;
|
|
|
53 |
}
|
|
|
54 |
});
|
|
|
55 |
}
|
|
|
56 |
};
|