diff options
author | Devaev Maxim <[email protected]> | 2018-12-16 04:13:19 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-12-16 04:13:19 +0300 |
commit | 6626e514b391d672a6352bbd965a1b3d671ed487 (patch) | |
tree | 3097483623d03dfc48de8613bab9655ca130f57d /web/share/js/index/main.js | |
parent | d7fb06d22ebfad8134c5d1a1e2bd6f6001baf8c4 (diff) |
logout
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); + } + } + }); +} |