// User Management admin page: create users, change passwords, delete users.
// CSRF token and the current user's id are handed off from PHP via
//
.
const csrfToken = document.body.dataset.csrfToken;
const currentUserId = document.body.dataset.currentUserId;
const userModal = document.getElementById('modal-user');
const passwordModal = document.getElementById('modal-password');
const editModal = document.getElementById('modal-edit');
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text ?? '';
return div.innerHTML;
}
async function postForm(formData) {
const response = await fetch('users.php', {
method: 'POST',
body: formData,
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
return response.json();
}
const EYE_OPEN_SVG = `
`;
const EYE_OFF_SVG = `
`;
function resetPasswordVisibility(form) {
form.querySelectorAll('.password-toggle-btn').forEach((btn) => {
const input = document.getElementById(btn.dataset.target);
if (input) input.type = 'password';
btn.setAttribute('aria-label', 'Show password');
btn.innerHTML = EYE_OPEN_SVG;
});
}
// Add User modal
function openUserModal() {
const form = document.getElementById('form-user');
form.reset();
resetPasswordVisibility(form);
userModal.showModal();
}
// Native