const API_URL = "https://backend.laundryweb.altafcreator.com" async function login() { const field = document.getElementById("pwfield"); const response = await fetch(`${API_URL}/admin_login`, { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: `{"password": "${field.value}"}`, }); if (response.status == 202) window.location.href = "./panel.html"; else document.getElementById("passwordFeedback").style.display = "inherit"; } async function checkLoginStatus() { const response = await fetch(`${API_URL}/admin_check`, { method: "POST", credentials: "include" }); 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}/override_status`, { 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"; } } }