users: Drop jQuery code as the library dependency has been removed

Closes: #2484

Tests:

- Functional tests for users app works.

- When updating the user if the delete user is not checked, delete confirmation
dialog is not shown.

- When updating the user if the delete user is checked, delete confirmation
dialog is shown. It can be dismissed and re-shown many times. When confirm
button is clicked, the form is submitted and user is deleted.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2025-01-04 11:36:01 -08:00 committed by James Valleroy
parent 79482f7a38
commit f2ce5b7afd
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -22,8 +22,6 @@
* in this page.
*/
var deleteConfirmed = false;
document.addEventListener('DOMContentLoaded', (event) => {
const form = document.querySelector('form.form-update');
form.addEventListener('submit', onUserUpdateSubmit);
@ -33,28 +31,31 @@ document.addEventListener('DOMContentLoaded', (event) => {
confirmDeleteButton.addEventListener('click', () => {
onUserDeleteConfirmed(form);
});
var deleteConfirmed = false;
const modal = new bootstrap.Modal('#user-delete-confirm-dialog');
// Show the confirmation dialog if the delete checkbox is selected
function onUserUpdateSubmit(event) {
const deleteUserCheckbox = document.getElementById('id_delete');
if (!deleteUserCheckbox.checked) {
return;
}
if (deleteConfirmed) { // Deletion is already confirmed
deleteConfirmed = false;
return;
}
event.preventDefault();
modal.show();
};
// Submit the user edit form
function onUserDeleteConfirmed(form) {
deleteConfirmed = true;
modal.hide();
// Click instead of submit to disable the submission button
form.querySelector('input[type=submit]').click();
};
});
// Show the confirmation dialog if the delete checkbox is selected
function onUserUpdateSubmit(event) {
const deleteUserCheckbox = document.getElementById('id_delete');
if (!deleteUserCheckbox.checked) {
return;
}
if (deleteConfirmed) { // Deletion is already confirmed
deleteConfirmed = false;
return;
}
event.preventDefault();
$("#user-delete-confirm-dialog").modal('show');
};
// Submit the user edit form
function onUserDeleteConfirmed(form) {
deleteConfirmed = true;
$('#user-delete-confirm-dialog').modal('hide');
// Click instead of submit to disable the submission button
form.querySelector('input[type=submit]').click();
};