diff options
| author | altaf-creator <dev@altafcreator.com> | 2026-01-23 09:50:33 +0800 |
|---|---|---|
| committer | altaf-creator <dev@altafcreator.com> | 2026-01-23 09:50:33 +0800 |
| commit | e5d96d19292224ea9513e145b02e35338eff0857 (patch) | |
| tree | 1ef0e0f362b1bbcddd661f19e22493282fd49316 /frontend/admin/admin.js | |
| parent | aab0cbcfcd8699c9715196b2d2b948011be58642 (diff) | |
machine override status
Diffstat (limited to 'frontend/admin/admin.js')
| -rw-r--r-- | frontend/admin/admin.js | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/frontend/admin/admin.js b/frontend/admin/admin.js index bc31007..8a4a331 100644 --- a/frontend/admin/admin.js +++ b/frontend/admin/admin.js @@ -11,6 +11,9 @@ async function login() { }, body: `{"password": "${field.value}"}`, }); + + if (response.status == 202) window.location.href = "./panel.html"; + else document.getElementById("passwordFeedback").style.display = "inherit"; } async function checkLoginStatus() { @@ -18,5 +21,57 @@ async function checkLoginStatus() { method: "POST", credentials: "include" }); - console.log(response); + + return response.status == 202; +} + +async function autoLogin() { + if (await checkLoginStatus()) { + window.location.href = "./panel.html"; + } +} + +async function panelLoginCheck() { + const msg = document.getElementById("unauthorised"); + const authDiv = document.getElementById("authorised"); + + if (await checkLoginStatus()) { + msg.style.display = "none"; + authDiv.style.display = "inherit"; + } else { + msg.style.display = "inherit"; + authDiv.style.display = "none"; + } +} + +async function overrideMachineStatus(block, machine) { + const img = document.getElementById("h"+block.toString()+"m"+machine.toString()+"img"); + const dropdown = document.getElementById("h"+block.toString()+"m"+machine.toString()); + + const response = await fetch(`${API_URL}/admin_login`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json" + }, + body: `{"block": ${block}, "machine_id": ${machine}, "disabled": ${dropdown.selectedIndex == 1}`, + }); + + if (response.status != 200) { + return; + } + + if (dropdown.selectedIndex == 1) { + if (machine % 2 == 0) { + img.src = "/assets/img/washer_down.png"; + } else { + img.src = "/assets/img/dryer_down.png"; + } + } else { + if (machine % 2 == 0) { + img.src = "/assets/img/washer_off.png"; + } else { + img.src = "/assets/img/dryer_off.png"; + } + } } |
