Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions htdocs/js/UsersAssignedToSet/usersassignedtoset.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,41 @@
document.getElementsByName('assignToSelected')[0]?.click();
});

const uncheckedCheckboxes = [];
unassign_confirm_dialog?.addEventListener('hide.bs.modal', () => {
if (unassign_confirmed) return;
for (const checkbox of uncheckedCheckboxes) {
checkbox.checked = true;
}
uncheckedCheckboxes.length = 0;
});

document.getElementById('assignForm')?.addEventListener('submit', (e) => {
const action = e.submitter?.name;
if (action === 'assignToAll') {
// Check all current users.
allCheckboxes.forEach((checkbox) => {
for (const checkbox of allCheckboxes) {
if (checkbox.dataset.isCurrent === '1') checkbox.checked = true;
});
}
// Set to false to avoid unassigning users intentionally.
const confirmInput = document.getElementsByName('allow_unassign')[0];
if (confirmInput) confirmInput.value = 0;
} else if (action === 'unassignFromAll' || action === 'assignToSelected') {
if (action === 'unassignFromAll') {
uncheckedCheckboxes.length = 0;
// Uncheck all users.
allCheckboxes.forEach((checkbox) => {
for (const checkbox of allCheckboxes) {
if (checkbox.checked) uncheckedCheckboxes.push(checkbox);
checkbox.checked = false;
});
}
}

// Check if any sets have been unchecked.
const uncheckedSets = [];
allCheckboxes.forEach((checkbox) => {
for (const checkbox of allCheckboxes) {
if (checkbox.checked === false && checkbox.dataset.isAssigned === '1')
uncheckedSets.push(checkbox.dataset.username);
});
}
if (uncheckedSets.length > 0) {
if (unassign_confirmed) {
unassign_confirmed = false;
Expand All @@ -55,4 +66,12 @@
}
}
});

for (const button of document.getElementsByName('reset-button')) {
button.addEventListener('click', () => {
for (const checkbox of allCheckboxes) {
checkbox.checked = checkbox.dataset.isAssigned === '1';
}
});
}
})();
10 changes: 7 additions & 3 deletions templates/ContentGenerator/Instructor/UsersAssignedToSet.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
class => 'visually-hidden',
tabindex => -1,
'aria-hidden' => 'true' =%>
<div class="mt-2">
<div class="mt-2 submit-buttons-container">
% if ($numberAssignedCurrentUsers < $numberCurrentUsers) {
<%= submit_button maketext('Assign to All Current Users'),
name => 'assignToAll',
Expand All @@ -55,8 +55,9 @@
<%= maketext('Use the "Assigned" checkboxes to assign/unassign this set. Unassigning the set will '
. 'delete all of the data for the associated user and cannot be undone.') =%>
</p>
<div class="mb-2">
<div class="mb-2 submit-buttons-container">
<%= submit_button maketext('Save'), name => 'assignToSelected', class => 'btn btn-primary' =%>
<button name="reset-button" type="button" class="btn btn-primary"><%= maketext('Reset') %></button>
</div>
<div class="table-responsive">
<table class="table table-bordered table-sm font-sm text-nowrap w-auto">
Expand Down Expand Up @@ -134,7 +135,10 @@
</tbody>
</table>
</div>
<%= submit_button maketext('Save'), name => 'assignToSelected', class => 'btn btn-primary' =%>
<div class="submit-buttons-container">
<%= submit_button maketext('Save'), name => 'assignToSelected', class => 'btn btn-primary' =%>
<button name="reset-button" type="button" class="btn btn-primary"><%= maketext('Reset') %></button>
</div>
<div
class="modal fade"
id="unassign_confirm_dialog"
Expand Down