71 lines
2.4 KiB
JavaScript
71 lines
2.4 KiB
JavaScript
let vote = {
|
|
plusId: null,
|
|
plusNickname: "",
|
|
plusReason: "",
|
|
minusId: null,
|
|
minusNickname: "",
|
|
minusReason: ""
|
|
}
|
|
|
|
let current_page = 0;
|
|
|
|
async function main() {
|
|
let players = await fetch("/data/players").then(r => r.json());
|
|
let select = document.getElementById("player_id");
|
|
let nickname = document.getElementById("nickname");
|
|
let reason = document.getElementById("reason");
|
|
players.forEach((x) => {
|
|
let option = document.createElement("option");
|
|
option.value = x["id"];
|
|
option.textContent = x["name"];
|
|
select.append(option);
|
|
})
|
|
select.value = null;
|
|
let rightButton = document.getElementById("next");
|
|
let leftButton = document.getElementById("prev");
|
|
let title = document.getElementById("app_title");
|
|
// better to do event listeners onchange with condition currentpage
|
|
// such as currentpage gets changed before reassigning values
|
|
// should work
|
|
rightButton.addEventListener("click", () => {
|
|
if (current_page) {
|
|
vote.minusId = parseInt(select.value);
|
|
select.value = null;
|
|
vote.minusNickname = nickname.value;
|
|
nickname.value = "";
|
|
vote.minusReason = reason.value;
|
|
reason.value = "";
|
|
console.log(vote);
|
|
} else {
|
|
rightButton.textContent = "À voté!";
|
|
title.textContent = "Vote -";
|
|
current_page = 1;
|
|
vote.plusId = parseInt(select.value);
|
|
select.value = null;
|
|
vote.plusNickname = nickname.value;
|
|
nickname.value = "";
|
|
vote.plusReason = reason.value;
|
|
reason.value = "";
|
|
leftButton.hidden = false;
|
|
select.value = vote.minusId;
|
|
nickname.value = vote.minusNickname;
|
|
reason.value = vote.minusReason;
|
|
}
|
|
})
|
|
leftButton.addEventListener("click", () => {
|
|
if (current_page) {
|
|
current_page = 0;
|
|
title.textContent = "Vote +";
|
|
rightButton.textContent = "Suivant";
|
|
vote.minusId = parseInt(select.value);
|
|
vote.minusNickname = nickname.value;
|
|
vote.minusReason = reason.value;
|
|
leftButton.hidden = true;
|
|
select.value = vote.plusId;
|
|
nickname.value = vote.plusNickname;
|
|
reason.value = vote.plusReason;
|
|
}
|
|
})
|
|
}
|
|
|
|
let _ = main(); |