2023-06-16 12:43:34 +00:00
|
|
|
import { ThemeManager } from "./modules/theme.js";
|
2021-01-12 23:43:44 +00:00
|
|
|
import { lang, LangFile, loadLangSelector } from "./modules/lang.js";
|
2021-01-05 18:16:23 +00:00
|
|
|
import { Modal } from "./modules/modal.js";
|
|
|
|
import { Tabs } from "./modules/tabs.js";
|
|
|
|
import { inviteList, createInvite } from "./modules/invites.js";
|
|
|
|
import { accountsList } from "./modules/accounts.js";
|
|
|
|
import { settingsList } from "./modules/settings.js";
|
|
|
|
import { ProfileEditor } from "./modules/profiles.js";
|
2023-06-15 22:52:16 +00:00
|
|
|
import { _get, _post, notificationBox, whichAnimationEvent } from "./modules/common.js";
|
2021-03-07 15:23:44 +00:00
|
|
|
import { Updater } from "./modules/update.js";
|
2023-06-15 22:52:16 +00:00
|
|
|
import { Login } from "./modules/login.js";
|
2020-09-21 21:03:20 +00:00
|
|
|
|
2023-06-16 12:43:34 +00:00
|
|
|
const theme = new ThemeManager(document.getElementById("button-theme"));
|
2020-09-21 21:03:20 +00:00
|
|
|
|
2021-01-12 23:15:12 +00:00
|
|
|
window.lang = new lang(window.langFile as LangFile);
|
2021-01-12 23:43:44 +00:00
|
|
|
loadLangSelector("admin");
|
2021-01-12 23:15:12 +00:00
|
|
|
// _get(`/lang/admin/${window.language}.json`, null, (req: XMLHttpRequest) => {
|
|
|
|
// if (req.readyState == 4 && req.status == 200) {
|
|
|
|
// langLoaded = true;
|
|
|
|
// window.lang = new lang(req.response as LangFile);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
window.animationEvent = whichAnimationEvent();
|
2020-09-21 21:03:20 +00:00
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
window.token = "";
|
2020-09-21 21:03:20 +00:00
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
window.availableProfiles = window.availableProfiles || [];
|
2020-10-22 16:50:40 +00:00
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
// load modals
|
|
|
|
(() => {
|
|
|
|
window.modals = {} as Modals;
|
|
|
|
|
|
|
|
window.modals.login = new Modal(document.getElementById('modal-login'), true);
|
|
|
|
|
|
|
|
window.modals.addUser = new Modal(document.getElementById('modal-add-user'));
|
|
|
|
|
|
|
|
window.modals.about = new Modal(document.getElementById('modal-about'));
|
|
|
|
(document.getElementById('setting-about') as HTMLSpanElement).onclick = window.modals.about.toggle;
|
|
|
|
|
|
|
|
window.modals.modifyUser = new Modal(document.getElementById('modal-modify-user'));
|
|
|
|
|
|
|
|
window.modals.deleteUser = new Modal(document.getElementById('modal-delete-user'));
|
|
|
|
|
|
|
|
window.modals.settingsRestart = new Modal(document.getElementById('modal-restart'));
|
|
|
|
|
|
|
|
window.modals.settingsRefresh = new Modal(document.getElementById('modal-refresh'));
|
|
|
|
|
2021-11-13 18:53:53 +00:00
|
|
|
window.modals.ombiProfile = new Modal(document.getElementById('modal-ombi-profile'));
|
|
|
|
document.getElementById('form-ombi-defaults').addEventListener('submit', window.modals.ombiProfile.close);
|
2021-01-05 18:16:23 +00:00
|
|
|
|
|
|
|
window.modals.profiles = new Modal(document.getElementById("modal-user-profiles"));
|
|
|
|
|
|
|
|
window.modals.addProfile = new Modal(document.getElementById("modal-add-profile"));
|
2021-02-18 14:58:53 +00:00
|
|
|
|
|
|
|
window.modals.announce = new Modal(document.getElementById("modal-announce"));
|
2021-02-20 22:49:59 +00:00
|
|
|
|
|
|
|
window.modals.editor = new Modal(document.getElementById("modal-editor"));
|
2021-02-21 15:51:42 +00:00
|
|
|
|
|
|
|
window.modals.customizeEmails = new Modal(document.getElementById("modal-customize"));
|
2021-02-28 17:52:24 +00:00
|
|
|
|
|
|
|
window.modals.extendExpiry = new Modal(document.getElementById("modal-extend-expiry"));
|
2021-03-07 15:23:44 +00:00
|
|
|
|
|
|
|
window.modals.updateInfo = new Modal(document.getElementById("modal-update"));
|
2021-05-07 17:20:35 +00:00
|
|
|
|
2021-05-30 21:35:34 +00:00
|
|
|
window.modals.matrix = new Modal(document.getElementById("modal-matrix"));
|
|
|
|
|
2021-12-30 17:54:27 +00:00
|
|
|
window.modals.logs = new Modal(document.getElementById("modal-logs"));
|
|
|
|
|
2021-05-07 17:20:35 +00:00
|
|
|
if (window.telegramEnabled) {
|
|
|
|
window.modals.telegram = new Modal(document.getElementById("modal-telegram"));
|
|
|
|
}
|
2021-05-22 20:42:15 +00:00
|
|
|
|
|
|
|
if (window.discordEnabled) {
|
|
|
|
window.modals.discord = new Modal(document.getElementById("modal-discord"));
|
|
|
|
}
|
2021-10-13 14:04:22 +00:00
|
|
|
|
|
|
|
if (window.linkResetEnabled) {
|
|
|
|
window.modals.sendPWR = new Modal(document.getElementById("modal-send-pwr"));
|
|
|
|
}
|
2023-06-28 15:05:24 +00:00
|
|
|
|
|
|
|
if (window.referralsEnabled) {
|
|
|
|
window.modals.enableReferralsUser = new Modal(document.getElementById("modal-enable-referrals-user"));
|
2023-09-06 21:00:44 +00:00
|
|
|
window.modals.enableReferralsProfile = new Modal(document.getElementById("modal-enable-referrals-profile"));
|
2023-06-28 15:05:24 +00:00
|
|
|
}
|
2021-01-05 18:16:23 +00:00
|
|
|
})();
|
2020-10-22 16:50:40 +00:00
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
var inviteCreator = new createInvite();
|
2021-03-07 15:23:44 +00:00
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
var accounts = new accountsList();
|
|
|
|
|
|
|
|
window.invites = new inviteList();
|
|
|
|
|
|
|
|
var settings = new settingsList();
|
|
|
|
|
|
|
|
var profiles = new ProfileEditor();
|
|
|
|
|
|
|
|
window.notifications = new notificationBox(document.getElementById('notification-box') as HTMLDivElement, 5);
|
|
|
|
|
|
|
|
/*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;
|
2021-12-30 00:49:43 +00:00
|
|
|
(user.nextElementSibling as HTMLSpanElement).classList.toggle('@low');
|
|
|
|
(user.nextElementSibling as HTMLSpanElement).classList.toggle('@high');
|
|
|
|
(profile.nextElementSibling as HTMLSpanElement).classList.toggle('@low');
|
|
|
|
(profile.nextElementSibling as HTMLSpanElement).classList.toggle('@high');
|
2021-01-05 18:16:23 +00:00
|
|
|
profileSelect.classList.toggle('unfocused');
|
|
|
|
userSelect.classList.toggle('unfocused');
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// load tabs
|
2023-06-16 12:43:34 +00:00
|
|
|
const tabs: { url: string, reloader: () => void }[] = [
|
|
|
|
{
|
|
|
|
url: "invites",
|
|
|
|
reloader: window.invites.reload
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: "accounts",
|
|
|
|
reloader: accounts.reload
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: "settings",
|
|
|
|
reloader: settings.reload
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const defaultTab = tabs[0];
|
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
window.tabs = new Tabs();
|
|
|
|
|
2023-06-16 12:43:34 +00:00
|
|
|
for (let tab of tabs) {
|
|
|
|
window.tabs.addTab(tab.url, null, tab.reloader);
|
|
|
|
if (window.location.pathname == window.URLBase + "/" + tab.url) {
|
|
|
|
window.tabs.switch(tab.url, true);
|
2021-01-05 18:16:23 +00:00
|
|
|
}
|
2020-09-21 21:03:20 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 12:43:34 +00:00
|
|
|
// Default tab
|
2021-02-09 20:45:35 +00:00
|
|
|
if ((window.URLBase + "/").includes(window.location.pathname)) {
|
2023-06-16 12:43:34 +00:00
|
|
|
window.tabs.switch(defaultTab.url, true);
|
2020-09-21 21:03:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 18:16:23 +00:00
|
|
|
document.addEventListener("tab-change", (event: CustomEvent) => {
|
2021-01-15 21:16:11 +00:00
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const lang = urlParams.get('lang');
|
2021-02-05 13:31:56 +00:00
|
|
|
let tab = window.URLBase + "/" + event.detail;
|
|
|
|
if (tab == window.URLBase + "/invites") {
|
|
|
|
if (window.location.pathname == window.URLBase + "/") {
|
|
|
|
tab = window.URLBase + "/";
|
|
|
|
} else if (window.URLBase) { tab = window.URLBase; }
|
|
|
|
else { tab = "../"; }
|
2020-09-21 21:03:20 +00:00
|
|
|
}
|
2021-01-15 21:16:11 +00:00
|
|
|
if (lang) {
|
|
|
|
tab += "?lang=" + lang
|
|
|
|
}
|
2021-01-31 17:32:03 +00:00
|
|
|
window.history.pushState(event.detail, "Admin - jfa-go", tab);
|
2021-01-05 18:16:23 +00:00
|
|
|
});
|
2020-09-21 21:03:20 +00:00
|
|
|
|
2021-01-31 17:32:03 +00:00
|
|
|
window.onpopstate = (event: PopStateEvent) => {
|
|
|
|
console.log(event.state);
|
|
|
|
window.tabs.switch(event.state);
|
|
|
|
}
|
|
|
|
|
2023-06-15 22:52:16 +00:00
|
|
|
const login = new Login(window.modals.login as Modal, "/");
|
|
|
|
login.onLogin = () => {
|
2023-06-16 13:43:37 +00:00
|
|
|
console.log("Logged in.");
|
2023-06-15 22:52:16 +00:00
|
|
|
window.updater = new Updater();
|
|
|
|
setInterval(() => { window.invites.reload(); accounts.reload(); }, 30*1000);
|
|
|
|
const currentTab = window.tabs.current;
|
|
|
|
switch (currentTab) {
|
|
|
|
case "invites":
|
|
|
|
window.invites.reload();
|
|
|
|
break;
|
|
|
|
case "accounts":
|
|
|
|
accounts.reload();
|
|
|
|
break;
|
|
|
|
case "settings":
|
|
|
|
settings.reload();
|
|
|
|
break;
|
2020-11-12 21:04:35 +00:00
|
|
|
}
|
2020-09-21 21:03:20 +00:00
|
|
|
}
|
|
|
|
|
2023-06-17 16:26:36 +00:00
|
|
|
login.bindLogout(document.getElementById("logout-button"));
|
2020-09-21 21:03:20 +00:00
|
|
|
|
2023-06-17 16:26:36 +00:00
|
|
|
login.login("", "");
|