diff --git a/htdocs/js/UsersAssignedToSet/usersassignedtoset.js b/htdocs/js/UsersAssignedToSet/usersassignedtoset.js index 9b037b7d0c..ccb22d0785 100644 --- a/htdocs/js/UsersAssignedToSet/usersassignedtoset.js +++ b/htdocs/js/UsersAssignedToSet/usersassignedtoset.js @@ -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; @@ -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'; + } + }); + } })(); diff --git a/templates/ContentGenerator/Instructor/UsersAssignedToSet.html.ep b/templates/ContentGenerator/Instructor/UsersAssignedToSet.html.ep index da750d3bf9..bfd5347b29 100644 --- a/templates/ContentGenerator/Instructor/UsersAssignedToSet.html.ep +++ b/templates/ContentGenerator/Instructor/UsersAssignedToSet.html.ep @@ -39,7 +39,7 @@ class => 'visually-hidden', tabindex => -1, 'aria-hidden' => 'true' =%> -