define class for AdminPanel

This commit is contained in:
Lukas-Heiligenbrunner 2020-02-10 11:16:44 +01:00
parent 1238a121f4
commit 7e8a857caf
2 changed files with 38 additions and 27 deletions

View File

@ -1,34 +1,45 @@
$(document).ready(function () { $(document).ready(function () {
console.log("page loaded"); new AdminPanel();
$.post('/senddata/checkloginstate', 'action=getloginstate', function (data) { });
console.log(data);
if (data.loggedin == true) { class AdminPanel {
$("#userlabel").html(" " + data.username); constructor() {
if (data.permission > 0) { this.checkLoginState();
$("#adminpanel").show(); this.addClickListeners();
}
checkLoginState(){
$.post('/senddata/checkloginstate', 'action=getloginstate', function (data) {
console.log(data);
if (data.loggedin == true) {
$("#userlabel").html(" " + data.username);
if (data.permission > 0) {
$("#adminpanel").show();
}
} else {
$("#userlabel").html(" not logged in!!");
} }
} else {
$("#userlabel").html(" not logged in!!");
}
}, 'json');
$("#btn-shutdown").click(function (event) {
console.log("shutting down server");
$.post('/senddata/admindata', 'action=shutdownserver', function (data) {
console.log(data);
}, 'json'); }, 'json');
}
}); addClickListeners(){
$("#btn-shutdown").click(function (event) {
console.log("shutting down server");
$("#btn-restart").click(function (event) { $.post('/senddata/admindata', 'action=shutdownserver', function (data) {
console.log("restarting server"); console.log(data);
$.post('/senddata/admindata', 'action=restartserver', function (data) { }, 'json');
console.log(data);
}, 'json'); });
});
}); $("#btn-restart").click(function (event) {
console.log("restarting server");
$.post('/senddata/admindata', 'action=restartserver', function (data) {
console.log(data);
}, 'json');
});
}
}