2017-07-13 23:25:54 +02:00
|
|
|
let nicknameInput = document.getElementById("nicknameInput");
|
|
|
|
let lobbyIdInput = document.getElementById("lobbyIdInput");
|
2017-09-14 05:59:39 +02:00
|
|
|
let joinLobbyForm = document.getElementById("joinLobbyForm");
|
2017-07-13 23:25:54 +02:00
|
|
|
let joinLobbyButton = document.getElementById("joinLobbyButton");
|
|
|
|
|
2017-09-14 05:59:39 +02:00
|
|
|
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) {
|
2017-09-14 05:59:39 +02:00
|
|
|
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
|
|
|
});
|
2017-09-14 05:59:39 +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');
|
2017-09-14 05:59:39 +02:00
|
|
|
request.send();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
joinLobbyButton.onclick = function(e) {
|
|
|
|
joinLobbyForm.submit
|
2017-07-13 23:25:54 +02:00
|
|
|
}
|