Skip to content
Snippets Groups Projects
Commit 252c9d21 authored by Jan Hartig's avatar Jan Hartig
Browse files

bla

parent ead017b5
No related branches found
No related tags found
1 merge request!1Add error handling
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Raumfreischaltung - PTB VC</title>
......@@ -37,20 +38,20 @@
button:hover {
transition: background-color 0.12s ease-in-out;
background-color: #45a049;
background-color: green;
}
button:hover:disabled {
pointer-events: none;
}
#hiddenField {
.hiddenField {
margin-top: 5rem;
opacity: 0;
transition: opacity 0.25s ease-in;
}
#hiddenField.visible {
.hiddenField.visible {
opacity: 1;
}
......@@ -58,64 +59,88 @@
width: 40rem;
margin-bottom: 1.5rem;
}
.error {
color: darkred;
}
</style>
</head>
<body>
<h1>Raumfreischaltung</h1>
<input type="text" id="room" name="raumname" placeholder="Raumname" minlength="1">
<button type="button" onclick="process_form()" id="unlock">Freischalten</button>
<div id="hiddenField" aria-hidden="true">
<p id="urlText"></p>
<p id="urlTime"></p>
<input type="text" id="roomUrl" readonly>
<br>
<button id="copyButton" onclick="copyToClipboard()">Link in Zwischenablage kopieren</button>
</div>
<script>
const baseUrl = window.location.protocol + "//" + window.location.host
const unlockButton = document.getElementById('unlock')
const roomField = document.getElementById('room')
const hiddenField = document.getElementById('hiddenField');
const urlText = document.getElementById('urlText');
const urlTime = document.getElementById('urlTime');
const roomUrl = document.getElementById('roomUrl');
let room = window.location.href.substring(window.location.href.lastIndexOf('/') + 1)
if (room.length > 2 && room !== "raumfreischaltung") {
roomField.value = room;
get_room();
}
function get_room() {
fetch(baseUrl + "/unlockroom", {
method: "POST",
body: JSON.stringify({"room": room}),
headers: {"Content-Type": "application/json"}
}).then(data => {
data.json().then(data => {
urlText.innerHTML = "Dieser Link öffnet den Raum <b>" + data.room + "</b> ohne Zertifikat.";
urlTime.innerHTML = "Gültig bis <b>" + new Date(Date.now() + data.valid_for * 24 * 60 * 60 * 1000).toLocaleDateString() + "</b>";
roomUrl.value = baseUrl + "/" + data.room + "?jwt=" + data.jwt;
<h1>Raumfreischaltung</h1>
<input type="text" id="room" placeholder="Raumname" minlength="2" required>
<button type="button" onclick="process_form()" id="unlock">Freischalten</button>
<br><br>
<button type="button" onclick="" id="random">Zufälligen Raum erstellen</button>
<div id="hiddenFieldError" aria-hidden="true">
<p id="errorText" class="error"></p>
</div>
<div id="hiddenField" class="hiddenField" aria-hidden="true">
<p id="urlText"></p>
<p id="urlTime"></p>
<input type="text" id="roomUrl" readonly>
<br>
<button id="copyButton" onclick="copyToClipboard()">Link in Zwischenablage kopieren</button>
</div>
<script>
const baseUrl = window.location.protocol + "//" + window.location.host
const unlockButton = document.getElementById('unlock')
const randomButton = document.getElementById('random')
const roomField = document.getElementById('room')
const hiddenField = document.getElementById('hiddenField');
const hiddenFieldError = document.getElementById('hiddenField');
const errorText = document.getElementById('errorText');
const urlText = document.getElementById('urlText');
const urlTime = document.getElementById('urlTime');
const roomUrl = document.getElementById('roomUrl');
let room = window.location.href.substring(window.location.href.lastIndexOf('/') + 1)
if (room !== "raumfreischaltung") {
roomField.value = room;
unlockButton.click();
}
function get_room(_room) {
let _body;
if (_room) {
JSON.stringify({ "room": room })
} else {
""
}
fetch(baseUrl + "/unlockroom", {
method: "POST",
body: _body,
headers: { "Content-Type": "application/json" }
}).then(data => {
data.json().then(data => {
if (data.error) {
errorText.innerText = data.error
} else {
urlText.innerHTML = "Dieser Link öffnet den Raum <b>" + data.room + "</b> ohne Zertifikat.";
urlTime.innerHTML = "Gültig bis <b>" + new Date(Date.now() + data.valid_for * 24 * 60 * 60 * 1000).toLocaleDateString() + "</b>";
roomUrl.value = baseUrl + "/" + data.room + "?jwt=" + data.jwt;
}
})
})
})
unlockButton.disabled = true;
roomField.disabled = true;
hiddenField.classList.add('visible');
hiddenField.ariaHidden = "false";
}
function process_form() {
room = roomField.value
get_room()
}
function copyToClipboard() {
roomUrl.select();
document.execCommand('copy');
}
</script>
unlockButton.disabled = true;
randomButton.disabled = true;
roomField.disabled = true;
hiddenField.classList.add('visible');
hiddenField.ariaHidden = "false";
}
function process_form() {
room = roomField.value
get_room()
}
function copyToClipboard() {
roomUrl.select();
document.execCommand('copy');
}
</script>
</body>
</html>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment