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-29 18:42:26 +00:00
|
|
|
import { Tabs } from "./modules/tabs.js";
|
2020-12-30 23:48:01 +00:00
|
|
|
import { inviteList, createInvite } from "./modules/invites.js";
|
2021-01-01 23:31:32 +00:00
|
|
|
import { accountsList } from "./modules/accounts.js";
|
2021-01-02 21:39:36 +00:00
|
|
|
import { settingsList } from "./modules/settings.js";
|
2021-01-04 01:02:47 +00:00
|
|
|
import { ProfileEditor } from "./modules/profiles.js";
|
2021-01-01 23:31:32 +00:00
|
|
|
import { _post, notificationBox, whichAnimationEvent, toggleLoader } from "./modules/common.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
|
|
|
window.animationEvent = whichAnimationEvent();
|
2020-12-30 18:31:38 +00:00
|
|
|
|
2020-12-30 23:48:01 +00:00
|
|
|
window.token = "";
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2020-12-30 23:48:01 +00:00
|
|
|
window.availableProfiles = window.availableProfiles || [];
|
2020-12-28 19:56:11 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
// load modals
|
|
|
|
(() => {
|
|
|
|
window.modals = {} as Modals;
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.modals.login = new Modal(document.getElementById('modal-login'), true);
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.modals.addUser = new Modal(document.getElementById('modal-add-user'));
|
2020-12-29 18:42:26 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.modals.about = new Modal(document.getElementById('modal-about'));
|
|
|
|
(document.getElementById('setting-about') as HTMLSpanElement).onclick = window.modals.about.toggle;
|
2020-12-29 18:42:26 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.modals.modifyUser = new Modal(document.getElementById('modal-modify-user'));
|
2020-12-29 18:42:26 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.modals.deleteUser = new Modal(document.getElementById('modal-delete-user'));
|
2020-12-29 18:42:26 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.modals.settingsRestart = new Modal(document.getElementById('modal-restart'));
|
2020-12-29 18:42:26 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.modals.settingsRefresh = new Modal(document.getElementById('modal-refresh'));
|
2020-12-29 18:42:26 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.modals.ombiDefaults = new Modal(document.getElementById('modal-ombi-defaults'));
|
|
|
|
document.getElementById('form-ombi-defaults').addEventListener('submit', window.modals.ombiDefaults.close);
|
2021-01-04 01:02:47 +00:00
|
|
|
|
|
|
|
window.modals.profiles = new Modal(document.getElementById("modal-user-profiles"));
|
|
|
|
|
|
|
|
window.modals.addProfile = new Modal(document.getElementById("modal-add-profile"));
|
2021-01-01 23:31:32 +00:00
|
|
|
})();
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
var inviteCreator = new createInvite();
|
|
|
|
var accounts = new accountsList();
|
|
|
|
|
|
|
|
window.invites = new inviteList();
|
|
|
|
|
2021-01-02 21:39:36 +00:00
|
|
|
var settings = new settingsList();
|
|
|
|
|
2021-01-04 01:02:47 +00:00
|
|
|
var profiles = new ProfileEditor();
|
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
window.notifications = new notificationBox(document.getElementById('notification-box') as HTMLDivElement, 5);
|
|
|
|
|
|
|
|
/*const modifySettingsSource = function () {
|
2020-12-23 01:34:22 +00:00
|
|
|
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');
|
2021-01-01 23:31:32 +00:00
|
|
|
}*/
|
2020-12-29 18:42:26 +00:00
|
|
|
|
|
|
|
// load tabs
|
|
|
|
window.tabs = new Tabs();
|
2021-01-02 21:39:36 +00:00
|
|
|
window.tabs.addTab("invitesTab");
|
2021-01-01 23:31:32 +00:00
|
|
|
window.tabs.addTab("accountsTab", null, accounts.reload);
|
2021-01-02 21:39:36 +00:00
|
|
|
window.tabs.addTab("settingsTab", null, settings.reload);
|
2020-12-20 22:49:54 +00:00
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
function login(username: string, password: string, run?: (state?: number) => void) {
|
2020-12-29 18:42:26 +00:00
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
req.responseType = 'json';
|
|
|
|
let url = window.URLBase;
|
|
|
|
const refresh = (username == "" && password == "");
|
|
|
|
if (refresh) {
|
|
|
|
url += "/token/refresh";
|
|
|
|
} else {
|
|
|
|
url += "/token/login";
|
|
|
|
}
|
|
|
|
req.open("GET", url, true);
|
|
|
|
if (!refresh) {
|
|
|
|
req.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
|
|
|
|
}
|
|
|
|
req.onreadystatechange = function (): void {
|
|
|
|
if (this.readyState == 4) {
|
|
|
|
if (this.status != 200) {
|
|
|
|
let errorMsg = "Connection error.";
|
|
|
|
if (this.response) {
|
|
|
|
errorMsg = this.response["error"];
|
|
|
|
}
|
|
|
|
if (!errorMsg) {
|
|
|
|
errorMsg = "Unknown error";
|
|
|
|
}
|
|
|
|
if (!refresh) {
|
2020-12-30 23:48:01 +00:00
|
|
|
window.notifications.customError("loginError", errorMsg);
|
2020-12-29 18:42:26 +00:00
|
|
|
} else {
|
|
|
|
window.modals.login.show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const data = this.response;
|
|
|
|
window.token = data["token"];
|
|
|
|
window.modals.login.close();
|
2020-12-30 15:32:44 +00:00
|
|
|
window.invites.reload();
|
2021-01-01 23:31:32 +00:00
|
|
|
accounts.reload();
|
|
|
|
setInterval(() => { window.invites.reload(); accounts.reload(); }, 30*1000);
|
2020-12-30 23:48:01 +00:00
|
|
|
document.getElementById("logout-button").classList.remove("unfocused");
|
2020-12-29 18:42:26 +00:00
|
|
|
}
|
2021-01-01 23:31:32 +00:00
|
|
|
if (run) { run(+this.status); }
|
2020-12-29 18:42:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
req.send();
|
|
|
|
}
|
|
|
|
|
2021-01-01 23:31:32 +00:00
|
|
|
(document.getElementById('form-login') as HTMLFormElement).onsubmit = (event: SubmitEvent) => {
|
2020-12-29 18:42:26 +00:00
|
|
|
event.preventDefault();
|
2021-01-01 23:31:32 +00:00
|
|
|
const button = (event.target as HTMLElement).querySelector(".submit") as HTMLSpanElement;
|
2020-12-29 18:42:26 +00:00
|
|
|
const username = (document.getElementById("login-user") as HTMLInputElement).value;
|
|
|
|
const password = (document.getElementById("login-password") as HTMLInputElement).value;
|
|
|
|
if (!username || !password) {
|
2020-12-30 23:48:01 +00:00
|
|
|
window.notifications.customError("loginError", "The username and/or password were left blank.");
|
2020-12-29 18:42:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-01-01 23:31:32 +00:00
|
|
|
toggleLoader(button);
|
|
|
|
login(username, password, () => toggleLoader(button));
|
|
|
|
};
|
2020-12-23 01:34:22 +00:00
|
|
|
|
2020-12-29 18:42:26 +00:00
|
|
|
login("", "");
|
2020-12-30 15:32:44 +00:00
|
|
|
|
2020-12-30 23:48:01 +00:00
|
|
|
(document.getElementById('logout-button') as HTMLButtonElement).onclick = () => _post("/logout", null, (req: XMLHttpRequest): boolean => {
|
|
|
|
if (req.readyState == 4 && req.status == 200) {
|
|
|
|
window.token = "";
|
|
|
|
location.reload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2021-01-01 23:31:32 +00:00
|
|
|
|