64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
import * as Data from "../data.js";
|
|
import * as Form from "../form.js";
|
|
|
|
const submissionForm = document.getElementById('submission-form');
|
|
const nameTextbox = document.getElementById('name-textbox');
|
|
const emailTextbox = document.getElementById('email-textbox');
|
|
const passwordTextbox = document.getElementById('password-textbox');
|
|
const adminCheckboxSection = document.getElementById('admin-checkbox-section');
|
|
const adminCheckbox = document.getElementById('admin-checkbox');
|
|
const submitButton = document.getElementById('submit-button');
|
|
const deleteButton = document.getElementById('delete-button');
|
|
|
|
async function Initialize() {
|
|
let params = new URLSearchParams(location.search);
|
|
let accountID = params.get('account') || (document.getElementById('account-id') ? document.getElementById('account-id').value : null);
|
|
if(accountID) {
|
|
const account = await Data.getAccount(accountID);
|
|
console.log(account);
|
|
|
|
nameTextbox.value = account.name;
|
|
|
|
emailTextbox.value = account.email;
|
|
|
|
passwordTextbox.placeholder = "leave unchanged";
|
|
|
|
adminCheckbox.checked = account.isAdmin;
|
|
|
|
if(!document.getElementById('account-id')) {
|
|
adminCheckboxSection.style.visibility = "visible";
|
|
adminCheckbox.disabled = false;
|
|
|
|
Form.addHiddenValue('account', accountID, submissionForm);
|
|
}
|
|
|
|
deleteButton.style.visibility = "visible";
|
|
deleteButton.disabled = false;
|
|
}
|
|
else
|
|
{
|
|
adminCheckboxSection.style.visibility = "visible";
|
|
adminCheckbox.disabled = false;
|
|
}
|
|
nameTextbox.disabled = false;
|
|
nameTextbox.addEventListener('keyup', checkDataValidity);
|
|
emailTextbox.disabled = false;
|
|
emailTextbox.addEventListener('keyup', checkDataValidity);
|
|
passwordTextbox.disabled = false;
|
|
passwordTextbox.addEventListener('keyup', checkDataValidity);
|
|
checkDataValidity();
|
|
}
|
|
Initialize();
|
|
|
|
async function checkDataValidity() {
|
|
let dataIsValid = true;
|
|
|
|
if(!passwordTextbox.value && !passwordTextbox.placeholder) dataIsValid = false;
|
|
if(!nameTextbox.value) dataIsValid = false;
|
|
if(!emailTextbox.value) dataIsValid = false;
|
|
|
|
if(dataIsValid) submitButton.disabled = false;
|
|
else submitButton.disabled = true;
|
|
}
|
|
|
|
Form.addRemoveFunction(deleteButton, submissionForm, "account"); |