mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 17:10:10 +00:00
rename routes to make more sense
for example, /getInvite and /generateInvite become GET(/invites) and POST(/invites) respectively.
This commit is contained in:
parent
ce844e0574
commit
544f5674e8
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@ scss/bs5/*.css*
|
|||||||
data/static/*.css
|
data/static/*.css
|
||||||
data/static/*.js
|
data/static/*.js
|
||||||
data/static/*.js.map
|
data/static/*.js.map
|
||||||
|
data/static/ts/
|
||||||
!data/static/setup.js
|
!data/static/setup.js
|
||||||
data/config-base.json
|
data/config-base.json
|
||||||
data/config-default.ini
|
data/config-default.ini
|
||||||
|
@ -133,7 +133,7 @@ document.getElementById('jfTestButton').onclick = function() {
|
|||||||
nextButton.classList.add('disabled');
|
nextButton.classList.add('disabled');
|
||||||
nextButton.setAttribute('aria-disabled', 'true');
|
nextButton.setAttribute('aria-disabled', 'true');
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.open("POST", "/testJF", true);
|
req.open("POST", "/jellyfin/test", true);
|
||||||
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
req.responseType = 'json';
|
req.responseType = 'json';
|
||||||
req.onreadystatechange = function() {
|
req.onreadystatechange = function() {
|
||||||
@ -260,7 +260,7 @@ document.getElementById('submitButton').onclick = function() {
|
|||||||
// Send it
|
// Send it
|
||||||
config["restart-program"] = true;
|
config["restart-program"] = true;
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.open("POST", "/modifyConfig", true);
|
req.open("POST", "/config", true);
|
||||||
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
req.responseType = 'json';
|
req.responseType = 'json';
|
||||||
req.onreadystatechange = function() {
|
req.onreadystatechange = function() {
|
||||||
|
@ -1,348 +0,0 @@
|
|||||||
const checkCheckboxes = (): void => {
|
|
||||||
const defaultsButton = document.getElementById('accountsTabSetDefaults');
|
|
||||||
const deleteButton = document.getElementById('accountsTabDelete');
|
|
||||||
const checkboxes: NodeListOf<HTMLInputElement> = document.getElementById('accountsList').querySelectorAll('input[type=checkbox]:checked');
|
|
||||||
let checked = checkboxes.length;
|
|
||||||
if (checked == 0) {
|
|
||||||
Unfocus(defaultsButton);
|
|
||||||
Unfocus(deleteButton);
|
|
||||||
} else {
|
|
||||||
Focus(defaultsButton);
|
|
||||||
Focus(deleteButton);
|
|
||||||
if (checked == 1) {
|
|
||||||
deleteButton.textContent = 'Delete User';
|
|
||||||
} else {
|
|
||||||
deleteButton.textContent = 'Delete Users';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const validateEmail = (email: string): boolean => /\S+@\S+\.\S+/.test(email);
|
|
||||||
|
|
||||||
function changeEmail(icon: HTMLElement, id: string): void {
|
|
||||||
const iconContent = icon.outerHTML;
|
|
||||||
icon.setAttribute('class', '');
|
|
||||||
const entry = icon.nextElementSibling as HTMLInputElement;
|
|
||||||
const ogEmail = entry.value;
|
|
||||||
entry.readOnly = false;
|
|
||||||
entry.classList.remove('form-control-plaintext');
|
|
||||||
entry.classList.add('form-control');
|
|
||||||
if (ogEmail == "") {
|
|
||||||
entry.placeholder = 'Address';
|
|
||||||
}
|
|
||||||
const tick = createEl(`
|
|
||||||
<i class="fa fa-check d-inline-block icon-button text-success" style="margin-left: 0.5rem; margin-right: 0.5rem;"></i>
|
|
||||||
`);
|
|
||||||
tick.onclick = (): void => {
|
|
||||||
const newEmail = entry.value;
|
|
||||||
if (!validateEmail(newEmail) || newEmail == ogEmail) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cross.remove();
|
|
||||||
const spinner = createEl(`
|
|
||||||
<div class="spinner-border spinner-border-sm" role="status" style="width: 1rem; height: 1rem; margin-left: 0.5rem;">
|
|
||||||
<span class="sr-only">Saving...</span>
|
|
||||||
</div>
|
|
||||||
`);
|
|
||||||
tick.replaceWith(spinner);
|
|
||||||
let send = {};
|
|
||||||
send[id] = newEmail;
|
|
||||||
_post("/modifyEmails", send, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
if (this.status == 200 || this.status == 204) {
|
|
||||||
entry.nextElementSibling.remove();
|
|
||||||
} else {
|
|
||||||
entry.value = ogEmail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
icon.outerHTML = iconContent;
|
|
||||||
entry.readOnly = true;
|
|
||||||
entry.classList.remove('form-control');
|
|
||||||
entry.classList.add('form-control-plaintext');
|
|
||||||
entry.placeholder = '';
|
|
||||||
};
|
|
||||||
const cross = createEl(`
|
|
||||||
<i class="fa fa-close d-inline-block icon-button text-danger"></i>
|
|
||||||
`);
|
|
||||||
cross.onclick = (): void => {
|
|
||||||
tick.remove();
|
|
||||||
cross.remove();
|
|
||||||
icon.outerHTML = iconContent;
|
|
||||||
entry.readOnly = true;
|
|
||||||
entry.classList.remove('form-control');
|
|
||||||
entry.classList.add('form-control-plaintext');
|
|
||||||
entry.placeholder = '';
|
|
||||||
entry.value = ogEmail;
|
|
||||||
};
|
|
||||||
icon.parentNode.appendChild(tick);
|
|
||||||
icon.parentNode.appendChild(cross);
|
|
||||||
};
|
|
||||||
|
|
||||||
var jfUsers: Array<Object>;
|
|
||||||
|
|
||||||
function populateUsers(): void {
|
|
||||||
const acList = document.getElementById('accountsList');
|
|
||||||
acList.innerHTML = `
|
|
||||||
<div class="d-flex align-items-center">
|
|
||||||
<strong>Getting Users...</strong>
|
|
||||||
<div class="spinner-border ml-auto" role="status" aria-hidden="true"></div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
Unfocus(acList.parentNode.querySelector('thead'));
|
|
||||||
const accountsList = document.createElement('tbody');
|
|
||||||
accountsList.id = 'accountsList';
|
|
||||||
const generateEmail = (id: string, name: string, email: string): string => {
|
|
||||||
let entry: HTMLDivElement = document.createElement('div');
|
|
||||||
entry.id = 'email_' + id;
|
|
||||||
let emailValue: string = email;
|
|
||||||
if (emailValue == undefined) {
|
|
||||||
emailValue = "";
|
|
||||||
}
|
|
||||||
entry.innerHTML = `
|
|
||||||
<i class="fa fa-edit d-inline-block icon-button" style="margin-right: 2%;" onclick="changeEmail(this, '${id}')"></i>
|
|
||||||
<input type="email" class="form-control-plaintext form-control-sm text-muted d-inline-block addressText" id="address_${id}" style="width: auto;" value="${emailValue}" readonly>
|
|
||||||
`;
|
|
||||||
return entry.outerHTML;
|
|
||||||
};
|
|
||||||
const template = (id: string, username: string, email: string, lastActive: string, admin: boolean): string => {
|
|
||||||
let isAdmin = "No";
|
|
||||||
if (admin) {
|
|
||||||
isAdmin = "Yes";
|
|
||||||
}
|
|
||||||
let fci = "form-check-input";
|
|
||||||
if (bsVersion != 5) {
|
|
||||||
fci = "";
|
|
||||||
}
|
|
||||||
return `
|
|
||||||
<td nowrap="nowrap" class="align-middle" scope="row"><input class="${fci}" type="checkbox" value="" id="select_${id}" onclick="checkCheckboxes();"></td>
|
|
||||||
<td nowrap="nowrap" class="align-middle">${username}</td>
|
|
||||||
<td nowrap="nowrap" class="align-middle">${generateEmail(id, name, email)}</td>
|
|
||||||
<td nowrap="nowrap" class="align-middle">${lastActive}</td>
|
|
||||||
<td nowrap="nowrap" class="align-middle">${isAdmin}</td>
|
|
||||||
`;
|
|
||||||
};
|
|
||||||
|
|
||||||
_get("/getUsers", null, function (): void {
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
|
||||||
jfUsers = this.response['users'];
|
|
||||||
for (const user of jfUsers) {
|
|
||||||
let tr = document.createElement('tr');
|
|
||||||
tr.innerHTML = template(user['id'], user['name'], user['email'], user['last_active'], user['admin']);
|
|
||||||
accountsList.appendChild(tr);
|
|
||||||
}
|
|
||||||
Focus(acList.parentNode.querySelector('thead'));
|
|
||||||
acList.replaceWith(accountsList);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function populateRadios(): void {
|
|
||||||
const radioList = document.getElementById('defaultUserRadios');
|
|
||||||
radioList.textContent = '';
|
|
||||||
let first = true;
|
|
||||||
for (const i in jfUsers) {
|
|
||||||
const user = jfUsers[i];
|
|
||||||
const radio = document.createElement('div');
|
|
||||||
radio.classList.add('form-check');
|
|
||||||
let checked = '';
|
|
||||||
if (first) {
|
|
||||||
checked = 'checked';
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
radio.innerHTML = `
|
|
||||||
<input class="form-check-input" type="radio" name="defaultRadios" id="default_${user['id']}" ${checked}>
|
|
||||||
<label class="form-check-label" for="default_${user['id']}">${user['name']}</label>`;
|
|
||||||
radioList.appendChild(radio);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(<HTMLInputElement>document.getElementById('selectAll')).onclick = function (): void {
|
|
||||||
const checkboxes: NodeListOf<HTMLInputElement> = document.getElementById('accountsList').querySelectorAll('input[type=checkbox]');
|
|
||||||
for (let i = 0; i < checkboxes.length; i++) {
|
|
||||||
checkboxes[i].checked = (<HTMLInputElement>this).checked;
|
|
||||||
}
|
|
||||||
checkCheckboxes();
|
|
||||||
};
|
|
||||||
|
|
||||||
(<HTMLInputElement>document.getElementById('deleteModalNotify')).onclick = function (): void {
|
|
||||||
const textbox: HTMLElement = document.getElementById('deleteModalReasonBox');
|
|
||||||
if ((<HTMLInputElement>this).checked) {
|
|
||||||
Focus(textbox);
|
|
||||||
} else {
|
|
||||||
Unfocus(textbox);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
(<HTMLButtonElement>document.getElementById('accountsTabDelete')).onclick = function (): void {
|
|
||||||
const deleteButton = this as HTMLButtonElement;
|
|
||||||
const checkboxes: NodeListOf<HTMLInputElement> = document.getElementById('accountsList').querySelectorAll('input[type=checkbox]:checked');
|
|
||||||
let selected: Array<string> = new Array(checkboxes.length);
|
|
||||||
for (let i = 0; i < checkboxes.length; i++) {
|
|
||||||
selected[i] = checkboxes[i].id.replace("select_", "");
|
|
||||||
}
|
|
||||||
let title = " user";
|
|
||||||
let msg = "Notify user";
|
|
||||||
if (selected.length > 1) {
|
|
||||||
title += "s";
|
|
||||||
msg += "s";
|
|
||||||
}
|
|
||||||
title = `Delete ${selected.length} ${title}`;
|
|
||||||
msg += " of account deletion";
|
|
||||||
|
|
||||||
document.getElementById('deleteModalTitle').textContent = title;
|
|
||||||
const dmNotify = document.getElementById('deleteModalNotify') as HTMLInputElement;
|
|
||||||
dmNotify.checked = false;
|
|
||||||
document.getElementById('deleteModalNotifyLabel').textContent = msg;
|
|
||||||
const dmReason = document.getElementById('deleteModalReason') as HTMLTextAreaElement;
|
|
||||||
dmReason.value = '';
|
|
||||||
Unfocus(document.getElementById('deleteModalReasonBox'));
|
|
||||||
const dmSend = document.getElementById('deleteModalSend') as HTMLButtonElement;
|
|
||||||
dmSend.textContent = 'Delete';
|
|
||||||
dmSend.onclick = function (): void {
|
|
||||||
const button = this as HTMLButtonElement;
|
|
||||||
const send = {
|
|
||||||
'users': selected,
|
|
||||||
'notify': dmNotify.checked,
|
|
||||||
'reason': dmReason.value
|
|
||||||
};
|
|
||||||
_post("/deleteUser", send, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
if (this.status == 500) {
|
|
||||||
if ("error" in this.reponse) {
|
|
||||||
button.textContent = 'Failed';
|
|
||||||
} else {
|
|
||||||
button.textContent = 'Partial fail (check console)';
|
|
||||||
console.log(this.response);
|
|
||||||
}
|
|
||||||
setTimeout((): void => {
|
|
||||||
Unfocus(deleteButton);
|
|
||||||
deleteModal.hide();
|
|
||||||
}, 4000);
|
|
||||||
} else {
|
|
||||||
Unfocus(deleteButton);
|
|
||||||
deleteModal.hide()
|
|
||||||
}
|
|
||||||
populateUsers();
|
|
||||||
checkCheckboxes();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
deleteModal.show();
|
|
||||||
};
|
|
||||||
|
|
||||||
(<HTMLInputElement>document.getElementById('selectAll')).checked = false;
|
|
||||||
|
|
||||||
(<HTMLButtonElement>document.getElementById('accountsTabSetDefaults')).onclick = function (): void {
|
|
||||||
const checkboxes: NodeListOf<HTMLInputElement> = document.getElementById('accountsList').querySelectorAll('input[type=checkbox]:checked');
|
|
||||||
let userIDs: Array<string> = new Array(checkboxes.length);
|
|
||||||
for (let i = 0; i < checkboxes.length; i++){
|
|
||||||
userIDs[i] = checkboxes[i].id.replace("select_", "");
|
|
||||||
}
|
|
||||||
if (userIDs.length == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
populateRadios();
|
|
||||||
let userString = 'user';
|
|
||||||
if (userIDs.length > 1) {
|
|
||||||
userString += "s";
|
|
||||||
}
|
|
||||||
populateProfiles(true);
|
|
||||||
const profileSelect = document.getElementById('profileSelect') as HTMLSelectElement;
|
|
||||||
profileSelect.textContent = '';
|
|
||||||
for (let i = 0; i < availableProfiles.length; i++) {
|
|
||||||
profileSelect.innerHTML += `
|
|
||||||
<option value="${availableProfiles[i]}" ${(i == 0) ? "selected" : ""}>${availableProfiles[i]}</option>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
document.getElementById('defaultsTitle').textContent = `Apply settings to ${userIDs.length} ${userString}`;
|
|
||||||
document.getElementById('userDefaultsDescription').textContent = `
|
|
||||||
Apply settings from an existing profile or source settings from a user.
|
|
||||||
`;
|
|
||||||
document.getElementById('storeHomescreenLabel').textContent = `Apply homescreen layout`;
|
|
||||||
Focus(document.getElementById('defaultsSourceSection'));
|
|
||||||
(<HTMLSelectElement>document.getElementById('defaultsSource')).value = 'profile';
|
|
||||||
Focus(document.getElementById('profileSelectBox'));
|
|
||||||
Unfocus(document.getElementById('defaultUserRadios'));
|
|
||||||
Unfocus(document.getElementById('newProfileBox'));
|
|
||||||
document.getElementById('storeDefaults').onclick = (): void => storeDefaults(userIDs);
|
|
||||||
userDefaultsModal.show();
|
|
||||||
};
|
|
||||||
|
|
||||||
(<HTMLSelectElement>document.getElementById('defaultsSource')).addEventListener('change', function (): void {
|
|
||||||
const radios = document.getElementById('defaultUserRadios');
|
|
||||||
const profileBox = document.getElementById('profileSelectBox');
|
|
||||||
if (this.value == 'profile') {
|
|
||||||
Unfocus(radios);
|
|
||||||
Focus(profileBox);
|
|
||||||
} else {
|
|
||||||
Unfocus(profileBox);
|
|
||||||
Focus(radios);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
(<HTMLButtonElement>document.getElementById('newUserCreate')).onclick = function (): void {
|
|
||||||
const button = this as HTMLButtonElement;
|
|
||||||
const ogText = button.textContent;
|
|
||||||
button.innerHTML = `
|
|
||||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Creating...
|
|
||||||
`;
|
|
||||||
const email: string = (<HTMLInputElement>document.getElementById('newUserEmail')).value;
|
|
||||||
var username: string = email;
|
|
||||||
if (document.getElementById('newUserName') != null) {
|
|
||||||
username = (<HTMLInputElement>document.getElementById('newUserName')).value;
|
|
||||||
}
|
|
||||||
const password: string = (<HTMLInputElement>document.getElementById('newUserPassword')).value;
|
|
||||||
if (!validateEmail(email) && email != "") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const send = {
|
|
||||||
'username': username,
|
|
||||||
'password': password,
|
|
||||||
'email': email
|
|
||||||
};
|
|
||||||
_post("/newUserAdmin", send, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
rmAttr(button, 'btn-primary');
|
|
||||||
if (this.status == 200) {
|
|
||||||
addAttr(button, 'btn-success');
|
|
||||||
button.textContent = 'Success';
|
|
||||||
setTimeout((): void => {
|
|
||||||
rmAttr(button, 'btn-success');
|
|
||||||
addAttr(button, 'btn-primary');
|
|
||||||
button.textContent = ogText;
|
|
||||||
newUserModal.hide();
|
|
||||||
}, 1000);
|
|
||||||
populateUsers();
|
|
||||||
} else {
|
|
||||||
addAttr(button, 'btn-danger');
|
|
||||||
if ("error" in this.response) {
|
|
||||||
button.textContent = this.response["error"];
|
|
||||||
} else {
|
|
||||||
button.textContent = 'Failed';
|
|
||||||
}
|
|
||||||
setTimeout((): void => {
|
|
||||||
rmAttr(button, 'btn-danger');
|
|
||||||
addAttr(button, 'btn-primary');
|
|
||||||
button.textContent = ogText;
|
|
||||||
}, 2000);
|
|
||||||
populateUsers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
(<HTMLButtonElement>document.getElementById('accountsTabAddUser')).onclick = function (): void {
|
|
||||||
(<HTMLInputElement>document.getElementById('newUserEmail')).value = '';
|
|
||||||
(<HTMLInputElement>document.getElementById('newUserPassword')).value = '';
|
|
||||||
if (document.getElementById('newUserName') != null) {
|
|
||||||
(<HTMLInputElement>document.getElementById('newUserName')).value = '';
|
|
||||||
}
|
|
||||||
newUserModal.show();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,279 +0,0 @@
|
|||||||
interface Window {
|
|
||||||
token: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set in admin.html
|
|
||||||
var cssFile: string;
|
|
||||||
|
|
||||||
const _post = (url: string, data: Object, onreadystatechange: () => void): void => {
|
|
||||||
let req = new XMLHttpRequest();
|
|
||||||
req.open("POST", url, true);
|
|
||||||
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
||||||
req.onreadystatechange = onreadystatechange;
|
|
||||||
req.send(JSON.stringify(data));
|
|
||||||
};
|
|
||||||
|
|
||||||
const _get = (url: string, data: Object, onreadystatechange: () => void): void => {
|
|
||||||
let req = new XMLHttpRequest();
|
|
||||||
req.open("GET", url, true);
|
|
||||||
req.responseType = 'json';
|
|
||||||
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
||||||
req.onreadystatechange = onreadystatechange;
|
|
||||||
req.send(JSON.stringify(data));
|
|
||||||
};
|
|
||||||
|
|
||||||
const rmAttr = (el: HTMLElement, attr: string): void => {
|
|
||||||
if (el.classList.contains(attr)) {
|
|
||||||
el.classList.remove(attr);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const addAttr = (el: HTMLElement, attr: string): void => el.classList.add(attr);
|
|
||||||
|
|
||||||
const Focus = (el: HTMLElement): void => rmAttr(el, 'unfocused');
|
|
||||||
const Unfocus = (el: HTMLElement): void => addAttr(el, 'unfocused');
|
|
||||||
|
|
||||||
interface TabSwitcher {
|
|
||||||
els: Array<HTMLDivElement>;
|
|
||||||
tabButtons: Array<HTMLAnchorElement>;
|
|
||||||
focus: (el: number) => void;
|
|
||||||
invites: () => void;
|
|
||||||
accounts: () => void;
|
|
||||||
settings: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tabs: TabSwitcher = {
|
|
||||||
els: [document.getElementById('invitesTab') as HTMLDivElement, document.getElementById('accountsTab') as HTMLDivElement, document.getElementById('settingsTab') as HTMLDivElement],
|
|
||||||
tabButtons: [document.getElementById('invitesTabButton') as HTMLAnchorElement, document.getElementById('accountsTabButton') as HTMLAnchorElement, document.getElementById('settingsTabButton') as HTMLAnchorElement],
|
|
||||||
focus: (el: number): void => {
|
|
||||||
for (let i = 0; i < tabs.els.length; i++) {
|
|
||||||
if (i == el) {
|
|
||||||
Focus(tabs.els[i]);
|
|
||||||
addAttr(tabs.tabButtons[i], "active");
|
|
||||||
} else {
|
|
||||||
Unfocus(tabs.els[i]);
|
|
||||||
rmAttr(tabs.tabButtons[i], "active");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
invites: (): void => tabs.focus(0),
|
|
||||||
accounts: (): void => {
|
|
||||||
populateUsers();
|
|
||||||
(document.getElementById('selectAll') as HTMLInputElement).checked = false;
|
|
||||||
checkCheckboxes();
|
|
||||||
tabs.focus(1);
|
|
||||||
},
|
|
||||||
settings: (): void => openSettings(document.getElementById('settingsSections'), document.getElementById('settingsContent'), (): void => {
|
|
||||||
triggerTooltips();
|
|
||||||
showSetting("ui");
|
|
||||||
tabs.focus(2);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// for (let i = 0; i < tabs.els.length; i++) {
|
|
||||||
// tabs.tabButtons[i].onclick = (): void => tabs.focus(i);
|
|
||||||
// }
|
|
||||||
tabs.tabButtons[0].onclick = tabs.invites;
|
|
||||||
tabs.tabButtons[1].onclick = tabs.accounts;
|
|
||||||
tabs.tabButtons[2].onclick = tabs.settings;
|
|
||||||
|
|
||||||
|
|
||||||
tabs.invites();
|
|
||||||
|
|
||||||
// Predefined colors for the theme button.
|
|
||||||
var buttonColor: string = "custom";
|
|
||||||
if (cssFile.includes("jf")) {
|
|
||||||
buttonColor = "rgb(255,255,255)";
|
|
||||||
} else if (cssFile == ("bs" + bsVersion + ".css")) {
|
|
||||||
buttonColor = "rgb(16,16,16)";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buttonColor != "custom") {
|
|
||||||
const switchButton = document.createElement('button') as HTMLButtonElement;
|
|
||||||
switchButton.classList.add('btn', 'btn-secondary');
|
|
||||||
switchButton.innerHTML = `
|
|
||||||
Theme
|
|
||||||
<i class="fa fa-circle circle" style="color: ${buttonColor}; margin-left: 0.4rem;" id="fakeButton"></i>
|
|
||||||
`;
|
|
||||||
switchButton.onclick = (): void => toggleCSS(document.getElementById('fakeButton'));
|
|
||||||
document.getElementById('headerButtons').appendChild(switchButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
var loginModal = createModal('login');
|
|
||||||
var userDefaultsModal = createModal('userDefaults');
|
|
||||||
var usersModal = createModal('users');
|
|
||||||
var restartModal = createModal('restartModal');
|
|
||||||
var refreshModal = createModal('refreshModal');
|
|
||||||
var aboutModal = createModal('aboutModal');
|
|
||||||
var deleteModal = createModal('deleteModal');
|
|
||||||
var newUserModal = createModal('newUserModal');
|
|
||||||
|
|
||||||
var availableProfiles: Array<string>;
|
|
||||||
|
|
||||||
window["token"] = "";
|
|
||||||
|
|
||||||
function toClipboard(str: string): void {
|
|
||||||
const el = document.createElement('textarea') as HTMLTextAreaElement;
|
|
||||||
el.value = str;
|
|
||||||
el.readOnly = true;
|
|
||||||
el.style.position = "absolute";
|
|
||||||
el.style.left = "-9999px";
|
|
||||||
document.body.appendChild(el);
|
|
||||||
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
|
||||||
el.select();
|
|
||||||
document.execCommand("copy");
|
|
||||||
document.body.removeChild(el);
|
|
||||||
if (selected) {
|
|
||||||
document.getSelection().removeAllRanges();
|
|
||||||
document.getSelection().addRange(selected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function login(username: string, password: string, modal: boolean, button?: HTMLButtonElement, run?: (arg0: number) => void): void {
|
|
||||||
const req = new XMLHttpRequest();
|
|
||||||
req.responseType = 'json';
|
|
||||||
req.open("GET", "/getToken", true);
|
|
||||||
req.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
|
|
||||||
req.onreadystatechange = function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
if (this.status != 200) {
|
|
||||||
let errorMsg = this.response["error"];
|
|
||||||
if (!errorMsg) {
|
|
||||||
errorMsg = "Unknown error";
|
|
||||||
}
|
|
||||||
if (modal) {
|
|
||||||
button.disabled = false;
|
|
||||||
button.textContent = errorMsg;
|
|
||||||
addAttr(button, "btn-danger");
|
|
||||||
rmAttr(button, "btn-primary");
|
|
||||||
setTimeout((): void => {
|
|
||||||
addAttr(button, "btn-primary");
|
|
||||||
rmAttr(button, "btn-danger");
|
|
||||||
button.textContent = "Login";
|
|
||||||
}, 4000);
|
|
||||||
} else {
|
|
||||||
loginModal.show();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const data = this.response;
|
|
||||||
window.token = data["token"];
|
|
||||||
generateInvites();
|
|
||||||
setInterval((): void => generateInvites(), 60 * 1000);
|
|
||||||
addOptions(30, document.getElementById('days') as HTMLSelectElement);
|
|
||||||
addOptions(24, document.getElementById('hours') as HTMLSelectElement);
|
|
||||||
const minutes = document.getElementById('minutes') as HTMLSelectElement;
|
|
||||||
addOptions(59, minutes);
|
|
||||||
minutes.value = "30";
|
|
||||||
checkDuration();
|
|
||||||
if (modal) {
|
|
||||||
loginModal.hide();
|
|
||||||
}
|
|
||||||
Focus(document.getElementById('logoutButton'));
|
|
||||||
}
|
|
||||||
if (run) {
|
|
||||||
run(+this.status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
req.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
function createEl(html: string): HTMLElement {
|
|
||||||
let div = document.createElement('div') as HTMLDivElement;
|
|
||||||
div.innerHTML = html;
|
|
||||||
return div.firstElementChild as HTMLElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
(document.getElementById('loginForm') as HTMLFormElement).onsubmit = function (): boolean {
|
|
||||||
window.token = "";
|
|
||||||
const details = serializeForm('loginForm');
|
|
||||||
const button = document.getElementById('loginSubmit') as HTMLButtonElement;
|
|
||||||
addAttr(button, "btn-primary");
|
|
||||||
rmAttr(button, "btn-danger");
|
|
||||||
button.disabled = true;
|
|
||||||
button.innerHTML = `
|
|
||||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>
|
|
||||||
Loading...`;
|
|
||||||
login(details["username"], details["password"], true, button);
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
function storeDefaults(users: string | Array<string>): void {
|
|
||||||
// not sure if this does anything, but w/e
|
|
||||||
this.disabled = true;
|
|
||||||
this.innerHTML =
|
|
||||||
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
|
|
||||||
'Loading...';
|
|
||||||
const button = document.getElementById('storeDefaults') as HTMLButtonElement;
|
|
||||||
let data = { "homescreen": false };
|
|
||||||
if ((document.getElementById('defaultsSource') as HTMLSelectElement).value == 'profile') {
|
|
||||||
data["from"] = "profile";
|
|
||||||
data["profile"] = (document.getElementById('profileSelect') as HTMLSelectElement).value;
|
|
||||||
} else {
|
|
||||||
const radio = document.querySelector('input[name=defaultRadios]:checked') as HTMLInputElement
|
|
||||||
let id = radio.id.replace("default_", "");
|
|
||||||
data["from"] = "user";
|
|
||||||
data["id"] = id;
|
|
||||||
}
|
|
||||||
if (users != "all") {
|
|
||||||
data["apply_to"] = users;
|
|
||||||
}
|
|
||||||
if ((document.getElementById('storeDefaultHomescreen') as HTMLInputElement).checked) {
|
|
||||||
data["homescreen"] = true;
|
|
||||||
}
|
|
||||||
_post("/applySettings", data, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
if (this.status == 200 || this.status == 204) {
|
|
||||||
button.textContent = "Success";
|
|
||||||
addAttr(button, "btn-success");
|
|
||||||
rmAttr(button, "btn-danger");
|
|
||||||
rmAttr(button, "btn-primary");
|
|
||||||
button.disabled = false;
|
|
||||||
setTimeout((): void => {
|
|
||||||
button.textContent = "Submit";
|
|
||||||
addAttr(button, "btn-primary");
|
|
||||||
rmAttr(button, "btn-success");
|
|
||||||
button.disabled = false;
|
|
||||||
userDefaultsModal.hide();
|
|
||||||
}, 1000);
|
|
||||||
} else {
|
|
||||||
if ("error" in this.response) {
|
|
||||||
button.textContent = this.response["error"];
|
|
||||||
} else if (("policy" in this.response) || ("homescreen" in this.response)) {
|
|
||||||
button.textContent = "Failed (check console)";
|
|
||||||
} else {
|
|
||||||
button.textContent = "Failed";
|
|
||||||
}
|
|
||||||
addAttr(button, "btn-danger");
|
|
||||||
rmAttr(button, "btn-primary");
|
|
||||||
setTimeout((): void => {
|
|
||||||
button.textContent = "Submit";
|
|
||||||
addAttr(button, "btn-primary");
|
|
||||||
rmAttr(button, "btn-danger");
|
|
||||||
button.disabled = false;
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
generateInvites(true);
|
|
||||||
|
|
||||||
login("", "", false, null, (status: number): void => {
|
|
||||||
if (!(status == 200 || status == 204)) {
|
|
||||||
loginModal.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
(document.getElementById('logoutButton') as HTMLButtonElement).onclick = function (): void {
|
|
||||||
_post("/logout", null, function (): boolean {
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
|
||||||
window.token = "";
|
|
||||||
location.reload();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
|||||||
// Used for animation on theme change
|
|
||||||
const whichTransitionEvent = (): string => {
|
|
||||||
const el = document.createElement('fakeElement');
|
|
||||||
const transitions = {
|
|
||||||
'transition': 'transitionend',
|
|
||||||
'OTransition': 'oTransitionEnd',
|
|
||||||
'MozTransition': 'transitionend',
|
|
||||||
'WebkitTransition': 'webkitTransitionEnd'
|
|
||||||
};
|
|
||||||
for (const t in transitions) {
|
|
||||||
if (el.style[t] !== undefined) {
|
|
||||||
return transitions[t];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
};
|
|
||||||
|
|
||||||
var transitionEndEvent = whichTransitionEvent();
|
|
||||||
|
|
||||||
// Toggles between light and dark themes
|
|
||||||
const _toggleCSS = (): void => {
|
|
||||||
const els: NodeListOf<HTMLLinkElement> = document.querySelectorAll('link[rel="stylesheet"][type="text/css"]');
|
|
||||||
let cssEl = 0;
|
|
||||||
let remove = false;
|
|
||||||
if (els.length != 1) {
|
|
||||||
cssEl = 1;
|
|
||||||
remove = true
|
|
||||||
}
|
|
||||||
let href: string = "bs" + bsVersion;
|
|
||||||
if (!els[cssEl].href.includes(href + "-jf")) {
|
|
||||||
href += "-jf";
|
|
||||||
}
|
|
||||||
href += ".css";
|
|
||||||
let newEl = els[cssEl].cloneNode(true) as HTMLLinkElement;
|
|
||||||
newEl.href = href;
|
|
||||||
els[cssEl].parentNode.insertBefore(newEl, els[cssEl].nextSibling);
|
|
||||||
if (remove) {
|
|
||||||
els[0].remove();
|
|
||||||
}
|
|
||||||
document.cookie = "css=" + href;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggles between light and dark themes, but runs animation if window small enough.
|
|
||||||
var buttonWidth = 0;
|
|
||||||
const toggleCSS = (el: HTMLElement): void => {
|
|
||||||
const switchToColor = window.getComputedStyle(document.body, null).backgroundColor;
|
|
||||||
// Max page width for animation to take place
|
|
||||||
let maxWidth = 1500;
|
|
||||||
if (window.innerWidth < maxWidth) {
|
|
||||||
// Calculate minimum radius to cover screen
|
|
||||||
const radius = Math.sqrt(Math.pow(window.innerWidth, 2) + Math.pow(window.innerHeight, 2));
|
|
||||||
const currentRadius = el.getBoundingClientRect().width / 2;
|
|
||||||
const scale = radius / currentRadius;
|
|
||||||
buttonWidth = +window.getComputedStyle(el, null).width;
|
|
||||||
document.body.classList.remove('smooth-transition');
|
|
||||||
el.style.transform = `scale(${scale})`;
|
|
||||||
el.style.color = switchToColor;
|
|
||||||
el.addEventListener(transitionEndEvent, function (): void {
|
|
||||||
if (this.style.transform.length != 0) {
|
|
||||||
_toggleCSS();
|
|
||||||
this.style.removeProperty('transform');
|
|
||||||
document.body.classList.add('smooth-transition');
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
} else {
|
|
||||||
_toggleCSS();
|
|
||||||
el.style.color = switchToColor;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const rotateButton = (el: HTMLElement): void => {
|
|
||||||
if (el.classList.contains("rotated")) {
|
|
||||||
rmAttr(el, "rotated")
|
|
||||||
addAttr(el, "not-rotated");
|
|
||||||
} else {
|
|
||||||
rmAttr(el, "not-rotated");
|
|
||||||
addAttr(el, "rotated");
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,36 +0,0 @@
|
|||||||
var bsVersion = 4;
|
|
||||||
|
|
||||||
const send_to_addess_enabled = document.getElementById('send_to_addess_enabled');
|
|
||||||
if (send_to_addess_enabled) {
|
|
||||||
send_to_addess_enabled.classList.remove("form-check-input");
|
|
||||||
}
|
|
||||||
const multiUseEnabled = document.getElementById('multiUseEnabled');
|
|
||||||
if (multiUseEnabled) {
|
|
||||||
multiUseEnabled.classList.remove("form-check-input");
|
|
||||||
}
|
|
||||||
|
|
||||||
function createModal(id: string, find?: boolean): any {
|
|
||||||
$(`#${id}`).on("shown.bs.modal", (): void => document.body.classList.add("modal-open"));
|
|
||||||
return {
|
|
||||||
show: function (): any {
|
|
||||||
const temp = ($(`#${id}`) as any).modal("show");
|
|
||||||
return temp;
|
|
||||||
},
|
|
||||||
hide: function (): any {
|
|
||||||
return ($(`#${id}`) as any).modal("hide");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function triggerTooltips(): void {
|
|
||||||
const checkboxes = [].slice.call(document.getElementById('settingsContent').querySelectorAll('input[type="checkbox"]'));
|
|
||||||
for (const i in checkboxes) {
|
|
||||||
checkboxes[i].click();
|
|
||||||
checkboxes[i].click();
|
|
||||||
}
|
|
||||||
const tooltips = [].slice.call(document.querySelectorAll('a[data-toggle="tooltip"]'));
|
|
||||||
tooltips.map((el: HTMLAnchorElement): any => {
|
|
||||||
return ($(el) as any).tooltip();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
|||||||
declare var bootstrap: any;
|
|
||||||
|
|
||||||
var bsVersion = 5;
|
|
||||||
|
|
||||||
function createModal(id: string, find?: boolean): any {
|
|
||||||
let modal: any;
|
|
||||||
if (find) {
|
|
||||||
modal = bootstrap.Modal.getInstance(document.getElementById(id));
|
|
||||||
} else {
|
|
||||||
modal = new bootstrap.Modal(document.getElementById(id));
|
|
||||||
}
|
|
||||||
document.getElementById(id).addEventListener('shown.bs.modal', (): void => document.body.classList.add("modal-open"));
|
|
||||||
return {
|
|
||||||
modal: modal,
|
|
||||||
show: function (): any {
|
|
||||||
const temp = this.modal.show();
|
|
||||||
return temp;
|
|
||||||
},
|
|
||||||
hide: function (): any { return this.modal.hide(); }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function triggerTooltips(): void {
|
|
||||||
const checkboxes = [].slice.call(document.getElementById('settingsContent').querySelectorAll('input[type="checkbox"]'));
|
|
||||||
for (const i in checkboxes) {
|
|
||||||
checkboxes[i].click();
|
|
||||||
checkboxes[i].click();
|
|
||||||
}
|
|
||||||
const tooltips = [].slice.call(document.querySelectorAll('a[data-toggle="tooltip"]'));
|
|
||||||
tooltips.map((el: HTMLAnchorElement): any => {
|
|
||||||
return new bootstrap.Tooltip(el);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,378 +0,0 @@
|
|||||||
// Actually defined by templating in admin.html, this is just to avoid errors from tsc.
|
|
||||||
var notifications_enabled: any;
|
|
||||||
|
|
||||||
interface Invite {
|
|
||||||
code?: string;
|
|
||||||
expiresIn?: string;
|
|
||||||
empty: boolean;
|
|
||||||
remainingUses?: string;
|
|
||||||
email?: string;
|
|
||||||
usedBy?: Array<Array<string>>;
|
|
||||||
created?: string;
|
|
||||||
notifyExpiry?: boolean;
|
|
||||||
notifyCreation?: boolean;
|
|
||||||
profile?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const emptyInvite = (): Invite => { return { code: "None", empty: true } as Invite; }
|
|
||||||
|
|
||||||
function parseInvite(invite: Object): Invite {
|
|
||||||
let inv: Invite = { code: invite["code"], empty: false, };
|
|
||||||
if (invite["email"]) {
|
|
||||||
inv.email = invite["email"];
|
|
||||||
}
|
|
||||||
let time = ""
|
|
||||||
const f = ["days", "hours", "minutes"];
|
|
||||||
for (const i in f) {
|
|
||||||
if (invite[f[i]] != 0) {
|
|
||||||
time += `${invite[f[i]]}${f[i][0]} `;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inv.expiresIn = `Expires in ${time.slice(0, -1)}`;
|
|
||||||
if (invite["no-limit"]) {
|
|
||||||
inv.remainingUses = "∞";
|
|
||||||
} else if ("remaining-uses" in invite) {
|
|
||||||
inv.remainingUses = invite["remaining-uses"];
|
|
||||||
}
|
|
||||||
if ("used-by" in invite) {
|
|
||||||
inv.usedBy = invite["used-by"];
|
|
||||||
}
|
|
||||||
if ("created" in invite) {
|
|
||||||
inv.created = invite["created"];
|
|
||||||
}
|
|
||||||
if ("notify-expiry" in invite) {
|
|
||||||
inv.notifyExpiry = invite["notify-expiry"];
|
|
||||||
}
|
|
||||||
if ("notify-creation" in invite) {
|
|
||||||
inv.notifyCreation = invite["notify-creation"];
|
|
||||||
}
|
|
||||||
if ("profile" in invite) {
|
|
||||||
inv.profile = invite["profile"];
|
|
||||||
}
|
|
||||||
return inv;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setNotify(el: HTMLElement): void {
|
|
||||||
let send = {};
|
|
||||||
let code: string;
|
|
||||||
let notifyType: string;
|
|
||||||
if (el.id.includes("Expiry")) {
|
|
||||||
code = el.id.replace("_notifyExpiry", "");
|
|
||||||
notifyType = "notify-expiry";
|
|
||||||
} else if (el.id.includes("Creation")) {
|
|
||||||
code = el.id.replace("_notifyCreation", "");
|
|
||||||
notifyType = "notify-creation";
|
|
||||||
}
|
|
||||||
send[code] = {};
|
|
||||||
send[code][notifyType] = (el as HTMLInputElement).checked;
|
|
||||||
_post("/setNotify", send, function (): void {
|
|
||||||
if (this.readyState == 4 && this.status != 200) {
|
|
||||||
(el as HTMLInputElement).checked = !(el as HTMLInputElement).checked;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function genUsedBy(usedBy: Array<Array<string>>): string {
|
|
||||||
let uB = "";
|
|
||||||
if (usedBy && usedBy.length != 0) {
|
|
||||||
uB = `
|
|
||||||
<ul class="list-group list-group-flush">
|
|
||||||
<li class="list-group-item py-1">Users created:</li>
|
|
||||||
`;
|
|
||||||
for (const i in usedBy) {
|
|
||||||
uB += `
|
|
||||||
<li class="list-group-item py-1 disabled">
|
|
||||||
<div class="d-flex float-left">${usedBy[i][0]}</div>
|
|
||||||
<div class="d-flex float-right">${usedBy[i][1]}</div>
|
|
||||||
</li>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
uB += `</ul>`
|
|
||||||
}
|
|
||||||
return uB;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addItem(invite: Invite): void {
|
|
||||||
const links = document.getElementById('invites');
|
|
||||||
const container = document.createElement('div') as HTMLDivElement;
|
|
||||||
container.id = invite.code;
|
|
||||||
const item = document.createElement('div') as HTMLDivElement;
|
|
||||||
item.classList.add('list-group-item', 'd-flex', 'justify-content-between', 'd-inline-block');
|
|
||||||
let link = "";
|
|
||||||
let innerHTML = `<a>None</a>`;
|
|
||||||
if (invite.empty) {
|
|
||||||
item.innerHTML = `
|
|
||||||
<div class="d-flex align-items-center font-monospace" style="width: 40%;">
|
|
||||||
${innerHTML}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
container.appendChild(item);
|
|
||||||
links.appendChild(container);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
link = window.location.href.split('#')[0] + "invite/" + invite.code;
|
|
||||||
innerHTML = `
|
|
||||||
<div class="d-flex align-items-center font-monospace" style="width: 40%;">
|
|
||||||
<a class="invite-link" href="${link}">${invite.code.replace(/-/g, '-')}</a>
|
|
||||||
<i class="fa fa-clipboard icon-button" onclick="toClipboard('${link}')" style="margin-right: 0.5rem; margin-left: 0.5rem;"></i>
|
|
||||||
`;
|
|
||||||
if (invite.email) {
|
|
||||||
let email = invite.email;
|
|
||||||
if (!invite.email.includes("Failed to send to")) {
|
|
||||||
email = `Sent to ${email}`;
|
|
||||||
}
|
|
||||||
innerHTML += `
|
|
||||||
<span class="text-muted" style="margin-left: 0.4rem; font-style: italic; font-size: 0.8rem;">${email}</span>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
innerHTML += `
|
|
||||||
</div>
|
|
||||||
<div style="text-align: right;">
|
|
||||||
<span id="${invite.code}_expiry" style="margin-right: 1rem;">${invite.expiresIn}</span>
|
|
||||||
<div style="display: inline-block;">
|
|
||||||
<button class="btn btn-outline-danger" onclick="deleteInvite('${invite.code}')">Delete</button>
|
|
||||||
<i class="fa fa-angle-down collapsed icon-button not-rotated" style="padding: 1rem; margin: -1rem -1rem -1rem 0;" data-toggle="collapse" aria-expanded="false" data-target="#${CSS.escape(invite.code)}_collapse" onclick="rotateButton(this)"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
item.innerHTML = innerHTML;
|
|
||||||
container.appendChild(item);
|
|
||||||
|
|
||||||
let profiles = `
|
|
||||||
<label class="input-group-text" for="profile_${CSS.escape(invite.code)}">Profile: </label>
|
|
||||||
<select class="form-select" id="profile_${CSS.escape(invite.code)}" onchange="setProfile(this)">
|
|
||||||
<option value="NoProfile" selected>No Profile</option>
|
|
||||||
`;
|
|
||||||
for (const i in availableProfiles) {
|
|
||||||
let selected = "";
|
|
||||||
if (availableProfiles[i] == invite.profile) {
|
|
||||||
selected = "selected";
|
|
||||||
}
|
|
||||||
profiles += `<option value="${availableProfiles[i]}" ${selected}>${availableProfiles[i]}</option>`;
|
|
||||||
}
|
|
||||||
profiles += `</select>`;
|
|
||||||
|
|
||||||
let dateCreated: string;
|
|
||||||
if (invite.created) {
|
|
||||||
dateCreated = `<li class="list-group-item py-1">Created: ${invite.created}</li>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let middle: string;
|
|
||||||
if (notifications_enabled) {
|
|
||||||
middle = `
|
|
||||||
<div class="col" id="${CSS.escape(invite.code)}_notifyButtons">
|
|
||||||
<ul class="list-group list-group-flush">
|
|
||||||
Notify on:
|
|
||||||
<li class="list-group-item py-1 form-check">
|
|
||||||
<input class="form-check-input" type="checkbox" value="" id="${CSS.escape(invite.code)}_notifyExpiry" onclick="setNotify(this)" ${invite.notifyExpiry ? "checked" : ""}>
|
|
||||||
<label class="form-check-label" for="${CSS.escape(invite.code)}_notifyExpiry">Expiry</label>
|
|
||||||
</li>
|
|
||||||
<li class="list-group-item py-1 form-check">
|
|
||||||
<input class="form-check-input" type="checkbox" value="" id="${CSS.escape(invite.code)}_notifyCreation" onclick="setNotify(this)" ${invite.notifyCreation ? "checked" : ""}>
|
|
||||||
<label class="form-check-label" for="${CSS.escape(invite.code)}_notifyCreation">User creation</label>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let right: string = genUsedBy(invite.usedBy)
|
|
||||||
|
|
||||||
const dropdown = document.createElement('div') as HTMLDivElement;
|
|
||||||
dropdown.id = `${CSS.escape(invite.code)}_collapse`;
|
|
||||||
dropdown.classList.add("collapse");
|
|
||||||
dropdown.innerHTML = `
|
|
||||||
<div class="container row align-items-start card-body">
|
|
||||||
<div class="col">
|
|
||||||
<ul class="list-group list-group-flush">
|
|
||||||
<li class="input-group py-1">
|
|
||||||
${profiles}
|
|
||||||
</li>
|
|
||||||
${dateCreated}
|
|
||||||
<li class="list-group-item py-1" id="${CSS.escape(invite.code)}_remainingUses">Remaining uses: ${invite.remainingUses}</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
${middle}
|
|
||||||
<div class="col" id="${CSS.escape(invite.code)}_usersCreated">
|
|
||||||
${right}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
container.appendChild(dropdown);
|
|
||||||
links.appendChild(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateInvite(invite: Invite): void {
|
|
||||||
document.getElementById(invite.code + "_expiry").textContent = invite.expiresIn;
|
|
||||||
const remainingUses: any = document.getElementById(CSS.escape(invite.code) + "_remainingUses");
|
|
||||||
if (remainingUses) {
|
|
||||||
remainingUses.textContent = `Remaining uses: ${invite.remainingUses}`;
|
|
||||||
}
|
|
||||||
document.getElementById(CSS.escape(invite.code) + "_usersCreated").innerHTML = genUsedBy(invite.usedBy);
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete invite from DOM
|
|
||||||
const hideInvite = (code: string): void => document.getElementById(CSS.escape(code)).remove();
|
|
||||||
|
|
||||||
// delete invite from jfa-go
|
|
||||||
const deleteInvite = (code: string): void => _post("/deleteInvite", { "code": code }, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
generateInvites();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function generateInvites(empty?: boolean): void {
|
|
||||||
if (empty) {
|
|
||||||
document.getElementById('invites').textContent = '';
|
|
||||||
addItem(emptyInvite());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_get("/getInvites", null, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
let data = this.response;
|
|
||||||
availableProfiles = data['profiles'];
|
|
||||||
const Profiles = document.getElementById('inviteProfile') as HTMLSelectElement;
|
|
||||||
let innerHTML = "";
|
|
||||||
for (let i = 0; i < availableProfiles.length; i++) {
|
|
||||||
const profile = availableProfiles[i];
|
|
||||||
innerHTML += `
|
|
||||||
<option value="${profile}" ${(i == 0) ? "selected" : ""}>${profile}</option>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
innerHTML += `
|
|
||||||
<option value="NoProfile" ${(availableProfiles.length == 0) ? "selected" : ""}>No Profile</option>
|
|
||||||
`;
|
|
||||||
Profiles.innerHTML = innerHTML;
|
|
||||||
if (data['invites'] == null || data['invites'].length == 0) {
|
|
||||||
document.getElementById('invites').textContent = '';
|
|
||||||
addItem(emptyInvite());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let items = document.getElementById('invites').children;
|
|
||||||
for (const i in data['invites']) {
|
|
||||||
let match = false;
|
|
||||||
const inv = parseInvite(data['invites'][i]);
|
|
||||||
for (const x in items) {
|
|
||||||
if (items[x].id == inv.code) {
|
|
||||||
match = true;
|
|
||||||
updateInvite(inv);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!match) {
|
|
||||||
addItem(inv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// second pass to check for expired invites
|
|
||||||
items = document.getElementById('invites').children;
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
|
||||||
let exists = false;
|
|
||||||
for (const x in data['invites']) {
|
|
||||||
if (items[i].id == data['invites'][x]['code']) {
|
|
||||||
exists = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!exists) {
|
|
||||||
hideInvite(items[i].id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const addOptions = (length: number, el: HTMLSelectElement): void => {
|
|
||||||
for (let v = 0; v <= length; v++) {
|
|
||||||
const opt = document.createElement('option');
|
|
||||||
opt.textContent = ""+v;
|
|
||||||
opt.value = ""+v;
|
|
||||||
el.appendChild(opt);
|
|
||||||
}
|
|
||||||
el.value = "0";
|
|
||||||
};
|
|
||||||
|
|
||||||
function fixCheckboxes(): void {
|
|
||||||
const send_to_address: Array<HTMLInputElement> = [document.getElementById('send_to_address') as HTMLInputElement, document.getElementById('send_to_address_enabled') as HTMLInputElement];
|
|
||||||
if (send_to_address[0] != null) {
|
|
||||||
send_to_address[0].disabled = !send_to_address[1].checked;
|
|
||||||
}
|
|
||||||
const multiUseEnabled = document.getElementById('multiUseEnabled') as HTMLInputElement;
|
|
||||||
const multiUseCount = document.getElementById('multiUseCount') as HTMLInputElement;
|
|
||||||
const noUseLimit = document.getElementById('noUseLimit') as HTMLInputElement;
|
|
||||||
multiUseCount.disabled = !multiUseEnabled.checked;
|
|
||||||
noUseLimit.checked = false;
|
|
||||||
noUseLimit.disabled = !multiUseEnabled.checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
fixCheckboxes();
|
|
||||||
|
|
||||||
(document.getElementById('inviteForm') as HTMLFormElement).onsubmit = function (): boolean {
|
|
||||||
const button = document.getElementById('generateSubmit') as HTMLButtonElement;
|
|
||||||
button.disabled = true;
|
|
||||||
button.innerHTML = `
|
|
||||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>
|
|
||||||
Loading...`;
|
|
||||||
let send = serializeForm('inviteForm');
|
|
||||||
send["remaining-uses"] = +send["remaining-uses"];
|
|
||||||
if (!send['multiple-uses'] || send['no-limit']) {
|
|
||||||
delete send['remaining-uses'];
|
|
||||||
}
|
|
||||||
if (send["profile"] == "NoProfile") {
|
|
||||||
send["profile"] = "";
|
|
||||||
}
|
|
||||||
const sendToAddress: any = document.getElementById('send_to_address');
|
|
||||||
const sendToAddressEnabled: any = document.getElementById('send_to_address_enabled');
|
|
||||||
if (sendToAddress && sendToAddressEnabled) {
|
|
||||||
send['email'] = send['send_to_address'];
|
|
||||||
delete send['send_to_address'];
|
|
||||||
delete send['send_to_address_enabled'];
|
|
||||||
}
|
|
||||||
console.log(send);
|
|
||||||
_post("/generateInvite", send, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
button.textContent = 'Generate';
|
|
||||||
button.disabled = false;
|
|
||||||
generateInvites();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
triggerTooltips();
|
|
||||||
|
|
||||||
function setProfile(select: HTMLSelectElement): void {
|
|
||||||
if (!select.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let val = select.value;
|
|
||||||
if (select.value == "NoProfile") {
|
|
||||||
val = ""
|
|
||||||
}
|
|
||||||
const invite = select.id.replace("profile_", "");
|
|
||||||
const send = {
|
|
||||||
"invite": invite,
|
|
||||||
"profile": val
|
|
||||||
};
|
|
||||||
_post("/setProfile", send, function (): void {
|
|
||||||
if (this.readyState == 4 && this.status != 200) {
|
|
||||||
generateInvites();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkDuration(): void {
|
|
||||||
const boxVals: Array<number> = [+(document.getElementById("days") as HTMLSelectElement).value, +(document.getElementById("hours") as HTMLSelectElement).value, +(document.getElementById("minutes") as HTMLSelectElement).value];
|
|
||||||
const submit = document.getElementById('generateSubmit') as HTMLButtonElement;
|
|
||||||
if (boxVals.reduce((a: number, b: number): number => a + b) == 0) {
|
|
||||||
submit.disabled = true;
|
|
||||||
} else {
|
|
||||||
submit.disabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const nE: Array<string> = ["days", "hours", "minutes"];
|
|
||||||
for (const i in nE) {
|
|
||||||
document.getElementById(nE[i]).addEventListener("change", checkDuration);
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
const ombiDefaultsModal = createModal('ombiDefaults');
|
|
||||||
(document.getElementById('openOmbiDefaults') as HTMLButtonElement).onclick = function (): void {
|
|
||||||
let button = this as HTMLButtonElement;
|
|
||||||
button.disabled = true;
|
|
||||||
const ogHTML = button.innerHTML;
|
|
||||||
button.innerHTML =
|
|
||||||
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
|
|
||||||
'Loading...';
|
|
||||||
_get("/getOmbiUsers", null, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
if (this.status == 200) {
|
|
||||||
const users = this.response['users'];
|
|
||||||
const radioList = document.getElementById('ombiUserRadios');
|
|
||||||
radioList.textContent = '';
|
|
||||||
let first = true;
|
|
||||||
for (const i in users) {
|
|
||||||
const user = users[i];
|
|
||||||
const radio = document.createElement('div') as HTMLDivElement;
|
|
||||||
radio.classList.add('form-check');
|
|
||||||
let checked = '';
|
|
||||||
if (first) {
|
|
||||||
checked = 'checked';
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
radio.innerHTML = `
|
|
||||||
<input class="form-check-input" type="radio" name="ombiRadios" id="ombiDefault_${user['id']}" ${checked}>
|
|
||||||
<label class="form-check-label" for="ombiDefault_${user['id']}">${user['name']}</label>
|
|
||||||
`;
|
|
||||||
radioList.appendChild(radio);
|
|
||||||
}
|
|
||||||
button.disabled = false;
|
|
||||||
button.innerHTML = ogHTML;
|
|
||||||
const submitButton = document.getElementById('storeOmbiDefaults') as HTMLButtonElement;
|
|
||||||
submitButton.disabled = false;
|
|
||||||
submitButton.textContent = 'Submit';
|
|
||||||
addAttr(submitButton, "btn-primary");
|
|
||||||
rmAttr(submitButton, "btn-success");
|
|
||||||
rmAttr(submitButton, "btn-danger");
|
|
||||||
ombiDefaultsModal.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
(document.getElementById('storeOmbiDefaults') as HTMLButtonElement).onclick = function (): void {
|
|
||||||
let button = this as HTMLButtonElement;
|
|
||||||
button.disabled = true;
|
|
||||||
button.innerHTML =
|
|
||||||
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
|
|
||||||
'Loading...';
|
|
||||||
const radio = document.querySelector('input[name=ombiRadios]:checked') as HTMLInputElement;
|
|
||||||
const data = {
|
|
||||||
"id": radio.id.replace("ombiDefault_", "")
|
|
||||||
};
|
|
||||||
_post("/setOmbiDefaults", data, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
if (this.status == 200 || this.status == 204) {
|
|
||||||
button.textContent = "Success";
|
|
||||||
addAttr(button, "btn-success");
|
|
||||||
rmAttr(button, "btn-danger");
|
|
||||||
rmAttr(button, "btn-primary");
|
|
||||||
button.disabled = false;
|
|
||||||
setTimeout((): void => ombiDefaultsModal.hide(), 1000);
|
|
||||||
} else {
|
|
||||||
button.textContent = "Failed";
|
|
||||||
rmAttr(button, "btn-primary");
|
|
||||||
addAttr(button, "btn-danger");
|
|
||||||
setTimeout((): void => {
|
|
||||||
button.textContent = "Submit";
|
|
||||||
addAttr(button, "btn-primary");
|
|
||||||
rmAttr(button, "btn-danger");
|
|
||||||
button.disabled = false;
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
|||||||
function serializeForm(id: string): Object {
|
|
||||||
const form = document.getElementById(id) as HTMLFormElement;
|
|
||||||
let formData = {};
|
|
||||||
for (let i = 0; i < form.elements.length; i++) {
|
|
||||||
const el = form.elements[i];
|
|
||||||
if ((el as HTMLInputElement).type == "submit") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let name = (el as HTMLInputElement).name;
|
|
||||||
if (!name) {
|
|
||||||
name = el.id;
|
|
||||||
}
|
|
||||||
switch ((el as HTMLInputElement).type) {
|
|
||||||
case "checkbox":
|
|
||||||
formData[name] = (el as HTMLInputElement).checked;
|
|
||||||
break;
|
|
||||||
case "text":
|
|
||||||
case "password":
|
|
||||||
case "email":
|
|
||||||
case "number":
|
|
||||||
formData[name] = (el as HTMLInputElement).value;
|
|
||||||
break;
|
|
||||||
case "select-one":
|
|
||||||
case "select":
|
|
||||||
let val: string = (el as HTMLSelectElement).value.toString();
|
|
||||||
if (!isNaN(val as any)) {
|
|
||||||
formData[name] = +val;
|
|
||||||
} else {
|
|
||||||
formData[name] = val;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return formData;
|
|
||||||
}
|
|
@ -1,344 +0,0 @@
|
|||||||
var config: Object = {};
|
|
||||||
var modifiedConfig: Object = {};
|
|
||||||
|
|
||||||
function sendConfig(restart?: boolean): void {
|
|
||||||
modifiedConfig["restart-program"] = restart;
|
|
||||||
_post("/modifyConfig", modifiedConfig, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
const save = document.getElementById("settingsSave") as HTMLButtonElement
|
|
||||||
if (this.status == 200 || this.status == 204) {
|
|
||||||
save.textContent = "Success";
|
|
||||||
addAttr(save, "btn-success");
|
|
||||||
rmAttr(save, "btn-primary");
|
|
||||||
setTimeout((): void => {
|
|
||||||
save.textContent = "Save";
|
|
||||||
addAttr(save, "btn-primary");
|
|
||||||
rmAttr(save, "btn-success");
|
|
||||||
}, 1000);
|
|
||||||
} else {
|
|
||||||
save.textContent = "Save";
|
|
||||||
}
|
|
||||||
if (restart) {
|
|
||||||
refreshModal.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
(document.getElementById('openAbout') as HTMLButtonElement).onclick = (): void => {
|
|
||||||
aboutModal.show();
|
|
||||||
};
|
|
||||||
|
|
||||||
const openSettings = (settingsList: HTMLElement, settingsContent: HTMLElement, callback?: () => void): void => _get("/getConfig", null, function (): void {
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
|
||||||
settingsList.textContent = '';
|
|
||||||
config = this.response;
|
|
||||||
for (const i in config["order"]) {
|
|
||||||
const section: string = config["order"][i]
|
|
||||||
const sectionCollapse = document.createElement('div') as HTMLDivElement;
|
|
||||||
Unfocus(sectionCollapse);
|
|
||||||
sectionCollapse.id = section;
|
|
||||||
|
|
||||||
const title: string = config[section]["meta"]["name"];
|
|
||||||
const description: string = config[section]["meta"]["description"];
|
|
||||||
const entryListID: string = `${section}_entryList`;
|
|
||||||
// const footerID: string = `${section}_footer`;
|
|
||||||
|
|
||||||
sectionCollapse.innerHTML = `
|
|
||||||
<div class="card card-body">
|
|
||||||
<small class="text-muted">${description}</small>
|
|
||||||
<div class="${entryListID}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
for (const x in config[section]["order"]) {
|
|
||||||
const entry: string = config[section]["order"][x];
|
|
||||||
if (entry == "meta") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let entryName: string = config[section][entry]["name"];
|
|
||||||
let required = false;
|
|
||||||
if (config[section][entry]["required"]) {
|
|
||||||
entryName += ` <sup class="text-danger">*</sup>`;
|
|
||||||
required = true;
|
|
||||||
}
|
|
||||||
if (config[section][entry]["requires_restart"]) {
|
|
||||||
entryName += ` <sup class="text-danger">R</sup>`;
|
|
||||||
}
|
|
||||||
if ("description" in config[section][entry]) {
|
|
||||||
entryName +=`
|
|
||||||
<a class="text-muted" href="#" data-toggle="tooltip" data-placement="right" title="${config[section][entry]['description']}"><i class="fa fa-question-circle-o"></i></a>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
const entryValue: boolean | string = config[section][entry]["value"];
|
|
||||||
const entryType: string = config[section][entry]["type"];
|
|
||||||
const entryGroup = document.createElement('div');
|
|
||||||
if (entryType == "bool") {
|
|
||||||
entryGroup.classList.add("form-check");
|
|
||||||
entryGroup.innerHTML = `
|
|
||||||
<input class="form-check-input" type="checkbox" value="" id="${section}_${entry}" ${(entryValue as boolean) ? 'checked': ''} ${required ? 'required' : ''}>
|
|
||||||
<label class="form-check-label" for="${section}_${entry}">${entryName}</label>
|
|
||||||
`;
|
|
||||||
(entryGroup.querySelector('input[type=checkbox]') as HTMLInputElement).onclick = function (): void {
|
|
||||||
const me = this as HTMLInputElement;
|
|
||||||
for (const y in config["order"]) {
|
|
||||||
const sect: string = config["order"][y];
|
|
||||||
for (const z in config[sect]["order"]) {
|
|
||||||
const ent: string = config[sect]["order"][z];
|
|
||||||
if (`${sect}_${config[sect][ent]['depends_true']}` == me.id) {
|
|
||||||
(document.getElementById(`${sect}_${ent}`) as HTMLInputElement).disabled = !(me.checked);
|
|
||||||
} else if (`${sect}_${config[sect][ent]['depends_false']}` == me.id) {
|
|
||||||
(document.getElementById(`${sect}_${ent}`) as HTMLInputElement).disabled = me.checked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else if ((entryType == 'text') || (entryType == 'email') || (entryType == 'password') || (entryType == 'number')) {
|
|
||||||
entryGroup.classList.add("form-group");
|
|
||||||
entryGroup.innerHTML = `
|
|
||||||
<label for="${section}_${entry}">${entryName}</label>
|
|
||||||
<input type="${entryType}" class="form-control" id="${section}_${entry}" aria-describedby="${entry}" value="${entryValue}" ${required ? 'required' : ''}>
|
|
||||||
`;
|
|
||||||
} else if (entryType == 'select') {
|
|
||||||
entryGroup.classList.add("form-group");
|
|
||||||
const entryOptions: Array<string> = config[section][entry]["options"];
|
|
||||||
let innerGroup = `
|
|
||||||
<label for="${section}_${entry}">${entryName}</label>
|
|
||||||
<select class="form-control" id="${section}_${entry}" ${required ? 'required' : ''}>
|
|
||||||
`;
|
|
||||||
for (const z in entryOptions) {
|
|
||||||
const entryOption = entryOptions[z];
|
|
||||||
let selected: boolean = (entryOption == entryValue);
|
|
||||||
innerGroup += `
|
|
||||||
<option value="${entryOption}" ${selected ? 'selected' : ''}>${entryOption}</option>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
innerGroup += `</select>`;
|
|
||||||
entryGroup.innerHTML = innerGroup;
|
|
||||||
}
|
|
||||||
sectionCollapse.getElementsByClassName(entryListID)[0].appendChild(entryGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
settingsList.innerHTML += `
|
|
||||||
<button type="button" class="list-group-item list-group-item-action" id="${section}_button" onclick="showSetting('${section}')">${title}</button>
|
|
||||||
`;
|
|
||||||
settingsContent.appendChild(sectionCollapse);
|
|
||||||
}
|
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
interface Profile {
|
|
||||||
Admin: boolean;
|
|
||||||
LibraryAccess: string;
|
|
||||||
FromUser: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
(document.getElementById('profiles_button') as HTMLButtonElement).onclick = (): void => showSetting("profiles", populateProfiles);
|
|
||||||
|
|
||||||
const populateProfiles = (noTable?: boolean): void => _get("/getProfiles", null, function (): void {
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
|
||||||
const profileList = document.getElementById('profileList');
|
|
||||||
profileList.textContent = '';
|
|
||||||
availableProfiles = [this.response["default_profile"]];
|
|
||||||
for (let name in this.response) {
|
|
||||||
if (name != availableProfiles[0]) {
|
|
||||||
availableProfiles.push(name);
|
|
||||||
}
|
|
||||||
if (!noTable && name != "default_profile") {
|
|
||||||
const profile: Profile = {
|
|
||||||
Admin: this.response[name]["admin"],
|
|
||||||
LibraryAccess: this.response[name]["libraries"],
|
|
||||||
FromUser: this.response[name]["fromUser"]
|
|
||||||
};
|
|
||||||
profileList.innerHTML += `
|
|
||||||
<td nowrap="nowrap" class="align-middle"><strong>${name}</strong></td>
|
|
||||||
<td nowrap="nowrap" class="align-middle"><input class="${(bsVersion == 5) ? "form-check-input" : ""}" type="radio" name="defaultProfile" onclick="setDefaultProfile('${name}')" ${(name == availableProfiles[0]) ? "checked" : ""}></td>
|
|
||||||
<td nowrap="nowrap" class="align-middle">${profile.FromUser}</td>
|
|
||||||
<td nowrap="nowrap" class="align-middle">${profile.Admin ? "Yes" : "No"}</td>
|
|
||||||
<td nowrap="nowrap" class="align-middle">${profile.LibraryAccess}</td>
|
|
||||||
<td nowrap="nowrap" class="align-middle"><button class="btn btn-outline-danger" id="defaultProfile_${name}" onclick="deleteProfile('${name}')">Delete</button></td>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const setDefaultProfile = (name: string): void => _post("/setDefaultProfile", { "name": name }, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
if (this.status != 200) {
|
|
||||||
(document.getElementById(`defaultProfile_${availableProfiles[0]}`) as HTMLInputElement).checked = true;
|
|
||||||
(document.getElementById(`defaultProfile_${name}`) as HTMLInputElement).checked = false;
|
|
||||||
} else {
|
|
||||||
generateInvites();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const deleteProfile = (name: string): void => _post("/deleteProfile", { "name": name }, function (): void {
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
|
||||||
populateProfiles();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const createProfile = (): void => _get("/getUsers", null, function (): void {
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
|
||||||
jfUsers = this.response["users"];
|
|
||||||
populateRadios();
|
|
||||||
const submitButton = document.getElementById('storeDefaults') as HTMLButtonElement;
|
|
||||||
submitButton.disabled = false;
|
|
||||||
submitButton.textContent = 'Create';
|
|
||||||
addAttr(submitButton, "btn-primary");
|
|
||||||
rmAttr(submitButton, "btn-danger");
|
|
||||||
rmAttr(submitButton, "btn-success");
|
|
||||||
document.getElementById('defaultsTitle').textContent = `Create Profile`;
|
|
||||||
document.getElementById('userDefaultsDescription').textContent = `
|
|
||||||
Create an account and configure it to your liking, then choose it from below to store the settings as a profile. Profiles can be specified per invite, so that any new user on that invite will have the settings applied.`;
|
|
||||||
document.getElementById('storeHomescreenLabel').textContent = `Store homescreen layout`;
|
|
||||||
(document.getElementById('defaultsSource') as HTMLSelectElement).value = 'fromUser';
|
|
||||||
document.getElementById('defaultsSourceSection').classList.add('unfocused');
|
|
||||||
(document.getElementById('storeDefaults') as HTMLButtonElement).onclick = storeProfile;
|
|
||||||
Focus(document.getElementById('newProfileBox'));
|
|
||||||
(document.getElementById('newProfileName') as HTMLInputElement).value = '';
|
|
||||||
Focus(document.getElementById('defaultUserRadios'));
|
|
||||||
userDefaultsModal.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function storeProfile(): void {
|
|
||||||
this.disabled = true;
|
|
||||||
this.innerHTML =
|
|
||||||
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
|
|
||||||
'Loading...';
|
|
||||||
const button = document.getElementById('storeDefaults') as HTMLButtonElement;
|
|
||||||
const radio = document.querySelector('input[name=defaultRadios]:checked') as HTMLInputElement
|
|
||||||
const name = (document.getElementById('newProfileName') as HTMLInputElement).value;
|
|
||||||
let id = radio.id.replace("default_", "");
|
|
||||||
let data = {
|
|
||||||
"name": name,
|
|
||||||
"id": id,
|
|
||||||
"homescreen": false
|
|
||||||
}
|
|
||||||
if ((document.getElementById('storeDefaultHomescreen') as HTMLInputElement).checked) {
|
|
||||||
data["homescreen"] = true;
|
|
||||||
}
|
|
||||||
_post("/createProfile", data, function (): void {
|
|
||||||
if (this.readyState == 4) {
|
|
||||||
if (this.status == 200 || this.status == 204) {
|
|
||||||
button.textContent = "Success";
|
|
||||||
addAttr(button, "btn-success");
|
|
||||||
rmAttr(button, "btn-danger");
|
|
||||||
rmAttr(button, "btn-primary");
|
|
||||||
button.disabled = false;
|
|
||||||
setTimeout((): void => {
|
|
||||||
button.textContent = "Create";
|
|
||||||
addAttr(button, "btn-primary");
|
|
||||||
rmAttr(button, "btn-success");
|
|
||||||
button.disabled = false;
|
|
||||||
userDefaultsModal.hide();
|
|
||||||
|
|
||||||
}, 1000);
|
|
||||||
populateProfiles();
|
|
||||||
generateInvites();
|
|
||||||
} else {
|
|
||||||
if ("error" in this.response) {
|
|
||||||
button.textContent = this.response["error"];
|
|
||||||
} else if (("policy" in this.response) || ("homescreen" in this.response)) {
|
|
||||||
button.textContent = "Failed (check console)";
|
|
||||||
} else {
|
|
||||||
button.textContent = "Failed";
|
|
||||||
}
|
|
||||||
addAttr(button, "btn-danger");
|
|
||||||
rmAttr(button, "btn-primary");
|
|
||||||
setTimeout((): void => {
|
|
||||||
button.textContent = "Create";
|
|
||||||
addAttr(button, "btn-primary");
|
|
||||||
rmAttr(button, "btn-danger");
|
|
||||||
button.disabled = false;
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function showSetting(id: string, runBefore?: () => void): void {
|
|
||||||
const els = document.getElementById('settingsLeft').querySelectorAll("button[type=button]:not(.static)") 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);
|
|
||||||
if (runBefore) {
|
|
||||||
runBefore();
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
modifiedConfig = {};
|
|
||||||
const save = this as HTMLButtonElement;
|
|
||||||
let restartSettingsChanged = false;
|
|
||||||
let settingsChanged = false;
|
|
||||||
for (const i in config["order"]) {
|
|
||||||
const section = config["order"][i];
|
|
||||||
for (const x in config[section]["order"]) {
|
|
||||||
const entry = config[section]["order"][x];
|
|
||||||
if (entry == "meta") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let val: string;
|
|
||||||
const entryID = `${section}_${entry}`;
|
|
||||||
const el = document.getElementById(entryID) as HTMLInputElement;
|
|
||||||
if (el.type == "checkbox") {
|
|
||||||
val = el.checked.toString();
|
|
||||||
} else {
|
|
||||||
val = el.value.toString();
|
|
||||||
}
|
|
||||||
if (val != config[section][entry]["value"].toString()) {
|
|
||||||
if (!(section in modifiedConfig)) {
|
|
||||||
modifiedConfig[section] = {};
|
|
||||||
}
|
|
||||||
modifiedConfig[section][entry] = val;
|
|
||||||
settingsChanged = true;
|
|
||||||
if (config[section][entry]["requires_restart"]) {
|
|
||||||
restartSettingsChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const spinnerHTML = `
|
|
||||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>
|
|
||||||
Loading...`;
|
|
||||||
if (restartSettingsChanged) {
|
|
||||||
save.innerHTML = spinnerHTML;
|
|
||||||
(document.getElementById('applyRestarts') as HTMLButtonElement).onclick = (): void => sendConfig();
|
|
||||||
const restartButton = document.getElementById('applyAndRestart') as HTMLButtonElement;
|
|
||||||
if (restartButton) {
|
|
||||||
restartButton.onclick = (): void => sendConfig(true);
|
|
||||||
}
|
|
||||||
restartModal.show();
|
|
||||||
} else if (settingsChanged) {
|
|
||||||
save.innerHTML = spinnerHTML;
|
|
||||||
sendConfig();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
(document.getElementById('restartModalCancel') as HTMLButtonElement).onclick = (): void => {
|
|
||||||
document.getElementById('settingsSave').textContent = "Save";
|
|
||||||
};
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "../data/static",
|
|
||||||
"target": "es6",
|
|
||||||
"lib": ["dom", "es2017"],
|
|
||||||
"types": ["jquery"]
|
|
||||||
}
|
|
||||||
}
|
|
@ -463,7 +463,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="serialize.js"></script>
|
<script src="serialize.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
var availableProfiles = [];
|
||||||
{{ if .notifications }}
|
{{ if .notifications }}
|
||||||
var notifications_enabled = true;
|
var notifications_enabled = true;
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
40
main.go
40
main.go
@ -455,34 +455,34 @@ func start(asDaemon, firstCall bool) {
|
|||||||
router.GET("/invite/:invCode", app.InviteProxy)
|
router.GET("/invite/:invCode", app.InviteProxy)
|
||||||
api := router.Group("/", app.webAuth())
|
api := router.Group("/", app.webAuth())
|
||||||
router.POST("/logout", app.Logout)
|
router.POST("/logout", app.Logout)
|
||||||
api.POST("/newUserAdmin", app.NewUserAdmin)
|
api.DELETE("/users", app.DeleteUser)
|
||||||
api.POST("/generateInvite", app.GenerateInvite)
|
api.GET("/users", app.GetUsers)
|
||||||
api.GET("/getInvites", app.GetInvites)
|
api.POST("/users", app.NewUserAdmin)
|
||||||
api.GET("/getProfiles", app.GetProfiles)
|
api.POST("/invites", app.GenerateInvite)
|
||||||
api.POST("/setProfile", app.SetProfile)
|
api.GET("/invites", app.GetInvites)
|
||||||
api.POST("/setDefaultProfile", app.SetDefaultProfile)
|
api.DELETE("/invites", app.DeleteInvite)
|
||||||
api.POST("/createProfile", app.CreateProfile)
|
api.POST("/invites/profile", app.SetProfile)
|
||||||
api.POST("/deleteProfile", app.DeleteProfile)
|
api.GET("/profiles", app.GetProfiles)
|
||||||
api.POST("/setNotify", app.SetNotify)
|
api.POST("/profiles/default", app.SetDefaultProfile)
|
||||||
api.POST("/deleteInvite", app.DeleteInvite)
|
api.POST("/profiles", app.CreateProfile)
|
||||||
api.POST("/deleteUser", app.DeleteUser)
|
api.DELETE("/profiles", app.DeleteProfile)
|
||||||
api.GET("/getUsers", app.GetUsers)
|
api.POST("/invites/notify", app.SetNotify)
|
||||||
api.POST("/modifyEmails", app.ModifyEmails)
|
api.POST("/users/emails", app.ModifyEmails)
|
||||||
// api.POST("/setDefaults", app.SetDefaults)
|
// api.POST("/setDefaults", app.SetDefaults)
|
||||||
api.POST("/applySettings", app.ApplySettings)
|
api.POST("/users/settings", app.ApplySettings)
|
||||||
api.GET("/getConfig", app.GetConfig)
|
api.GET("/config", app.GetConfig)
|
||||||
api.POST("/modifyConfig", app.ModifyConfig)
|
api.POST("/config", app.ModifyConfig)
|
||||||
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
||||||
api.GET("/getOmbiUsers", app.OmbiUsers)
|
api.GET("/ombi/users", app.OmbiUsers)
|
||||||
api.POST("/setOmbiDefaults", app.SetOmbiDefaults)
|
api.POST("/ombi/defaults", app.SetOmbiDefaults)
|
||||||
}
|
}
|
||||||
app.info.Printf("Starting router @ %s", address)
|
app.info.Printf("Starting router @ %s", address)
|
||||||
} else {
|
} else {
|
||||||
router.GET("/", func(gc *gin.Context) {
|
router.GET("/", func(gc *gin.Context) {
|
||||||
gc.HTML(200, "setup.html", gin.H{})
|
gc.HTML(200, "setup.html", gin.H{})
|
||||||
})
|
})
|
||||||
router.POST("/testJF", app.TestJF)
|
router.POST("/jellyfin/test", app.TestJF)
|
||||||
router.POST("/modifyConfig", app.ModifyConfig)
|
router.POST("/config", app.ModifyConfig)
|
||||||
app.info.Printf("Loading setup @ %s", address)
|
app.info.Printf("Loading setup @ %s", address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ function changeEmail(icon: HTMLElement, id: string): void {
|
|||||||
tick.replaceWith(spinner);
|
tick.replaceWith(spinner);
|
||||||
let send = {};
|
let send = {};
|
||||||
send[id] = newEmail;
|
send[id] = newEmail;
|
||||||
_post("/modifyEmails", send, function (): void {
|
_post("/users/emails", send, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
if (this.status == 200 || this.status == 204) {
|
if (this.status == 200 || this.status == 204) {
|
||||||
entry.nextElementSibling.remove();
|
entry.nextElementSibling.remove();
|
||||||
@ -123,7 +123,7 @@ function populateUsers(): void {
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
_get("/getUsers", null, function (): void {
|
_get("/users", null, function (): void {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
jfUsers = this.response['users'];
|
jfUsers = this.response['users'];
|
||||||
for (const user of jfUsers) {
|
for (const user of jfUsers) {
|
||||||
@ -206,7 +206,7 @@ function populateRadios(): void {
|
|||||||
'notify': dmNotify.checked,
|
'notify': dmNotify.checked,
|
||||||
'reason': dmReason.value
|
'reason': dmReason.value
|
||||||
};
|
};
|
||||||
_post("/deleteUser", send, function (): void {
|
_delete("/users", send, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
if (this.status == 500) {
|
if (this.status == 500) {
|
||||||
if ("error" in this.reponse) {
|
if ("error" in this.reponse) {
|
||||||
@ -301,7 +301,7 @@ function populateRadios(): void {
|
|||||||
'password': password,
|
'password': password,
|
||||||
'email': email
|
'email': email
|
||||||
};
|
};
|
||||||
_post("/newUserAdmin", send, function (): void {
|
_post("/users", send, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
rmAttr(button, 'btn-primary');
|
rmAttr(button, 'btn-primary');
|
||||||
if (this.status == 200) {
|
if (this.status == 200) {
|
||||||
|
29
ts/admin.ts
29
ts/admin.ts
@ -5,15 +5,6 @@ interface Window {
|
|||||||
// Set in admin.html
|
// Set in admin.html
|
||||||
var cssFile: string;
|
var cssFile: string;
|
||||||
|
|
||||||
const _post = (url: string, data: Object, onreadystatechange: () => void): void => {
|
|
||||||
let req = new XMLHttpRequest();
|
|
||||||
req.open("POST", url, true);
|
|
||||||
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
||||||
req.onreadystatechange = onreadystatechange;
|
|
||||||
req.send(JSON.stringify(data));
|
|
||||||
};
|
|
||||||
|
|
||||||
const _get = (url: string, data: Object, onreadystatechange: () => void): void => {
|
const _get = (url: string, data: Object, onreadystatechange: () => void): void => {
|
||||||
let req = new XMLHttpRequest();
|
let req = new XMLHttpRequest();
|
||||||
req.open("GET", url, true);
|
req.open("GET", url, true);
|
||||||
@ -24,6 +15,24 @@ const _get = (url: string, data: Object, onreadystatechange: () => void): void =
|
|||||||
req.send(JSON.stringify(data));
|
req.send(JSON.stringify(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const _post = (url: string, data: Object, onreadystatechange: () => void): void => {
|
||||||
|
let req = new XMLHttpRequest();
|
||||||
|
req.open("POST", url, true);
|
||||||
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
|
req.onreadystatechange = onreadystatechange;
|
||||||
|
req.send(JSON.stringify(data));
|
||||||
|
};
|
||||||
|
|
||||||
|
function _delete(url: string, data: Object, onreadystatechange: () => void): void {
|
||||||
|
let req = new XMLHttpRequest();
|
||||||
|
req.open("DELETE", url, true);
|
||||||
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
|
req.onreadystatechange = onreadystatechange;
|
||||||
|
req.send(JSON.stringify(data));
|
||||||
|
}
|
||||||
|
|
||||||
const rmAttr = (el: HTMLElement, attr: string): void => {
|
const rmAttr = (el: HTMLElement, attr: string): void => {
|
||||||
if (el.classList.contains(attr)) {
|
if (el.classList.contains(attr)) {
|
||||||
el.classList.remove(attr);
|
el.classList.remove(attr);
|
||||||
@ -222,7 +231,7 @@ function storeDefaults(users: string | Array<string>): void {
|
|||||||
if ((document.getElementById('storeDefaultHomescreen') as HTMLInputElement).checked) {
|
if ((document.getElementById('storeDefaultHomescreen') as HTMLInputElement).checked) {
|
||||||
data["homescreen"] = true;
|
data["homescreen"] = true;
|
||||||
}
|
}
|
||||||
_post("/applySettings", data, function (): void {
|
_post("/users/settings", data, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
if (this.status == 200 || this.status == 204) {
|
if (this.status == 200 || this.status == 204) {
|
||||||
button.textContent = "Success";
|
button.textContent = "Success";
|
||||||
|
@ -65,7 +65,7 @@ function setNotify(el: HTMLElement): void {
|
|||||||
}
|
}
|
||||||
send[code] = {};
|
send[code] = {};
|
||||||
send[code][notifyType] = (el as HTMLInputElement).checked;
|
send[code][notifyType] = (el as HTMLInputElement).checked;
|
||||||
_post("/setNotify", send, function (): void {
|
_post("/invites/notify", send, function (): void {
|
||||||
if (this.readyState == 4 && this.status != 200) {
|
if (this.readyState == 4 && this.status != 200) {
|
||||||
(el as HTMLInputElement).checked = !(el as HTMLInputElement).checked;
|
(el as HTMLInputElement).checked = !(el as HTMLInputElement).checked;
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ function updateInvite(invite: Invite): void {
|
|||||||
const hideInvite = (code: string): void => document.getElementById(CSS.escape(code)).remove();
|
const hideInvite = (code: string): void => document.getElementById(CSS.escape(code)).remove();
|
||||||
|
|
||||||
// delete invite from jfa-go
|
// delete invite from jfa-go
|
||||||
const deleteInvite = (code: string): void => _post("/deleteInvite", { "code": code }, function (): void {
|
const deleteInvite = (code: string): void => _delete("/invites", { "code": code }, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
generateInvites();
|
generateInvites();
|
||||||
}
|
}
|
||||||
@ -229,7 +229,7 @@ function generateInvites(empty?: boolean): void {
|
|||||||
addItem(emptyInvite());
|
addItem(emptyInvite());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_get("/getInvites", null, function (): void {
|
_get("/invites", null, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
let data = this.response;
|
let data = this.response;
|
||||||
availableProfiles = data['profiles'];
|
availableProfiles = data['profiles'];
|
||||||
@ -330,7 +330,7 @@ fixCheckboxes();
|
|||||||
delete send['send_to_address_enabled'];
|
delete send['send_to_address_enabled'];
|
||||||
}
|
}
|
||||||
console.log(send);
|
console.log(send);
|
||||||
_post("/generateInvite", send, function (): void {
|
_post("/invites", send, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
button.textContent = 'Generate';
|
button.textContent = 'Generate';
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
@ -355,7 +355,7 @@ function setProfile(select: HTMLSelectElement): void {
|
|||||||
"invite": invite,
|
"invite": invite,
|
||||||
"profile": val
|
"profile": val
|
||||||
};
|
};
|
||||||
_post("/setProfile", send, function (): void {
|
_post("/invites/profile", send, function (): void {
|
||||||
if (this.readyState == 4 && this.status != 200) {
|
if (this.readyState == 4 && this.status != 200) {
|
||||||
generateInvites();
|
generateInvites();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ const ombiDefaultsModal = createModal('ombiDefaults');
|
|||||||
button.innerHTML =
|
button.innerHTML =
|
||||||
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
|
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
|
||||||
'Loading...';
|
'Loading...';
|
||||||
_get("/getOmbiUsers", null, function (): void {
|
_get("/ombi/users", null, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
if (this.status == 200) {
|
if (this.status == 200) {
|
||||||
const users = this.response['users'];
|
const users = this.response['users'];
|
||||||
@ -52,7 +52,7 @@ const ombiDefaultsModal = createModal('ombiDefaults');
|
|||||||
const data = {
|
const data = {
|
||||||
"id": radio.id.replace("ombiDefault_", "")
|
"id": radio.id.replace("ombiDefault_", "")
|
||||||
};
|
};
|
||||||
_post("/setOmbiDefaults", data, function (): void {
|
_post("/ombi/defaults", data, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
if (this.status == 200 || this.status == 204) {
|
if (this.status == 200 || this.status == 204) {
|
||||||
button.textContent = "Success";
|
button.textContent = "Success";
|
||||||
|
@ -3,7 +3,7 @@ var modifiedConfig: Object = {};
|
|||||||
|
|
||||||
function sendConfig(restart?: boolean): void {
|
function sendConfig(restart?: boolean): void {
|
||||||
modifiedConfig["restart-program"] = restart;
|
modifiedConfig["restart-program"] = restart;
|
||||||
_post("/modifyConfig", modifiedConfig, function (): void {
|
_post("/config", modifiedConfig, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
const save = document.getElementById("settingsSave") as HTMLButtonElement
|
const save = document.getElementById("settingsSave") as HTMLButtonElement
|
||||||
if (this.status == 200 || this.status == 204) {
|
if (this.status == 200 || this.status == 204) {
|
||||||
@ -29,7 +29,7 @@ function sendConfig(restart?: boolean): void {
|
|||||||
aboutModal.show();
|
aboutModal.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
const openSettings = (settingsList: HTMLElement, settingsContent: HTMLElement, callback?: () => void): void => _get("/getConfig", null, function (): void {
|
const openSettings = (settingsList: HTMLElement, settingsContent: HTMLElement, callback?: () => void): void => _get("/config", null, function (): void {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
settingsList.textContent = '';
|
settingsList.textContent = '';
|
||||||
config = this.response;
|
config = this.response;
|
||||||
@ -139,7 +139,7 @@ interface Profile {
|
|||||||
|
|
||||||
(document.getElementById('profiles_button') as HTMLButtonElement).onclick = (): void => showSetting("profiles", populateProfiles);
|
(document.getElementById('profiles_button') as HTMLButtonElement).onclick = (): void => showSetting("profiles", populateProfiles);
|
||||||
|
|
||||||
const populateProfiles = (noTable?: boolean): void => _get("/getProfiles", null, function (): void {
|
const populateProfiles = (noTable?: boolean): void => _get("/profiles", null, function (): void {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
const profileList = document.getElementById('profileList');
|
const profileList = document.getElementById('profileList');
|
||||||
profileList.textContent = '';
|
profileList.textContent = '';
|
||||||
@ -167,7 +167,7 @@ const populateProfiles = (noTable?: boolean): void => _get("/getProfiles", null,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const setDefaultProfile = (name: string): void => _post("/setDefaultProfile", { "name": name }, function (): void {
|
const setDefaultProfile = (name: string): void => _post("/profiles/default", { "name": name }, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
if (this.status != 200) {
|
if (this.status != 200) {
|
||||||
(document.getElementById(`defaultProfile_${availableProfiles[0]}`) as HTMLInputElement).checked = true;
|
(document.getElementById(`defaultProfile_${availableProfiles[0]}`) as HTMLInputElement).checked = true;
|
||||||
@ -178,13 +178,13 @@ const setDefaultProfile = (name: string): void => _post("/setDefaultProfile", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const deleteProfile = (name: string): void => _post("/deleteProfile", { "name": name }, function (): void {
|
const deleteProfile = (name: string): void => _delete("/profiles", { "name": name }, function (): void {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
populateProfiles();
|
populateProfiles();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const createProfile = (): void => _get("/getUsers", null, function (): void {
|
const createProfile = (): void => _get("/users", null, function (): void {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
jfUsers = this.response["users"];
|
jfUsers = this.response["users"];
|
||||||
populateRadios();
|
populateRadios();
|
||||||
@ -225,7 +225,7 @@ function storeProfile(): void {
|
|||||||
if ((document.getElementById('storeDefaultHomescreen') as HTMLInputElement).checked) {
|
if ((document.getElementById('storeDefaultHomescreen') as HTMLInputElement).checked) {
|
||||||
data["homescreen"] = true;
|
data["homescreen"] = true;
|
||||||
}
|
}
|
||||||
_post("/createProfile", data, function (): void {
|
_post("/profiles", data, function (): void {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
if (this.status == 200 || this.status == 204) {
|
if (this.status == 200 || this.status == 204) {
|
||||||
button.textContent = "Success";
|
button.textContent = "Success";
|
||||||
|
Loading…
Reference in New Issue
Block a user