Adds authorization permissions administrator dashboard

This commit is contained in:
BinaryAlley committed 2024-12-22 19:17:47 +02:00
1 parent 152cb48050
commit 583b8db865
106 files changed
+5916 -2085

No files matched your search

@@ -70,30 +70,22 @@
</div>
@section Scripts {
<script type="text/javascript" data-form="@scriptId" defer>
document.getElementById('change-password-form').addEventListener('keypress', async (e) => {
if (e.key === 'Enter') {
e.preventDefault();
const form = e.target.closest('form');
await handleChangePassword(form);
}
});
// create cleanup registry for this view
const cleanupFunctions = [];
document.getElementById('change-password-form').addEventListener('submit', async (e) => {
e.preventDefault();
await handleChangePassword(e.target);
});
const form = document.getElementById('change-password-form');
const txtCurrentPassword = form.querySelector('[name="CurrentPassword"]');
const txtNewPassword = form.querySelector('[name="NewPassword"]');
const txtNewPasswordConfirm = form.querySelector('[name="NewPasswordConfirm"]');
async function handleChangePassword(form) {
const txtCurrentPassword = form.querySelector('[name="CurrentPassword"]');
const txtNewPassword = form.querySelector('[name="NewPassword"]');
const txtNewPasswordConfirm = form.querySelector('[name="NewPasswordConfirm"]');
const changePasswordSuccess = document.getElementById('change-password-success');
const divCurrentPassword = document.getElementById('div-current-password');
const divNewPassword = document.getElementById('div-new-password');
const divNewPasswordConfirm = document.getElementById('div-new-password-confirm');
const divChangePasswordSubmit = document.getElementById('div-change-password-submit');
const changePasswordSuccess = document.getElementById('change-password-success');
const divCurrentPassword = document.getElementById('div-current-password');
const divNewPassword = document.getElementById('div-new-password');
const divNewPasswordConfirm = document.getElementById('div-new-password-confirm');
const divChangePasswordSubmit = document.getElementById('div-change-password-submit');
// perform the password change
async function handleChangePasswordAsync() {
const formData = {
CurrentPassword: txtCurrentPassword.value,
NewPassword: txtNewPassword.value,
@@ -108,5 +100,37 @@
divChangePasswordSubmit.classList.add('hidden');
}
}
// on Enter key pressed
const handleEnterKey = async function(e) {
if (e.key === 'Enter') {
e.preventDefault();
await handleChangePasswordAsync();
}
};
// on form submit event
const handleSubmit = async function(e) {
e.preventDefault();
await handleChangePasswordAsync();
};
// add listeners
form.addEventListener('keypress', handleEnterKey);
form.addEventListener('submit', handleSubmit);
// register cleanup for these listeners
cleanupFunctions.push(() => {
form.removeEventListener('keypress', handleEnterKey);
form.removeEventListener('submit', handleSubmit);
});
// store all cleanups for this view on window object using the scriptId
window.viewCleanups = window.viewCleanups || {};
window.viewCleanups['@scriptId'] = () => {
cleanupFunctions.forEach(cleanup => cleanup());
console.log(`Unloaded @scriptId`);
};
console.log(`Loaded @scriptId`);
</script>
}