diff --git a/static/html/index.html b/static/html/index.html index d6482c2..6474231 100644 --- a/static/html/index.html +++ b/static/html/index.html @@ -16,6 +16,8 @@

Vote +

+ + diff --git a/static/js/index.js b/static/js/index.js index da35d26..daf8559 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -24,10 +24,25 @@ async function main() { option.textContent = x["name"]; select.append(option); }) + let other = document.createElement("option"); + other.value = "other"; + other.textContent = "Autre"; + select.append(other); select.value = null; nickname.value = ""; reason.value = ""; select.addEventListener("change", () => { + if (select.value === "other") { + let other = document.getElementById("other"); + other.hidden = false; + let otherLabel = document.getElementById("other_label"); + otherLabel.hidden = false; + } else { + let other = document.getElementById("other"); + other.hidden = true; + let otherLabel = document.getElementById("other_label"); + otherLabel.hidden = true; + } if (current_page) { vote.minus_player_id = parseInt(select.value); } else { @@ -59,6 +74,19 @@ async function main() { true, "warning"); return; } + if (select.value === "other") { + let otherInput = document.getElementById("other"); + let otherInputLabel = document.getElementById("other_label"); + let player = await fetch("/player", {method: "post", body: JSON.stringify({"name": otherInput.value})}).then(r => r.json()); + let option = document.createElement("option"); + option.value = player["id"]; + option.textContent = player["name"]; + select.insertBefore(option, other); + vote.minus_player_id = parseInt(player["id"]); + otherInput.value = ""; + otherInput.hidden = true; + otherInputLabel.hidden = true; + } if (await fetch("/vote", { method: "post", body: JSON.stringify(vote) }) @@ -76,6 +104,19 @@ async function main() { } rightButton.textContent = "À voté!"; title.textContent = "Vote -"; + if (select.value === "other") { + let otherInput = document.getElementById("other"); + let otherInputLabel = document.getElementById("other_label"); + let player = await fetch("/player", {method: "post", body: JSON.stringify({"name": otherInput.value})}).then(r => r.json()); + let option = document.createElement("option"); + option.value = player["id"]; + option.textContent = player["name"]; + select.insertBefore(option, other); + vote.plus_player_id = parseInt(player["id"]); + otherInput.value = ""; + otherInput.hidden = true; + otherInputLabel.hidden = true; + } current_page = 1; leftButton.hidden = false; select.value = vote.minus_player_id;