doodul/js/index.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-07-13 23:25:54 +02:00
let nicknameInput = document.getElementById("nicknameInput");
let lobbyIdInput = document.getElementById("lobbyIdInput");
let joinLobbyForm = document.getElementById("joinLobbyForm");
2017-07-13 23:25:54 +02:00
let joinLobbyButton = document.getElementById("joinLobbyButton");
nicknameInput.oninput = lobbyIdInput.oninput = function(e) {
e.target.setCustomValidity("");
}
joinLobbyForm.onsubmit = function(e) {
2017-07-13 23:25:54 +02:00
let nickname = nicknameInput.value;
let lobbyId = lobbyIdInput.value;
let request = new XMLHttpRequest();
request.addEventListener("load", function (e) {
let response = JSON.parse(request.responseText);
if(response.canJoin)
{
joinLobbyForm.action = "/lobby/" + lobbyId;
joinLobbyForm.submit();
}
else
{
let badField = document.getElementsByName(response.badField)[0];
badField.setCustomValidity(response.reason);
badField.reportValidity();
}
2017-07-13 23:25:54 +02:00
});
request.open("GET", "/lobby/" + lobbyId + "/joinability?nickname=" + encodeURIComponent(nickname));
2017-07-13 23:25:54 +02:00
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.send();
return false;
}
joinLobbyButton.onclick = function(e) {
joinLobbyForm.submit
2017-07-13 23:25:54 +02:00
}