mirror of
https://github.com/hrfee/jellyfin-accounts.git
synced 2024-12-22 17:10:11 +00:00
no more jQuery on admin page
Functions well, but a few changes might be necessary visually.
This commit is contained in:
parent
fe12b7c4be
commit
d1cd83f5ff
@ -1,3 +1,9 @@
|
|||||||
|
var loginModal = new bootstrap.Modal(document.getElementById('login'));
|
||||||
|
var settingsModal = new bootstrap.Modal(document.getElementById('settingsMenu'));
|
||||||
|
var userDefaultsModal = new bootstrap.Modal(document.getElementById('userDefaults'));
|
||||||
|
var usersModal = new bootstrap.Modal(document.getElementById('users'));
|
||||||
|
var restartModal = new bootstrap.Modal(document.getElementById('restartModal'));
|
||||||
|
|
||||||
function parseInvite(invite, empty = false) {
|
function parseInvite(invite, empty = false) {
|
||||||
if (empty === true) {
|
if (empty === true) {
|
||||||
return ["None", "", "1"]
|
return ["None", "", "1"]
|
||||||
@ -70,19 +76,13 @@ function removeInvite(code) {
|
|||||||
function generateInvites(empty = false) {
|
function generateInvites(empty = false) {
|
||||||
// document.getElementById('invites').textContent = '';
|
// document.getElementById('invites').textContent = '';
|
||||||
if (empty === false) {
|
if (empty === false) {
|
||||||
$.ajax('/getInvites', {
|
var req = new XMLHttpRequest();
|
||||||
type : 'GET',
|
req.open("GET", "/getInvites", true);
|
||||||
dataType : 'json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
contentType: 'json',
|
req.responseType = 'json';
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4) {
|
||||||
},
|
var data = this.response;
|
||||||
beforeSend : function (xhr) {
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
},
|
|
||||||
data: { get_param: 'value' },
|
|
||||||
complete: function(response) {
|
|
||||||
var data = JSON.parse(response['responseText']);
|
|
||||||
if (data['invites'].length == 0) {
|
if (data['invites'].length == 0) {
|
||||||
document.getElementById('invites').textContent = '';
|
document.getElementById('invites').textContent = '';
|
||||||
addItem(parseInvite([], true));
|
addItem(parseInvite([], true));
|
||||||
@ -113,8 +113,9 @@ function generateInvites(empty = false) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
});
|
};
|
||||||
|
req.send();
|
||||||
} else if (empty === true) {
|
} else if (empty === true) {
|
||||||
document.getElementById('invites').textContent = '';
|
document.getElementById('invites').textContent = '';
|
||||||
addItem(parseInvite([], true));
|
addItem(parseInvite([], true));
|
||||||
@ -122,25 +123,23 @@ function generateInvites(empty = false) {
|
|||||||
};
|
};
|
||||||
function deleteInvite(code) {
|
function deleteInvite(code) {
|
||||||
var send = JSON.stringify({ "code": code });
|
var send = JSON.stringify({ "code": code });
|
||||||
$.ajax('/deleteInvite', {
|
var req = new XMLHttpRequest();
|
||||||
data : send,
|
req.open("POST", "/deleteInvite", true);
|
||||||
contentType : 'application/json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
type : 'POST',
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4) {
|
||||||
},
|
generateInvites();
|
||||||
beforeSend : function (xhr) {
|
};
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
};
|
||||||
},
|
req.send(send);
|
||||||
success: function() { generateInvites(); },
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
function addOptions(le, sel) {
|
function addOptions(le, sel) {
|
||||||
for (v = 0; v <= le; v++) {
|
for (v = 0; v <= le; v++) {
|
||||||
var opt = document.createElement('option');
|
var opt = document.createElement('option');
|
||||||
opt.appendChild(document.createTextNode(v))
|
opt.appendChild(document.createTextNode(v));
|
||||||
opt.value = v
|
opt.value = v;
|
||||||
sel.appendChild(opt)
|
sel.appendChild(opt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function toClipboard(str) {
|
function toClipboard(str) {
|
||||||
@ -162,41 +161,65 @@ function toClipboard(str) {
|
|||||||
document.getSelection().addRange(selected);
|
document.getSelection().addRange(selected);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function serializeForm(id) {
|
||||||
|
var form = document.getElementById(id);
|
||||||
|
var formData = {};
|
||||||
|
for (var i = 0; i < form.elements.length; i++) {
|
||||||
|
var el = form.elements[i];
|
||||||
|
if (el.type != 'submit') {
|
||||||
|
var name = el.name;
|
||||||
|
if (name == '') {
|
||||||
|
name = el.id;
|
||||||
|
};
|
||||||
|
switch (el.type) {
|
||||||
|
case 'checkbox':
|
||||||
|
formData[name] = el.checked;
|
||||||
|
break;
|
||||||
|
case 'text':
|
||||||
|
case 'password':
|
||||||
|
case 'select-one':
|
||||||
|
case 'email':
|
||||||
|
formData[name] = el.value;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return formData;
|
||||||
|
};
|
||||||
document.getElementById('inviteForm').onsubmit = function() {
|
document.getElementById('inviteForm').onsubmit = function() {
|
||||||
var button = document.getElementById('generateSubmit');
|
var button = document.getElementById('generateSubmit');
|
||||||
button.disabled = true;
|
button.disabled = true;
|
||||||
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...';
|
||||||
var send_object = $("form#inviteForm").serializeObject();
|
send_object = serializeForm('inviteForm');
|
||||||
|
console.log(send_object);
|
||||||
if (document.getElementById('send_to_address') != null) {
|
if (document.getElementById('send_to_address') != null) {
|
||||||
if (document.getElementById('send_to_address_enabled').checked) {
|
if (send_object['send_to_address_enabled']) {
|
||||||
send_object['email'] = document.getElementById('send_to_address').value;
|
send_object['email'] = send_object['send_to_address'];
|
||||||
|
delete send_object['send_to_address'];
|
||||||
|
delete send_object['send_to_address_enabled'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var send = JSON.stringify(send_object);
|
var send = JSON.stringify(send_object);
|
||||||
$.ajax('/generateInvite', {
|
var req = new XMLHttpRequest();
|
||||||
data : send,
|
req.open("POST", "/generateInvite", true);
|
||||||
contentType : 'application/json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
type : 'POST',
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4) {
|
||||||
},
|
|
||||||
beforeSend : function (xhr) {
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
},
|
|
||||||
success: function() {
|
|
||||||
button.textContent = 'Generate';
|
button.textContent = 'Generate';
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
generateInvites();
|
generateInvites();
|
||||||
},
|
};
|
||||||
|
};
|
||||||
});
|
req.send(send);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
$("form#loginForm").submit(function() {
|
document.getElementById('loginForm').onsubmit = function() {
|
||||||
window.token = "";
|
window.token = "";
|
||||||
var details = $("form#loginForm").serializeObject();
|
var details = serializeForm('loginForm');
|
||||||
var errorArea = document.getElementById('loginErrorArea');
|
var errorArea = document.getElementById('loginErrorArea');
|
||||||
errorArea.textContent = '';
|
errorArea.textContent = '';
|
||||||
var button = document.getElementById('loginSubmit');
|
var button = document.getElementById('loginSubmit');
|
||||||
@ -204,19 +227,11 @@ $("form#loginForm").submit(function() {
|
|||||||
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...';
|
||||||
$.ajax('/getToken', {
|
var req = new XMLHttpRequest();
|
||||||
type : 'GET',
|
req.responseType = 'json';
|
||||||
dataType : 'json',
|
req.onreadystatechange = function() {
|
||||||
contentType: 'json',
|
if (this.readyState == 4) {
|
||||||
xhrFields : {
|
if (this.status == 401) {
|
||||||
withCredentials: true
|
|
||||||
},
|
|
||||||
beforeSend : function (xhr) {
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(details['username'] + ":" + details['password']));
|
|
||||||
},
|
|
||||||
data: { get_param: 'value' },
|
|
||||||
complete: function(data) {
|
|
||||||
if (data['status'] == 401) {
|
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
button.textContent = 'Login';
|
button.textContent = 'Login';
|
||||||
var wrongPassword = document.createElement('div');
|
var wrongPassword = document.createElement('div');
|
||||||
@ -225,7 +240,8 @@ $("form#loginForm").submit(function() {
|
|||||||
wrongPassword.appendChild(document.createTextNode('Incorrect username or password.'));
|
wrongPassword.appendChild(document.createTextNode('Incorrect username or password.'));
|
||||||
errorArea.appendChild(wrongPassword);
|
errorArea.appendChild(wrongPassword);
|
||||||
} else {
|
} else {
|
||||||
window.token = JSON.parse(data['responseText'])['token'];
|
var data = this.response;
|
||||||
|
window.token = data['token'];
|
||||||
generateInvites();
|
generateInvites();
|
||||||
var interval = setInterval(function() { generateInvites(); }, 60 * 1000);
|
var interval = setInterval(function() { generateInvites(); }, 60 * 1000);
|
||||||
var hour = document.getElementById('hours');
|
var hour = document.getElementById('hours');
|
||||||
@ -234,35 +250,33 @@ $("form#loginForm").submit(function() {
|
|||||||
var minutes = document.getElementById('minutes');
|
var minutes = document.getElementById('minutes');
|
||||||
addOptions(59, minutes);
|
addOptions(59, minutes);
|
||||||
minutes.selected = "30";
|
minutes.selected = "30";
|
||||||
$('#login').modal('hide');
|
loginModal.hide();
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
});
|
};
|
||||||
|
req.open("GET", "/getToken", true);
|
||||||
|
req.setRequestHeader("Authorization", "Basic " + btoa(details['username'] + ":" + details['password']));
|
||||||
|
req.send();
|
||||||
return false;
|
return false;
|
||||||
});
|
};
|
||||||
document.getElementById('openDefaultsWizard').onclick = function () {
|
document.getElementById('openDefaultsWizard').onclick = function() {
|
||||||
this.disabled = true;
|
this.disabled = true
|
||||||
this.innerHTML =
|
this.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...';
|
||||||
$.ajax('getUsers', {
|
var req = new XMLHttpRequest();
|
||||||
type : 'GET',
|
req.responseType = 'json';
|
||||||
dataType : 'json',
|
req.open("GET", "/getUsers", true);
|
||||||
contentType : 'json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4) {
|
||||||
},
|
if (this.status == 200) {
|
||||||
beforeSend : function (xhr) {
|
var users = req.response['users'];
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
},
|
|
||||||
complete : function(data) {
|
|
||||||
if (data['status'] == 200) {
|
|
||||||
var radioList = document.getElementById('defaultUserRadios');
|
var radioList = document.getElementById('defaultUserRadios');
|
||||||
radioList.textContent = '';
|
radioList.textContent = '';
|
||||||
if (document.getElementById('setDefaultUser')) {
|
if (document.getElementById('setDefaultUser')) {
|
||||||
document.getElementById('setDefaultUser').remove();
|
document.getElementById('setDefaultUser').remove();
|
||||||
};
|
};
|
||||||
var users = data['responseJSON']['users'];
|
|
||||||
for (var i = 0; i < users.length; i++) {
|
for (var i = 0; i < users.length; i++) {
|
||||||
var user = users[i]
|
var user = users[i]
|
||||||
var radio = document.createElement('div');
|
var radio = document.createElement('div');
|
||||||
@ -291,11 +305,12 @@ document.getElementById('openDefaultsWizard').onclick = function () {
|
|||||||
submitButton.classList.remove('btn-danger');
|
submitButton.classList.remove('btn-danger');
|
||||||
submitButton.classList.add('btn-primary');
|
submitButton.classList.add('btn-primary');
|
||||||
};
|
};
|
||||||
$('#settingsMenu').modal('hide');
|
settingsModal.hide();
|
||||||
$('#userDefaults').modal('show');
|
userDefaultsModal.show();
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
});
|
};
|
||||||
|
req.send();
|
||||||
};
|
};
|
||||||
document.getElementById('storeDefaults').onclick = function () {
|
document.getElementById('storeDefaults').onclick = function () {
|
||||||
this.disabled = true;
|
this.disabled = true;
|
||||||
@ -310,17 +325,13 @@ document.getElementById('storeDefaults').onclick = function () {
|
|||||||
if (document.getElementById('storeDefaultHomescreen').checked) {
|
if (document.getElementById('storeDefaultHomescreen').checked) {
|
||||||
data['homescreen'] = true;
|
data['homescreen'] = true;
|
||||||
}
|
}
|
||||||
$.ajax('/setDefaults', {
|
var req = new XMLHttpRequest();
|
||||||
data : JSON.stringify(data),
|
req.open("POST", "/setDefaults", true);
|
||||||
contentType : 'application/json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
type : 'POST',
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4) {
|
||||||
},
|
if (this.status == 200 || this.status == 204) {
|
||||||
beforeSend : function (xhr) {
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
},
|
|
||||||
success: function() {
|
|
||||||
button.textContent = 'Success';
|
button.textContent = 'Success';
|
||||||
if (button.classList.contains('btn-danger')) {
|
if (button.classList.contains('btn-danger')) {
|
||||||
button.classList.remove('btn-danger');
|
button.classList.remove('btn-danger');
|
||||||
@ -330,10 +341,8 @@ document.getElementById('storeDefaults').onclick = function () {
|
|||||||
button.classList.add('btn-success');
|
button.classList.add('btn-success');
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
setTimeout(function(){$('#userDefaults').modal('hide');}, 1000);
|
setTimeout(function(){$('#userDefaults').modal('hide');}, 1000);
|
||||||
},
|
} else {
|
||||||
error: function() {
|
|
||||||
button.textContent = 'Failed';
|
button.textContent = 'Failed';
|
||||||
config_base_path = local_dir / "config-base.json"
|
|
||||||
button.classList.remove('btn-primary');
|
button.classList.remove('btn-primary');
|
||||||
button.classList.add('btn-danger');
|
button.classList.add('btn-danger');
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
@ -343,35 +352,69 @@ document.getElementById('storeDefaults').onclick = function () {
|
|||||||
button.classList.add('btn-primary');
|
button.classList.add('btn-primary');
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
};
|
||||||
});
|
};
|
||||||
}
|
};
|
||||||
}
|
req.send(JSON.stringify(data));
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// $.ajax('/setDefaults', {
|
||||||
|
// data : JSON.stringify(data),
|
||||||
|
// contentType : 'application/json',
|
||||||
|
// type : 'POST',
|
||||||
|
// xhrFields : {
|
||||||
|
// withCredentials: true
|
||||||
|
// },
|
||||||
|
// beforeSend : function (xhr) {
|
||||||
|
// xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
|
// },
|
||||||
|
// success: function() {
|
||||||
|
// button.textContent = 'Success';
|
||||||
|
// if (button.classList.contains('btn-danger')) {
|
||||||
|
// button.classList.remove('btn-danger');
|
||||||
|
// } else if (button.classList.contains('btn-primary')) {
|
||||||
|
// button.classList.remove('btn-primary');
|
||||||
|
// };
|
||||||
|
// button.classList.add('btn-success');
|
||||||
|
// button.disabled = false;
|
||||||
|
// setTimeout(function(){$('#userDefaults').modal('hide');}, 1000);
|
||||||
|
// },
|
||||||
|
// error: function() {
|
||||||
|
// button.textContent = 'Failed';
|
||||||
|
// button.classList.remove('btn-primary');
|
||||||
|
// button.classList.add('btn-danger');
|
||||||
|
// setTimeout(function(){
|
||||||
|
// var button = document.getElementById('storeDefaults');
|
||||||
|
// button.textContent = 'Submit';
|
||||||
|
// button.classList.remove('btn-danger');
|
||||||
|
// button.classList.add('btn-primary');
|
||||||
|
// button.disabled = false;
|
||||||
|
// }, 1000);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
document.getElementById('openUsers').onclick = function () {
|
document.getElementById('openUsers').onclick = function () {
|
||||||
this.disabled = true;
|
this.disabled = true;
|
||||||
this.innerHTML =
|
this.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...';
|
||||||
$.ajax('/getUsers', {
|
var req = new XMLHttpRequest();
|
||||||
type : 'GET',
|
req.open("GET", "/getUsers", true);
|
||||||
dataType : 'json',
|
req.responseType = 'json';
|
||||||
contentType: 'json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4) {
|
||||||
},
|
if (this.status == 200) {
|
||||||
beforeSend : function (xhr) {
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
},
|
|
||||||
data: { get_param: 'value' },
|
|
||||||
complete : function(data) {
|
|
||||||
if (data['status'] == 200) {
|
|
||||||
var list = document.getElementById('userList');
|
var list = document.getElementById('userList');
|
||||||
list.textContent = '';
|
list.textContent = '';
|
||||||
if (document.getElementById('saveUsers')) {
|
if (document.getElementById('saveUsers')) {
|
||||||
document.getElementById('saveUsers').remove();
|
document.getElementById('saveUsers').remove();
|
||||||
};
|
};
|
||||||
var users = data['responseJSON']['users'];
|
var users = req.response['users'];
|
||||||
for (var i = 0; i < users.length; i++) {
|
for (var i = 0; i < users.length; i++) {
|
||||||
var user = users[i]
|
var user = users[i]
|
||||||
var entry = document.createElement('p');
|
var entry = document.createElement('p');
|
||||||
@ -417,18 +460,18 @@ document.getElementById('openUsers').onclick = function () {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
send = JSON.stringify(send);
|
send = JSON.stringify(send);
|
||||||
$.ajax('/modifyUsers', {
|
var req = new XMLHttpRequest();
|
||||||
data : send,
|
req.open("POST", "/modifyUsers", true);
|
||||||
contentType : 'application/json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
type : 'POST',
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4) {
|
||||||
},
|
if (this.status == 200 || this.status == 204) {
|
||||||
beforeSend : function (xhr) {
|
usersModal.hide();
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
};
|
||||||
},
|
};
|
||||||
success: function() { $('#users').modal('hide'); },
|
};
|
||||||
});
|
req.send(send);
|
||||||
};
|
};
|
||||||
footer.appendChild(saveUsers);
|
footer.appendChild(saveUsers);
|
||||||
};
|
};
|
||||||
@ -440,35 +483,31 @@ document.getElementById('openUsers').onclick = function () {
|
|||||||
var button = document.getElementById('openUsers');
|
var button = document.getElementById('openUsers');
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
button.innerHTML = 'Users <i class="fa fa-user"></i>';
|
button.innerHTML = 'Users <i class="fa fa-user"></i>';
|
||||||
$('#settingsMenu').modal('hide');
|
settingsModal.hide();
|
||||||
$('#users').modal('show');
|
usersModal.show();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
req.send();
|
||||||
};
|
};
|
||||||
|
|
||||||
generateInvites(empty = true);
|
generateInvites(empty = true);
|
||||||
$("#login").modal('show');
|
loginModal.show()
|
||||||
|
|
||||||
var config = {};
|
var config = {};
|
||||||
var modifiedConfig = {};
|
var modifiedConfig = {};
|
||||||
|
|
||||||
document.getElementById('openSettings').onclick = function () {
|
document.getElementById('openSettings').onclick = function () {
|
||||||
restart_setting_changed = false;
|
restart_setting_changed = false;
|
||||||
$.ajax('getConfig', {
|
var req = new XMLHttpRequest();
|
||||||
type : 'GET',
|
req.open("GET", "/getConfig", true);
|
||||||
dataType : 'json',
|
req.responseType = 'json';
|
||||||
contentType : 'json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
},
|
|
||||||
beforeSend : function (xhr) {
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
},
|
|
||||||
complete : function(data) {
|
|
||||||
if (data['status'] == 200) {
|
|
||||||
var settingsList = document.getElementById('settingsList');
|
var settingsList = document.getElementById('settingsList');
|
||||||
settingsList.textContent = '';
|
settingsList.textContent = '';
|
||||||
config = data['responseJSON'];
|
config = this.response;
|
||||||
for (var section of Object.keys(config)) {
|
for (var section of Object.keys(config)) {
|
||||||
var sectionCollapse = document.createElement('div');
|
var sectionCollapse = document.createElement('div');
|
||||||
sectionCollapse.classList.add('collapse');
|
sectionCollapse.classList.add('collapse');
|
||||||
@ -578,45 +617,50 @@ document.getElementById('openSettings').onclick = function () {
|
|||||||
settingsList.appendChild(sectionCollapse);
|
settingsList.appendChild(sectionCollapse);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
},
|
};
|
||||||
});
|
req.send();
|
||||||
$('#settingsMenu').modal('show');
|
settingsModal.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#settingsMenu').on('shown.bs.modal', function() {
|
document.getElementById('settingsMenu').addEventListener('shown.bs.modal', function() {
|
||||||
$("a[data-toggle='tooltip']").each(function (i, obj) {
|
var to_trigger = [].slice.call(document.querySelectorAll('a[data-toggle="tooltip"]'));
|
||||||
$(obj).tooltip();
|
var tooltips = to_trigger.map(function(el) {
|
||||||
|
return new bootstrap.Tooltip(el);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
//
|
||||||
|
// $('#settingsMenu').on('shown.bs.modal', function() {
|
||||||
|
// $("a[data-toggle='tooltip']").each(function (i, obj) {
|
||||||
|
// $(obj).tooltip();
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
//
|
||||||
function sendConfig(modalId) {
|
function sendConfig(modalId) {
|
||||||
var modal = document.getElementById(modalId);
|
var modal = document.getElementById(modalId);
|
||||||
var send = JSON.stringify(modifiedConfig);
|
var send = JSON.stringify(modifiedConfig);
|
||||||
$.ajax('/modifyConfig', {
|
var req = new XMLHttpRequest();
|
||||||
data : send,
|
req.open("POST", "/modifyConfig", true);
|
||||||
contentType : 'application/json',
|
req.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
||||||
type : 'POST',
|
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||||
xhrFields : {
|
req.onreadystatechange = function() {
|
||||||
withCredentials: true
|
if (this.readyState == 4) {
|
||||||
},
|
if (this.status == 200 || this.status == 204) {
|
||||||
beforeSend : function (xhr) {
|
bootstrap.Modal.getInstance(document.getElementById(modalId)).hide();
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
|
|
||||||
},
|
|
||||||
success: function() {
|
|
||||||
$('#' + modalId).modal('hide');
|
|
||||||
if (modalId != 'settingsMenu') {
|
if (modalId != 'settingsMenu') {
|
||||||
$('#settingsMenu').modal('hide');
|
settingsModal.hide();
|
||||||
};
|
};
|
||||||
},
|
};
|
||||||
fail: function(xhr, textStatus, errorThrown) {
|
};
|
||||||
var footer = modal.getElementsByClassName('modal-dialog')[0].getElementsByClassName('modal-content')[0].getElementsByClassName('modal-footer')[0];
|
// fail: function(xhr, textStatus, errorThrown) {
|
||||||
var alert = document.createElement('div');
|
// var footer = modal.getElementsByClassName('modal-dialog')[0].getElementsByClassName('modal-content')[0].getElementsByClassName('modal-footer')[0];
|
||||||
alert.classList.add('alert', 'alert-danger');
|
// var alert = document.createElement('div');
|
||||||
alert.setAttribute('role', 'alert');
|
// alert.classList.add('alert', 'alert-danger');
|
||||||
alert.appendChild(document.createTextNode('Error: ' + errorThrown));
|
// alert.setAttribute('role', 'alert');
|
||||||
footer.appendChild(alert);
|
// alert.appendChild(document.createTextNode('Error: ' + errorThrown));
|
||||||
},
|
// footer.appendChild(alert);
|
||||||
});
|
// },
|
||||||
|
};
|
||||||
|
req.send(send);
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementById('settingsSave').onclick = function() {
|
document.getElementById('settingsSave').onclick = function() {
|
||||||
@ -650,15 +694,12 @@ document.getElementById('settingsSave').onclick = function() {
|
|||||||
// if (restart_setting_changed) {
|
// if (restart_setting_changed) {
|
||||||
if (restart_setting_changed) {
|
if (restart_setting_changed) {
|
||||||
document.getElementById('applyRestarts').onclick = function(){sendConfig('restartModal');};
|
document.getElementById('applyRestarts').onclick = function(){sendConfig('restartModal');};
|
||||||
$('#settingsMenu').modal('hide');
|
settingsModal.hide();
|
||||||
$('#restartModal').modal({
|
restartModal.show();
|
||||||
backdrop: 'static',
|
|
||||||
show: true
|
|
||||||
});
|
|
||||||
} else if (settings_changed) {
|
} else if (settings_changed) {
|
||||||
sendConfig('settingsMenu');
|
sendConfig('settingsMenu');
|
||||||
} else {
|
} else {
|
||||||
$('#settingsMenu').modal('hide');
|
settingsModal.hide();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
<title>Admin</title>
|
<title>Admin</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="login" aria-hidden="true" data-backdrop="static">
|
<div class="modal fade" id="login" role="dialog" aria-labelledby="login" aria-hidden="true" data-backdrop="static">
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@ -79,7 +79,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal fade" id="settingsMenu" tabindex="-1" role="dialog" aria-labelledby="settings menu" aria-hidden="true">
|
<div class="modal fade" id="settingsMenu" role="dialog" aria-labelledby="settings menu" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@ -108,7 +108,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal fade" id="users" tabindex="-1" role="dialog" aria-labelledby="users" aria-hidden="true">
|
<div class="modal fade" id="users" role="dialog" aria-labelledby="users" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@ -127,7 +127,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal fade" id="userDefaults" tabindex="-1" role="dialog" aria-labelledby="users" aria-hidden="true">
|
<div class="modal fade" id="userDefaults" role="dialog" aria-labelledby="users" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@ -150,7 +150,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal fade" id="restartModal" tabindex="-1" role="dialog" aria-labelledby"Restart Warning" aria-hidden="true">
|
<div class="modal fade" id="restartModal" role="dialog" aria-labelledby"Restart Warning" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
Loading…
Reference in New Issue
Block a user