diff options
Diffstat (limited to 'web/share/js/index/main.js')
-rw-r--r-- | web/share/js/index/main.js | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/web/share/js/index/main.js b/web/share/js/index/main.js index 8f5c74a6..f42b9af6 100644 --- a/web/share/js/index/main.js +++ b/web/share/js/index/main.js @@ -1,4 +1,8 @@ +var wm; + function main() { + wm = new WindowManager(); + if (checkBrowser()) { __setAppText(); __loadKvmdInfo(); @@ -36,20 +40,12 @@ function __loadKvmdInfo() { $("apps-box").innerHTML = "<ul id=\"apps\"></ul>"; apps.forEach(function(app) { - $("apps").innerHTML += ` - <li> - <div class="app"> - <a href="${app.path}"> - <div> - <img class="svg-gray" src="${app.icon}"> - ${app.name} - </div> - </a> - </div> - </li> - `; + $("apps").innerHTML += __makeApp(null, app.path, app.icon, app.name); }); + $("apps").innerHTML += __makeApp("logout-button", "#", "share/svg/logout.svg", "Logout"); + tools.setOnClick($("logout-button"), __logout); + if (info.meta && info.meta.server && info.meta.server.host) { $("kvmd-meta-server-host").innerHTML = info.meta.server.host; document.title = "Pi-KVM Index: " + info.meta.server.host; @@ -63,3 +59,28 @@ function __loadKvmdInfo() { } }); } + +function __makeApp(id, path, icon, name) { + return `<li> + <div ${id ? "id=\"" + id + "\"" : ""} class="app"> + <a href="${path}"> + <div> + <img class="svg-gray" src="${icon}"> + ${name} + </div> + </a> + </div> + </li>`; +} + +function __logout() { + var http = tools.makeRequest("POST", "/kvmd/auth/logout", function() { + if (http.readyState === 4) { + if (http.status === 200) { + document.location.href = "/login"; + } else { + wm.error("Logout error:<br>", http.responseText); + } + } + }); +} |