-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathveranstaltungsleitenden-portal.js
More file actions
47 lines (43 loc) · 1.66 KB
/
Copy pathveranstaltungsleitenden-portal.js
File metadata and controls
47 lines (43 loc) · 1.66 KB
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
const csrfHeader = document.querySelector("head meta[name='_csrf_header']")?.content
const csrfToken = document.querySelector("head meta[name='_csrf']")?.content
const roomPin = document.querySelector("head meta[name='room-pin']")?.content
const alertMessage = document.querySelector("#alert-message")
const checkedInAmount = document.querySelector("#checked-in-amount strong")
const requestRoomReset = async () => {
const formData = new FormData();
formData.append('roomPin', roomPin)
const res = await fetch("reset", {
method: 'POST',
headers: {
[csrfHeader]: csrfToken,
},
body: formData,
})
const { success=false } = await res.json()
return success
}
const resetCheckedInAmount = () => {
checkedInAmount.innerText = 0
}
const showMessage = (message) => {
alertMessage.style.display = "flex"
alertMessage.innerText = message
setTimeout(() => {
alertMessage.style.display = "none"
alertMessage.innerText = ""
}, 3000)
}
document.getElementById("reset-room").onclick = async () => {
try{
if(!csrfHeader) throw new Error('csrf header not found')
if(!csrfToken) throw new Error('csrf token not found')
if(!roomPin) throw new Error('roomPin not found')
if(confirm("Wollen Sie den Raum wirklich zurücksetzen?")){
if(!await requestRoomReset()) throw new Error('internal server error')
resetCheckedInAmount();
showMessage("Der Raum wurde erfolgreich zurückgesetzt");
}
}catch(err){
alert("Beim Zurücksetzen des Raumes ist ein Fehler aufgetreten.");
}
}