1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
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}/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";
}
}
}
|