Línea 19... |
Línea 19... |
19 |
* @module core_admin/bulk_user_actions
|
19 |
* @module core_admin/bulk_user_actions
|
20 |
* @copyright 2024 Marina Glancy
|
20 |
* @copyright 2024 Marina Glancy
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
22 |
*/
|
22 |
*/
|
Línea 23... |
Línea 23... |
23 |
|
23 |
|
24 |
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
24 |
import * as reportSelectors from "core_reportbuilder/local/selectors";
|
25 |
import * as tableEvents from 'core_table/local/dynamic/events';
|
25 |
import * as tableEvents from "core_table/local/dynamic/events";
|
26 |
import * as FormChangeChecker from 'core_form/changechecker';
|
26 |
import * as FormChangeChecker from "core_form/changechecker";
|
27 |
import * as CustomEvents from 'core/custom_interaction_events';
|
27 |
import * as CustomEvents from "core/custom_interaction_events";
|
Línea 28... |
Línea 28... |
28 |
import jQuery from 'jquery';
|
28 |
import jQuery from "jquery";
|
29 |
|
29 |
|
30 |
const Selectors = {
|
30 |
const Selectors = {
|
- |
|
31 |
bulkActionsForm: "form#user-bulk-action-form",
|
31 |
bulkActionsForm: 'form#user-bulk-action-form',
|
32 |
userReportWrapper: '[data-region="report-user-list-wrapper"]',
|
- |
|
33 |
checkbox:
|
32 |
userReportWrapper: '[data-region="report-user-list-wrapper"]',
|
34 |
'input[type="checkbox"][data-togglegroup="report-select-all"][data-toggle="slave"]',
|
- |
|
35 |
masterCheckbox:
|
33 |
checkbox: 'input[type="checkbox"][data-togglegroup="report-select-all"][data-toggle="slave"]',
|
36 |
'input[type="checkbox"][data-togglegroup="report-select-all"][data-toggle="master"]',
|
34 |
masterCheckbox: 'input[type="checkbox"][data-togglegroup="report-select-all"][data-toggle="master"]',
|
37 |
checkedRows:
|
Línea 35... |
Línea 38... |
35 |
checkedRows: '[data-togglegroup="report-select-all"][data-toggle="slave"]:checked',
|
38 |
'[data-togglegroup="report-select-all"][data-toggle="slave"]:checked',
|
36 |
};
|
39 |
};
|
37 |
|
40 |
|
38 |
/**
|
41 |
/**
|
- |
|
42 |
* Initialise module
|
- |
|
43 |
*/
|
- |
|
44 |
export const init = () => {
|
- |
|
45 |
const userBulkForm = document.querySelector(Selectors.bulkActionsForm);
|
- |
|
46 |
const userReport = userBulkForm
|
- |
|
47 |
?.closest(Selectors.userReportWrapper)
|
- |
|
48 |
?.querySelector(reportSelectors.regions.report);
|
- |
|
49 |
if (!userBulkForm || !userReport) {
|
- |
|
50 |
return;
|
- |
|
51 |
}
|
- |
|
52 |
const actionSelect = userBulkForm.querySelector("select");
|
- |
|
53 |
CustomEvents.define(actionSelect, [CustomEvents.events.accessibleChange]);
|
- |
|
54 |
|
- |
|
55 |
jQuery(actionSelect).on(CustomEvents.events.accessibleChange, (event) => {
|
- |
|
56 |
if (event.target.value && `${event.target.value}` !== "0") {
|
- |
|
57 |
const e = new Event("submit", { cancelable: true });
|
- |
|
58 |
userBulkForm.dispatchEvent(e);
|
- |
|
59 |
if (!e.defaultPrevented) {
|
- |
|
60 |
FormChangeChecker.markFormSubmitted(userBulkForm);
|
- |
|
61 |
userBulkForm.submit();
|
Línea -... |
Línea 62... |
- |
|
62 |
}
|
- |
|
63 |
}
|
- |
|
64 |
});
|
- |
|
65 |
|
39 |
* Initialise module
|
66 |
// Every time the checkboxes in the report are changed, update the list of users in the form values
|
- |
|
67 |
// and enable/disable the action select.
|
40 |
*/
|
68 |
const updateUserIds = () => {
|
- |
|
69 |
const selectedUsers = [
|
- |
|
70 |
...userReport.querySelectorAll(Selectors.checkedRows),
|
- |
|
71 |
];
|
- |
|
72 |
const selectedUserIds = selectedUsers.map((check) => parseInt(check.value));
|
- |
|
73 |
userBulkForm.querySelector('[name="userids"]').value =
|
41 |
export const init = () => {
|
74 |
selectedUserIds.join(",");
|
42 |
|
75 |
|
43 |
const userBulkForm = document.querySelector(Selectors.bulkActionsForm);
|
76 |
// Disable the action selector if nothing selected, and reset the current selection.
|
44 |
const userReport = userBulkForm?.closest(Selectors.userReportWrapper)?.querySelector(reportSelectors.regions.report);
|
- |
|
45 |
if (!userBulkForm || !userReport) {
|
- |
|
Línea 46... |
Línea -... |
46 |
return;
|
- |
|
47 |
}
|
- |
|
48 |
const actionSelect = userBulkForm.querySelector('select');
|
77 |
actionSelect.disabled = selectedUsers.length === 0;
|
49 |
CustomEvents.define(actionSelect, [CustomEvents.events.accessibleChange]);
|
- |
|
50 |
|
- |
|
51 |
jQuery(actionSelect).on(CustomEvents.events.accessibleChange, event => {
|
78 |
if (actionSelect.disabled) {
|
52 |
if (event.target.value && `${event.target.value}` !== "0") {
|
- |
|
53 |
const e = new Event('submit', {cancelable: true});
|
- |
|
54 |
userBulkForm.dispatchEvent(e);
|
- |
|
55 |
if (!e.defaultPrevented) {
|
79 |
actionSelect.value = "0";
|
56 |
FormChangeChecker.markFormSubmitted(userBulkForm);
|
- |
|
57 |
userBulkForm.submit();
|
80 |
}
|
58 |
}
|
81 |
|
59 |
}
|
82 |
const selectedUsersNames = selectedUsers.map(
|
60 |
});
|
- |
|
61 |
|
- |
|
62 |
// Every time the checkboxes in the report are changed, update the list of users in the form values
|
- |
|
63 |
// and enable/disable the action select.
|
- |
|
64 |
const updateUserIds = () => {
|
- |
|
65 |
const selectedUsers = [...userReport.querySelectorAll(Selectors.checkedRows)];
|
- |
|
66 |
const selectedUserIds = selectedUsers.map(check => parseInt(check.value));
|
83 |
(check) => document.querySelector(`label[for="${check.id}"]`).textContent
|
67 |
userBulkForm.querySelector('[name="userids"]').value = selectedUserIds.join(',');
|
84 |
);
|
68 |
|
- |
|
69 |
// Disable the action selector if nothing selected, and reset the current selection.
|
- |
|
70 |
actionSelect.disabled = selectedUsers.length === 0;
|
- |
|
71 |
if (actionSelect.disabled) {
|
- |
|
72 |
actionSelect.value = "0";
|
- |
|
73 |
}
|
- |
|
74 |
|
85 |
// Add the user ids and names to the form data attributes so they can be available from the
|
- |
|
86 |
// other JS modules that listen to the form submit event.
|
- |
|
87 |
userBulkForm.data = {
|
- |
|
88 |
userids: selectedUserIds,
|
Línea -... |
Línea 89... |
- |
|
89 |
usernames: selectedUsersNames,
|
- |
|
90 |
};
|
- |
|
91 |
};
|
- |
|
92 |
|
- |
|
93 |
updateUserIds();
|
- |
|
94 |
|
- |
|
95 |
document.addEventListener("change", (event) => {
|
75 |
const selectedUsersNames = selectedUsers.map(check => document.querySelector(`label[for="${check.id}"]`).textContent);
|
96 |
// When checkboxes are checked next to individual users or the master toggle (Select all/none).
|
- |
|
97 |
if (
|
- |
|
98 |
(event.target.matches(Selectors.checkbox) ||
|
Línea 76... |
Línea -... |
76 |
// Add the user ids and names to the form data attributes so they can be available from the
|
- |
|
77 |
// other JS modules that listen to the form submit event.
|
- |
|
78 |
userBulkForm.data = {userids: selectedUserIds, usernames: selectedUsersNames};
|
- |
|
79 |
};
|
- |
|
80 |
|
- |
|
81 |
updateUserIds();
|
- |
|
82 |
|
- |
|
83 |
document.addEventListener('change', event => {
|
- |
|
84 |
// When checkboxes are checked next to individual users or the master toggle (Select all/none).
|
99 |
event.target.matches(Selectors.masterCheckbox)) &&
|
85 |
if ((event.target.matches(Selectors.checkbox) || event.target.matches(Selectors.masterCheckbox))
|
100 |
userReport.contains(event.target)
|
86 |
&& userReport.contains(event.target)) {
|
101 |
) {
|
87 |
updateUserIds();
|
102 |
updateUserIds();
|
88 |
}
|
103 |
}
|
89 |
});
|
104 |
});
|
90 |
|
105 |
|