web-base/js/admin.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-02-10 00:52:25 +01:00
$(document).ready(function() {
2020-04-04 01:15:59 +02:00
// Login
2020-02-10 00:52:25 +01:00
$("#username").keypress(function(e) { if(e.which == 13) $("#password").focus(); });
$("#password").keypress(function(e) { if(e.which == 13) $("#btnLogin").click(); });
$("#btnLogin").click(function() {
2020-04-03 22:10:21 +02:00
const username = $("#username").val();
const password = $("#password").val();
const errorDiv = $("#loginError");
const createdDiv = $("#accountCreated");
const stayLoggedIn = $("#stayLoggedIn").is(":checked");
const btn = $(this);
2020-02-10 00:52:25 +01:00
errorDiv.hide();
btn.prop("disabled", true);
btn.html("Logging in… <i class=\"fa fa-spin fa-circle-notch\"></i>");
2020-04-03 22:10:21 +02:00
jsCore.apiCall("/user/login", {"username": username, "password": password, "stayLoggedIn": stayLoggedIn }, function(data) {
2020-02-10 00:52:25 +01:00
window.location.reload();
}, function(err) {
btn.html("Login");
btn.prop("disabled", false);
$("#password").val("");
createdDiv.hide();
errorDiv.html(err);
errorDiv.show();
});
});
2020-04-03 22:10:21 +02:00
2020-04-04 01:15:59 +02:00
$("#userTableRefresh").click(function() {
let tbody = $("#userTable > tbody");
let page = parseInt($("#userPageNavigation li.active > a").text().trim());
tbody.find("tr").remove();
tbody.append("<tr><td colspan=\"4\" class=\"text-center\">Loading… " + createLoadingIcon() + "</td></tr>");
jsCore.apiCall("/user/fetch", { page: page}, function (data) {
let pageCount = data["pages"];
let users = data["users"];
let userRows = [];
// TODO: .. maybe use ts instead of plain js?
for(let userId in users) {
let user = users[userId];
userRows.push("<tr><td>" + user.name + "</td><td>" + user.email + "</td><td></td><td></td></tr>");
}
tbody.html(userRows.join(""));
}, function (err) {
alert(err);
});
2020-04-03 22:10:21 +02:00
});
2020-04-04 15:11:38 +02:00
$("#btnLogout").click(function() {
jsCore.apiCall("/user/logout", function(data) {
document.location = "/admin";
}, function(err) {
alert("err");
});
});
2020-02-10 00:52:25 +01:00
});