|
|
@ -1,15 +1,22 @@
|
|
|
|
var config: Object = {};
|
|
|
|
var config: Object = {};
|
|
|
|
var modifiedConfig: Object = {};
|
|
|
|
var modifiedConfig: Object = {};
|
|
|
|
|
|
|
|
|
|
|
|
function sendConfig(modalID: string, restart?: boolean): void {
|
|
|
|
function sendConfig(restart?: boolean): void {
|
|
|
|
modifiedConfig["restart-program"] = restart;
|
|
|
|
modifiedConfig["restart-program"] = restart;
|
|
|
|
_post("/modifyConfig", modifiedConfig, function (): void {
|
|
|
|
_post("/modifyConfig", modifiedConfig, function (): void {
|
|
|
|
if (this.readyState == 4) {
|
|
|
|
if (this.readyState == 4) {
|
|
|
|
|
|
|
|
const save = document.getElementById("settingsSave") as HTMLButtonElement
|
|
|
|
if (this.status == 200 || this.status == 204) {
|
|
|
|
if (this.status == 200 || this.status == 204) {
|
|
|
|
createModal(modalID, true).hide();
|
|
|
|
save.textContent = "Success";
|
|
|
|
if (modalID != "settingsMenu") {
|
|
|
|
addAttr(save, "btn-success");
|
|
|
|
settingsModal.hide();
|
|
|
|
rmAttr(save, "btn-primary");
|
|
|
|
}
|
|
|
|
setTimeout((): void => {
|
|
|
|
|
|
|
|
save.textContent = "Save";
|
|
|
|
|
|
|
|
addAttr(save, "btn-primary");
|
|
|
|
|
|
|
|
rmAttr(save, "btn-success");
|
|
|
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
save.textContent = "Save";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (restart) {
|
|
|
|
if (restart) {
|
|
|
|
refreshModal.show();
|
|
|
|
refreshModal.show();
|
|
|
@ -46,7 +53,6 @@ function sendConfig(modalID: string, restart?: boolean): void {
|
|
|
|
document.getElementById('defaultsSourceSection').classList.add('unfocused');
|
|
|
|
document.getElementById('defaultsSourceSection').classList.add('unfocused');
|
|
|
|
(document.getElementById('storeDefaults') as HTMLButtonElement).onclick = (): void => storeDefaults('all');
|
|
|
|
(document.getElementById('storeDefaults') as HTMLButtonElement).onclick = (): void => storeDefaults('all');
|
|
|
|
Focus(document.getElementById('defaultUserRadios'));
|
|
|
|
Focus(document.getElementById('defaultUserRadios'));
|
|
|
|
settingsModal.hide();
|
|
|
|
|
|
|
|
userDefaultsModal.show();
|
|
|
|
userDefaultsModal.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -54,19 +60,17 @@ function sendConfig(modalID: string, restart?: boolean): void {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
(document.getElementById('openAbout') as HTMLButtonElement).onclick = (): void => {
|
|
|
|
(document.getElementById('openAbout') as HTMLButtonElement).onclick = (): void => {
|
|
|
|
settingsModal.hide();
|
|
|
|
|
|
|
|
aboutModal.show();
|
|
|
|
aboutModal.show();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
(document.getElementById('openSettings') as HTMLButtonElement).onclick = (): void => _get("/getConfig", null, function (): void {
|
|
|
|
const openSettings = (settingsList: HTMLElement, settingsContent: HTMLElement, callback?: () => void): void => _get("/getConfig", null, function (): void {
|
|
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
|
|
const settingsList = document.getElementById('settingsList');
|
|
|
|
|
|
|
|
settingsList.textContent = '';
|
|
|
|
settingsList.textContent = '';
|
|
|
|
config = this.response;
|
|
|
|
config = this.response;
|
|
|
|
for (const i in config["order"]) {
|
|
|
|
for (const i in config["order"]) {
|
|
|
|
const section: string = config["order"][i]
|
|
|
|
const section: string = config["order"][i]
|
|
|
|
const sectionCollapse = document.createElement('div') as HTMLDivElement;
|
|
|
|
const sectionCollapse = document.createElement('div') as HTMLDivElement;
|
|
|
|
addAttr(sectionCollapse, "collapse");
|
|
|
|
Unfocus(sectionCollapse);
|
|
|
|
sectionCollapse.id = section;
|
|
|
|
sectionCollapse.id = section;
|
|
|
|
|
|
|
|
|
|
|
|
const title: string = config[section]["meta"]["name"];
|
|
|
|
const title: string = config[section]["meta"]["name"];
|
|
|
@ -151,16 +155,42 @@ function sendConfig(modalID: string, restart?: boolean): void {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
settingsList.innerHTML += `
|
|
|
|
settingsList.innerHTML += `
|
|
|
|
<button type="button" class="list-group-item list-group-item-action" id="${section}_button" data-toggle="collapse" data-target="#${section}">${title}</button>
|
|
|
|
<button type="button" class="list-group-item list-group-item-action" id="${section}_button" onclick="showSetting('${section}')">${title}</button>
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
settingsList.appendChild(sectionCollapse);
|
|
|
|
settingsContent.appendChild(sectionCollapse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settingsModal.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function showSetting(id: string): void {
|
|
|
|
|
|
|
|
const els = document.getElementById('settingsSections').querySelectorAll("button[type=button]") as NodeListOf<HTMLButtonElement>;
|
|
|
|
|
|
|
|
for (let i = 0; i < els.length; i++) {
|
|
|
|
|
|
|
|
const el = els[i];
|
|
|
|
|
|
|
|
if (el.id != `${id}_button`) {
|
|
|
|
|
|
|
|
rmAttr(el, "active");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const sectEl = document.getElementById(el.id.replace("_button", ""));
|
|
|
|
|
|
|
|
if (sectEl.id != id) {
|
|
|
|
|
|
|
|
Unfocus(sectEl);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addAttr(document.getElementById(`${id}_button`), "active");
|
|
|
|
|
|
|
|
const section = document.getElementById(id);
|
|
|
|
|
|
|
|
Focus(section);
|
|
|
|
|
|
|
|
if (screen.width <= 1100) {
|
|
|
|
|
|
|
|
// ugly
|
|
|
|
|
|
|
|
setTimeout((): void => section.scrollIntoView(<ScrollIntoViewOptions>{ block: "center", behavior: "smooth" }), 200);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// (document.getElementById('openSettings') as HTMLButtonElement).onclick = (): void => openSettings(document.getElementById('settingsList'), document.getElementById('settingsList'), (): void => settingsModal.show());
|
|
|
|
|
|
|
|
|
|
|
|
(document.getElementById('settingsSave') as HTMLButtonElement).onclick = function (): void {
|
|
|
|
(document.getElementById('settingsSave') as HTMLButtonElement).onclick = function (): void {
|
|
|
|
modifiedConfig = {};
|
|
|
|
modifiedConfig = {};
|
|
|
|
|
|
|
|
const save = this as HTMLButtonElement;
|
|
|
|
let restartSettingsChanged = false;
|
|
|
|
let restartSettingsChanged = false;
|
|
|
|
let settingsChanged = false;
|
|
|
|
let settingsChanged = false;
|
|
|
|
for (const i in config["order"]) {
|
|
|
|
for (const i in config["order"]) {
|
|
|
@ -178,7 +208,7 @@ function sendConfig(modalID: string, restart?: boolean): void {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
val = el.value.toString();
|
|
|
|
val = el.value.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (val != config[section][entry]["value"]) {
|
|
|
|
if (val != config[section][entry]["value"].toString()) {
|
|
|
|
if (!(section in modifiedConfig)) {
|
|
|
|
if (!(section in modifiedConfig)) {
|
|
|
|
modifiedConfig[section] = {};
|
|
|
|
modifiedConfig[section] = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -190,17 +220,23 @@ function sendConfig(modalID: string, restart?: boolean): void {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const spinnerHTML = `
|
|
|
|
|
|
|
|
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>
|
|
|
|
|
|
|
|
Loading...`;
|
|
|
|
if (restartSettingsChanged) {
|
|
|
|
if (restartSettingsChanged) {
|
|
|
|
(document.getElementById('applyRestarts') as HTMLButtonElement).onclick = (): void => sendConfig("restartModal");
|
|
|
|
save.innerHTML = spinnerHTML;
|
|
|
|
|
|
|
|
(document.getElementById('applyRestarts') as HTMLButtonElement).onclick = (): void => sendConfig();
|
|
|
|
const restartButton = document.getElementById('applyAndRestart') as HTMLButtonElement;
|
|
|
|
const restartButton = document.getElementById('applyAndRestart') as HTMLButtonElement;
|
|
|
|
if (restartButton) {
|
|
|
|
if (restartButton) {
|
|
|
|
restartButton.onclick = (): void => sendConfig("restartModal", true);
|
|
|
|
restartButton.onclick = (): void => sendConfig(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settingsModal.hide();
|
|
|
|
|
|
|
|
restartModal.show();
|
|
|
|
restartModal.show();
|
|
|
|
} else if (settingsChanged) {
|
|
|
|
} else if (settingsChanged) {
|
|
|
|
sendConfig("settingsMenu");
|
|
|
|
save.innerHTML = spinnerHTML;
|
|
|
|
} else {
|
|
|
|
sendConfig();
|
|
|
|
settingsModal.hide();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(document.getElementById('restartModalCancel') as HTMLButtonElement).onclick = (): void => {
|
|
|
|
|
|
|
|
document.getElementById('settingsSave').textContent = "Save";
|
|
|
|
|
|
|
|
};
|
|
|
|