From 09a89989a915134e11562bec5eff35dbc6d20d58 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Wed, 21 Oct 2026 08:50:37 -0500 Subject: [PATCH 1/2] Recheck checkboxes on the users assigned to set page after cancelling unassign from all. Pull request #3233 made it so that all checkboxes are unchecked when the "Unassign from All Users" button is used, and then the modal dialog asking for confirmation of the unassign is shown. However, if you then cancel that dialog (by clicking "Cancel", clicking anywhere outside of the dialog, clicking the close button in the dialog, or pressing the Esc key), then all of those checkboxes remain unchecked. That is not ideal. This makes it so that the status of each checkbox is put back to its state before the "Unassign from All Users" button was pressed. Also replace the `forEach` usage with `for of` loops. --- .../UsersAssignedToSet/usersassignedtoset.js | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/htdocs/js/UsersAssignedToSet/usersassignedtoset.js b/htdocs/js/UsersAssignedToSet/usersassignedtoset.js index 9b037b7d0c..b39939c976 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; From 51f1a9056d32238f4ed3df561e66d011eaa32436 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Thu, 22 Oct 2026 16:19:51 -0500 Subject: [PATCH 2/2] Also add a reset button to the "Users Assigned to Set" page. When this button is pressed, the checkboxes are all reset to their status on initial page load which is the current assignment status in the database. --- htdocs/js/UsersAssignedToSet/usersassignedtoset.js | 8 ++++++++ .../Instructor/UsersAssignedToSet.html.ep | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/htdocs/js/UsersAssignedToSet/usersassignedtoset.js b/htdocs/js/UsersAssignedToSet/usersassignedtoset.js index b39939c976..ccb22d0785 100644 --- a/htdocs/js/UsersAssignedToSet/usersassignedtoset.js +++ b/htdocs/js/UsersAssignedToSet/usersassignedtoset.js @@ -66,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' =%> -
+
% if ($numberAssignedCurrentUsers < $numberCurrentUsers) { <%= submit_button maketext('Assign to All Current Users'), name => 'assignToAll', @@ -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.') =%>

-
+
<%= submit_button maketext('Save'), name => 'assignToSelected', class => 'btn btn-primary' =%> +
@@ -134,7 +135,10 @@
- <%= submit_button maketext('Save'), name => 'assignToSelected', class => 'btn btn-primary' =%> +
+ <%= submit_button maketext('Save'), name => 'assignToSelected', class => 'btn btn-primary' =%> + +