var isPlaying = false; function showRegisterForm() { document.getElementById("text-container").style.top = '2%' document.getElementById("register-button").style.opacity = 0 document.getElementById("participation-buttons").style.display = 'inline-block' document.getElementById("name-form").style.display = 'inherit' document.getElementById("add-calender-event").style.display = 'none' document.getElementById("guest-name").focus() if (!isPlaying) { playPause(); } } function playPause() { var audio = document.getElementById("audio"); var playButton = document.getElementById("play-button"); var pauseButton = document.getElementById("pause-button"); var playText = document.getElementById("playing-text"); var pauseText = document.getElementById("paused-text"); if (isPlaying) { audio.pause(); playButton.style.display = "inherit"; pauseButton.style.display = "none"; playText.style.display = "none"; pauseText.style.display = "table-cell"; } else { audio.play(); playButton.style.display = "none"; pauseButton.style.display = "inherit"; playText.style.display = "table-cell"; pauseText.style.display = "none"; } isPlaying = !isPlaying; } async function participate(isParticipating) { let value = document.getElementById("guest-name").value if (!value) { return } let name = value.trim() document.getElementById("participation-buttons").style.display = 'none' document.getElementById("name-form").style.display = 'none' console.log("Registering: " + name); if (isParticipating) { let registered = await performRequest(name, "register") if (registered) { document.getElementById("registered-text").style.display = 'inherit' document.getElementById("add-calender-event").style.display = 'inherit' } else { document.getElementById("error-text").style.display = 'inherit' } } else { let declined = await performRequest(name, "decline") if (declined) { document.getElementById("declined-text").style.display = 'inherit' } else { document.getElementById("error-text").style.display = 'inherit' } } } function handleErrors(response) { if (!response.ok) throw new Error(response.status); return response.text(); } function catchErrors(error) { console.log(error); return "Failed"; } async function performRequest(name, path) { let text = await fetch("/festival/api/" + path, { method: 'POST', body: name }).then(handleErrors).catch(catchErrors); if (text == "Success") { console.log("Registered: " + name); return true; } console.log("Failed to register: " + text); return false; } function download(file) { window.location = file }