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 for defining the bulk actions area in the assignment grading page.
|
|
|
18 |
*
|
|
|
19 |
* @module mod_assign/bulkactions/grading/bulk_actions
|
|
|
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 BulkActions from 'core/bulkactions/bulk_actions';
|
|
|
25 |
import GeneralAction from './general_action';
|
|
|
26 |
import DeleteAction from './delete';
|
|
|
27 |
import ExtendAction from './extend';
|
|
|
28 |
import MessageAction from './message';
|
|
|
29 |
import SetMarkingAllocationAction from './setmarkingallocation';
|
|
|
30 |
import SetMarkingWorkflowStateAction from './setmarkingworkflowstate';
|
|
|
31 |
import Templates from 'core/templates';
|
|
|
32 |
import {getString} from 'core/str';
|
|
|
33 |
|
|
|
34 |
const Selectors = {
|
|
|
35 |
selectBulkItemCheckbox: 'input[type="checkbox"][name="selectedusers"]',
|
|
|
36 |
selectBulkItemTrigger: 'input[type="checkbox"][name="selectedusers"], input[type="checkbox"][name="selectall"]',
|
|
|
37 |
};
|
|
|
38 |
|
|
|
39 |
export default class extends BulkActions {
|
|
|
40 |
/** @type {number} The course module ID. */
|
|
|
41 |
#cmid;
|
|
|
42 |
|
|
|
43 |
/** @type {boolean} Whether to show the extend action. */
|
|
|
44 |
#extend;
|
|
|
45 |
|
|
|
46 |
/** @type {boolean} Whether to show the grant extension action. */
|
|
|
47 |
#grantAttempt;
|
|
|
48 |
|
|
|
49 |
/** @type {boolean} Whether to show the set marking allocation action. */
|
|
|
50 |
#markingAllocation;
|
|
|
51 |
|
|
|
52 |
/** @type {string} Whether to show the message action. */
|
|
|
53 |
#message;
|
|
|
54 |
|
|
|
55 |
/** @type {Array} The list of plugin operations. */
|
|
|
56 |
#pluginOperations;
|
|
|
57 |
|
|
|
58 |
/** @type {boolean} Whether to show the remove submission action. */
|
|
|
59 |
#removeSubmission;
|
|
|
60 |
|
|
|
61 |
/** @type {string} The session key. */
|
|
|
62 |
#sesskey;
|
|
|
63 |
|
|
|
64 |
/** @type {boolean} Whether to show the revert to draft action. */
|
|
|
65 |
#submissionDrafts;
|
|
|
66 |
|
|
|
67 |
/** @type {boolean} Whether to show the set workflow state action. */
|
|
|
68 |
#workflowState;
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Returns the instance of the class.
|
|
|
72 |
*
|
|
|
73 |
* @param {Object} options - The options object.
|
|
|
74 |
* @param {number} options.cmid - The course module ID.
|
|
|
75 |
* @param {string} options.message - Whether to show the message action.
|
|
|
76 |
* @param {boolean} options.submissiondrafts - Whether to show the revert to draft action.
|
|
|
77 |
* @param {boolean} options.removesubmission - Whether to show the remove submission action.
|
|
|
78 |
* @param {boolean} options.extend - Whether to show the grant extension action.
|
|
|
79 |
* @param {boolean} options.grantattempt - Whether to show the grant attempt action.
|
|
|
80 |
* @param {boolean} options.workflowstate - Whether to show the set workflow state action.
|
|
|
81 |
* @param {boolean} options.markingallocation - Whether to show the set marking allocation action.
|
|
|
82 |
* @param {Array} options.pluginoperations - The list of plugin operations.
|
|
|
83 |
* @param {string} options.sesskey - The session key.
|
|
|
84 |
* @returns {this} An instance of the anonymous class extending BulkActions.
|
|
|
85 |
*/
|
|
|
86 |
static init(options) {
|
|
|
87 |
return new this(options);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* The class constructor
|
|
|
92 |
*
|
|
|
93 |
* @param {Object} options - The options object.
|
|
|
94 |
* @param {number} options.cmid - The course module ID.
|
|
|
95 |
* @param {string} options.message - Whether to show the message action.
|
|
|
96 |
* @param {boolean} options.submissiondrafts - Whether to show the revert to draft action.
|
|
|
97 |
* @param {boolean} options.removesubmission - Whether to show the remove submission action.
|
|
|
98 |
* @param {boolean} options.extend - Whether to show the grant extension action.
|
|
|
99 |
* @param {boolean} options.grantattempt - Whether to show the grant attempt action.
|
|
|
100 |
* @param {boolean} options.workflowstate - Whether to show the set workflow state action.
|
|
|
101 |
* @param {boolean} options.markingallocation - Whether to show the set marking allocation action.
|
|
|
102 |
* @param {Array} options.pluginoperations - The list of plugin operations.
|
|
|
103 |
* @param {string} options.sesskey - The session key.
|
|
|
104 |
*/
|
|
|
105 |
constructor({
|
|
|
106 |
cmid, message, submissiondrafts, removesubmission, extend,
|
|
|
107 |
grantattempt, workflowstate, markingallocation, pluginoperations, sesskey
|
|
|
108 |
}) {
|
|
|
109 |
super();
|
|
|
110 |
this.#cmid = cmid;
|
|
|
111 |
this.#message = message;
|
|
|
112 |
this.#submissionDrafts = submissiondrafts;
|
|
|
113 |
this.#removeSubmission = removesubmission;
|
|
|
114 |
this.#extend = extend;
|
|
|
115 |
this.#grantAttempt = grantattempt;
|
|
|
116 |
this.#workflowState = workflowstate;
|
|
|
117 |
this.#markingAllocation = markingallocation;
|
|
|
118 |
this.#sesskey = sesskey;
|
|
|
119 |
this.#pluginOperations = pluginoperations;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
getBulkActions() {
|
|
|
123 |
const actions = [
|
|
|
124 |
new GeneralAction(
|
|
|
125 |
this.#cmid,
|
|
|
126 |
this.#sesskey,
|
|
|
127 |
'lock',
|
|
|
128 |
getString('batchoperationlock', 'mod_assign'),
|
|
|
129 |
Templates.renderPix('i/lock', 'core'),
|
|
|
130 |
getString('locksubmissions', 'mod_assign'),
|
|
|
131 |
getString('batchoperationconfirmlock', 'mod_assign'),
|
|
|
132 |
getString('batchoperationlock', 'mod_assign'),
|
|
|
133 |
),
|
|
|
134 |
new GeneralAction(
|
|
|
135 |
this.#cmid,
|
|
|
136 |
this.#sesskey,
|
|
|
137 |
'unlock',
|
|
|
138 |
getString('batchoperationunlock', 'mod_assign'),
|
|
|
139 |
Templates.renderPix('i/unlock', 'core'),
|
|
|
140 |
getString('unlocksubmissions', 'mod_assign'),
|
|
|
141 |
getString('batchoperationconfirmunlock', 'mod_assign'),
|
|
|
142 |
getString('batchoperationunlock', 'mod_assign'),
|
|
|
143 |
),
|
|
|
144 |
new GeneralAction(
|
|
|
145 |
this.#cmid,
|
|
|
146 |
this.#sesskey,
|
|
|
147 |
'downloadselected',
|
|
|
148 |
getString('batchoperationdownloadselected', 'mod_assign'),
|
|
|
149 |
Templates.renderPix('t/download', 'core'),
|
|
|
150 |
getString('downloadselectedsubmissions', 'mod_assign'),
|
|
|
151 |
getString('batchoperationconfirmdownloadselected', 'mod_assign'),
|
|
|
152 |
getString('batchoperationdownloadselected', 'mod_assign'),
|
|
|
153 |
),
|
|
|
154 |
];
|
|
|
155 |
|
|
|
156 |
if (this.#removeSubmission) {
|
|
|
157 |
actions.push(new DeleteAction(this.#cmid, this.#sesskey));
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
if (this.#extend) {
|
|
|
161 |
actions.push(new ExtendAction(this.#cmid, this.#sesskey));
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
if (this.#grantAttempt) {
|
|
|
165 |
actions.push(
|
|
|
166 |
new GeneralAction(
|
|
|
167 |
this.#cmid,
|
|
|
168 |
this.#sesskey,
|
|
|
169 |
'addattempt',
|
|
|
170 |
getString('batchoperationaddattempt', 'mod_assign'),
|
|
|
171 |
Templates.renderPix('t/add', 'core'),
|
|
|
172 |
getString('addattempt', 'mod_assign'),
|
|
|
173 |
getString('batchoperationconfirmaddattempt', 'mod_assign'),
|
|
|
174 |
getString('batchoperationaddattempt', 'mod_assign'),
|
|
|
175 |
)
|
|
|
176 |
);
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
if (this.#workflowState) {
|
|
|
180 |
actions.push(new SetMarkingWorkflowStateAction(this.#cmid, this.#sesskey));
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
if (this.#markingAllocation) {
|
|
|
184 |
actions.push(new SetMarkingAllocationAction(this.#cmid, this.#sesskey));
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
if (this.#submissionDrafts) {
|
|
|
188 |
actions.push(
|
|
|
189 |
new GeneralAction(
|
|
|
190 |
this.#cmid,
|
|
|
191 |
this.#sesskey,
|
|
|
192 |
'reverttodraft',
|
|
|
193 |
getString('batchoperationreverttodraft', 'mod_assign'),
|
|
|
194 |
Templates.renderPix('e/undo', 'core'),
|
|
|
195 |
getString('reverttodraft', 'mod_assign'),
|
|
|
196 |
getString('batchoperationconfirmreverttodraft', 'mod_assign'),
|
|
|
197 |
getString('batchoperationreverttodraft', 'mod_assign'),
|
|
|
198 |
)
|
|
|
199 |
);
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
if (this.#message) {
|
|
|
203 |
actions.push(new MessageAction());
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
for (const operation of this.#pluginOperations) {
|
|
|
207 |
actions.push(
|
|
|
208 |
new GeneralAction(
|
|
|
209 |
this.#cmid,
|
|
|
210 |
this.#sesskey,
|
|
|
211 |
operation.key,
|
|
|
212 |
operation.label,
|
|
|
213 |
operation.icon,
|
|
|
214 |
operation.confirmationtitle,
|
|
|
215 |
operation.confirmationquestion,
|
|
|
216 |
)
|
|
|
217 |
);
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
return actions;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
getSelectedItems() {
|
|
|
224 |
return document.querySelectorAll(`${Selectors.selectBulkItemCheckbox}:checked`);
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
registerItemSelectChangeEvent(eventHandler) {
|
|
|
228 |
const itemSelectCheckboxes = document.querySelectorAll(Selectors.selectBulkItemTrigger);
|
|
|
229 |
itemSelectCheckboxes.forEach((checkbox) => {
|
|
|
230 |
checkbox.addEventListener('change', eventHandler.bind(this));
|
|
|
231 |
});
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
deselectItem(selectedItem) {
|
|
|
235 |
selectedItem.checked = false;
|
|
|
236 |
selectedItem.closest('tr').classList.replace('selectedrow', 'unselectedrow');
|
|
|
237 |
}
|
|
|
238 |
}
|