2020-12-28 19:56:11 +00:00
|
|
|
import { toggleTheme, loadTheme } from "./modules/theme.js";
|
2020-12-28 18:15:52 +00:00
|
|
|
import { Modal } from "./modules/modal.js";
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2020-12-28 19:56:11 +00:00
|
|
|
loadTheme();
|
2020-12-24 21:22:28 +00:00
|
|
|
(document.getElementById('button-theme') as HTMLSpanElement).onclick = toggleTheme;
|
|
|
|
|
2020-12-20 22:49:54 +00:00
|
|
|
const whichAnimationEvent = () => {
|
|
|
|
const el = document.createElement("fakeElement");
|
|
|
|
if (el.style["animation"] !== void 0) {
|
|
|
|
return "animationend";
|
|
|
|
}
|
|
|
|
return "webkitAnimationEnd";
|
|
|
|
}
|
|
|
|
window.animationEvent = whichAnimationEvent();
|
|
|
|
const toggles: HTMLInputElement[] = Array.from(document.getElementsByClassName('toggle-details'));
|
|
|
|
for (let toggle of toggles) {
|
|
|
|
toggle.onclick = () => {
|
|
|
|
const el = toggle.parentElement.parentElement.parentElement.nextElementSibling as HTMLDivElement;
|
2020-12-26 15:51:07 +00:00
|
|
|
if (el.classList.contains("focused")) {
|
|
|
|
el.classList.toggle("focused");
|
|
|
|
el.classList.toggle("unfocused");
|
2020-12-20 22:49:54 +00:00
|
|
|
} else {
|
2020-12-26 15:51:07 +00:00
|
|
|
el.classList.toggle("unfocused");
|
|
|
|
el.classList.toggle("focused");
|
2020-12-20 22:49:54 +00:00
|
|
|
}
|
|
|
|
toggle.previousElementSibling.classList.toggle("rotated");
|
|
|
|
toggle.previousElementSibling.classList.toggle("not-rotated");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const checkInfUses = function (check: HTMLInputElement, mode = 2) {
|
|
|
|
const uses = document.getElementById('inv-uses') as HTMLInputElement;
|
|
|
|
if (mode == 2) {
|
|
|
|
uses.disabled = check.checked;
|
2020-12-27 16:56:55 +00:00
|
|
|
check.parentElement.classList.toggle('~neutral');
|
|
|
|
check.parentElement.classList.toggle('~urge');
|
|
|
|
check.parentElement.parentElement.nextElementSibling.classList.toggle('unfocused');
|
2020-12-20 22:49:54 +00:00
|
|
|
} else if (mode == 1) {
|
|
|
|
uses.disabled = true;
|
|
|
|
check.checked = true;
|
2020-12-27 16:56:55 +00:00
|
|
|
check.parentElement.classList.remove('~neutral');
|
|
|
|
check.parentElement.classList.add('~urge');
|
|
|
|
check.parentElement.parentElement.nextElementSibling.classList.remove('unfocused');
|
2020-12-20 22:49:54 +00:00
|
|
|
} else {
|
|
|
|
uses.disabled = false;
|
|
|
|
check.checked = false;
|
2020-12-27 16:56:55 +00:00
|
|
|
check.parentElement.classList.remove('~urge');
|
|
|
|
check.parentElement.classList.add('~neutral');
|
|
|
|
check.parentElement.parentElement.nextElementSibling.classList.add('unfocused');
|
2020-12-20 22:49:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let invInfUses = document.getElementById('inv-inf-uses') as HTMLInputElement;
|
|
|
|
invInfUses.onclick = () => { checkInfUses(invInfUses, 2); };
|
|
|
|
|
|
|
|
const checkEmailEnabled = function (check: HTMLInputElement, mode = 2) {
|
|
|
|
const input = document.getElementById('inv-email') as HTMLInputElement;
|
|
|
|
if (mode == 2) {
|
|
|
|
input.disabled = !check.checked;
|
2020-12-27 16:56:55 +00:00
|
|
|
check.parentElement.classList.toggle('~neutral');
|
|
|
|
check.parentElement.classList.toggle('~urge');
|
2020-12-20 22:49:54 +00:00
|
|
|
} else if (mode == 1) {
|
|
|
|
input.disabled = false;
|
|
|
|
check.checked = true;
|
2020-12-27 16:56:55 +00:00
|
|
|
check.parentElement.classList.remove('~neutral');
|
|
|
|
check.parentElement.classList.add('~urge');
|
2020-12-20 22:49:54 +00:00
|
|
|
} else {
|
|
|
|
input.disabled = true;
|
|
|
|
check.checked = false;
|
2020-12-27 16:56:55 +00:00
|
|
|
check.parentElement.classList.remove('~urge');
|
|
|
|
check.parentElement.classList.add('~neutral');
|
2020-12-20 22:49:54 +00:00
|
|
|
}
|
|
|
|
};
|
2020-12-28 19:56:11 +00:00
|
|
|
|
2020-12-20 22:49:54 +00:00
|
|
|
let invEmailEnabled = document.getElementById('inv-email-enabled') as HTMLInputElement;
|
|
|
|
invEmailEnabled.onchange = () => { checkEmailEnabled(invEmailEnabled, 2); };
|
|
|
|
|
|
|
|
checkInfUses(invInfUses, 0);
|
|
|
|
checkEmailEnabled(invEmailEnabled, 0);
|
|
|
|
|
|
|
|
const loadAccounts = function () {
|
|
|
|
const rows: HTMLTableRowElement[] = Array.from(document.getElementById("accounts-list").children);
|
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
|
const row = rows[i];
|
|
|
|
const editButton = row.querySelector(".icon") as HTMLElement;
|
|
|
|
const emailInput = row.querySelector(".input") as HTMLInputElement;
|
2020-12-27 16:56:55 +00:00
|
|
|
const outerClickListener = (event: Event) => {
|
|
|
|
if (!(event.target instanceof HTMLElement && (emailInput.contains(event.target) || editButton.contains(event.target)))) {
|
|
|
|
emailInput.classList.toggle('stealth-input-hidden');
|
|
|
|
emailInput.readOnly = !emailInput.readOnly;
|
|
|
|
editButton.classList.toggle('ri-edit-line');
|
|
|
|
editButton.classList.toggle('ri-check-line');
|
|
|
|
document.removeEventListener('click', outerClickListener);
|
|
|
|
}
|
|
|
|
};
|
2020-12-20 22:49:54 +00:00
|
|
|
editButton.onclick = function () {
|
|
|
|
emailInput.classList.toggle('stealth-input-hidden');
|
|
|
|
emailInput.readOnly = !emailInput.readOnly;
|
2020-12-27 16:56:55 +00:00
|
|
|
editButton.classList.toggle('ri-edit-line');
|
|
|
|
editButton.classList.toggle('ri-check-line');
|
|
|
|
if (editButton.classList.contains('ri-check-line')) {
|
|
|
|
document.addEventListener('click', outerClickListener);
|
|
|
|
}
|
2020-12-20 22:49:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
loadAccounts();
|
|
|
|
|
2020-12-23 01:34:22 +00:00
|
|
|
const modifySettingsSource = function () {
|
|
|
|
const profile = document.getElementById('radio-use-profile') as HTMLInputElement;
|
|
|
|
const user = document.getElementById('radio-use-user') as HTMLInputElement;
|
|
|
|
const profileSelect = document.getElementById('modify-user-profiles') as HTMLDivElement;
|
|
|
|
const userSelect = document.getElementById('modify-user-users') as HTMLDivElement;
|
|
|
|
(user.nextElementSibling as HTMLSpanElement).classList.toggle('!normal');
|
|
|
|
(user.nextElementSibling as HTMLSpanElement).classList.toggle('!high');
|
|
|
|
(profile.nextElementSibling as HTMLSpanElement).classList.toggle('!normal');
|
|
|
|
(profile.nextElementSibling as HTMLSpanElement).classList.toggle('!high');
|
2020-12-26 15:51:07 +00:00
|
|
|
profileSelect.classList.toggle('unfocused');
|
|
|
|
userSelect.classList.toggle('unfocused');
|
2020-12-23 01:34:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const radioUseProfile = document.getElementById('radio-use-profile') as HTMLInputElement;
|
|
|
|
radioUseProfile.addEventListener("change", modifySettingsSource);
|
|
|
|
radioUseProfile.checked = true;
|
|
|
|
const radioUseUser = document.getElementById('radio-use-user') as HTMLInputElement;
|
|
|
|
radioUseUser.addEventListener("change", modifySettingsSource);
|
|
|
|
radioUseUser.checked = false;
|
|
|
|
|
|
|
|
const checkDeleteUserNotify = function () {
|
|
|
|
if ((document.getElementById('delete-user-notify') as HTMLInputElement).checked) {
|
2020-12-26 15:51:07 +00:00
|
|
|
document.getElementById('textarea-delete-user').classList.remove('unfocused');
|
2020-12-23 01:34:22 +00:00
|
|
|
} else {
|
2020-12-26 15:51:07 +00:00
|
|
|
document.getElementById('textarea-delete-user').classList.add('unfocused');
|
2020-12-23 01:34:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
(document.getElementById('delete-user-notify') as HTMLInputElement).onchange = checkDeleteUserNotify;
|
|
|
|
checkDeleteUserNotify();
|
|
|
|
|
2020-12-20 22:49:54 +00:00
|
|
|
const tabs = ["invitesTab", "accountsTab", "settingsTab"]
|
|
|
|
for (let tab of tabs) {
|
|
|
|
(document.getElementById(`${tab}-button`) as HTMLSpanElement).onclick = function () {
|
|
|
|
for (let t of tabs) {
|
|
|
|
const tabEl = document.getElementById(t) as HTMLDivElement;
|
|
|
|
const tabButtonEl = document.getElementById(`${t}-button`) as HTMLSpanElement;
|
|
|
|
if (t == tab) {
|
2020-12-24 21:22:28 +00:00
|
|
|
tabButtonEl.classList.add("active", "~urge");
|
2020-12-20 22:49:54 +00:00
|
|
|
tabEl.classList.remove("unfocused");
|
|
|
|
} else {
|
|
|
|
tabButtonEl.classList.remove("active");
|
2020-12-24 21:22:28 +00:00
|
|
|
tabButtonEl.classList.remove("~urge");
|
2020-12-20 22:49:54 +00:00
|
|
|
tabEl.classList.add("unfocused");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-28 18:15:52 +00:00
|
|
|
window.modals = {} as Modals;
|
|
|
|
|
|
|
|
window.modals.login = new Modal(document.getElementById('modal-login'), true);
|
|
|
|
document.getElementById('form-login').addEventListener('submit', window.modals.login.close);
|
|
|
|
document.getElementById('modalButton').onclick = window.modals.login.toggle;
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2020-12-28 18:15:52 +00:00
|
|
|
window.modals.addUser = new Modal(document.getElementById('modal-add-user'));
|
|
|
|
(document.getElementById('accounts-add-user') as HTMLSpanElement).onclick = window.modals.addUser.toggle;
|
|
|
|
document.getElementById('form-add-user').addEventListener('submit', window.modals.addUser.close);
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2020-12-28 18:15:52 +00:00
|
|
|
window.modals.about = new Modal(document.getElementById('modal-about'));
|
|
|
|
(document.getElementById('setting-about') as HTMLSpanElement).onclick = window.modals.about.toggle;
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2020-12-28 18:15:52 +00:00
|
|
|
window.modals.modifyUser = new Modal(document.getElementById('modal-modify-user'));
|
|
|
|
document.getElementById('form-modify-user').addEventListener('submit', window.modals.modifyUser.close);
|
|
|
|
(document.getElementById('accounts-modify-user') as HTMLSpanElement).onclick = window.modals.modifyUser.toggle;
|
2020-12-23 01:34:22 +00:00
|
|
|
|
2020-12-28 18:15:52 +00:00
|
|
|
window.modals.deleteUser = new Modal(document.getElementById('modal-delete-user'));
|
|
|
|
document.getElementById('form-delete-user').addEventListener('submit', window.modals.deleteUser.close);
|
|
|
|
(document.getElementById('accounts-delete-user') as HTMLSpanElement).onclick = window.modals.deleteUser.toggle;
|
2020-12-23 01:34:22 +00:00
|
|
|
|
2020-12-28 18:15:52 +00:00
|
|
|
window.modals.settingsRestart = new Modal(document.getElementById('modal-restart'));
|
2020-12-23 01:34:22 +00:00
|
|
|
|
2020-12-28 18:15:52 +00:00
|
|
|
window.modals.settingsRefresh = new Modal(document.getElementById('modal-refresh'));
|
2020-12-23 01:34:22 +00:00
|
|
|
|
2020-12-28 18:15:52 +00:00
|
|
|
window.modals.ombiDefaults = new Modal(document.getElementById('modal-ombi-defaults'));
|
|
|
|
document.getElementById('form-ombi-defaults').addEventListener('submit', window.modals.ombiDefaults.close);
|