General update: site works.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
Vote = {
|
||||
vote_plus_id: null,
|
||||
vote_plus_nickname: "",
|
||||
vote_plus_reason: "",
|
||||
vote_moins_id: null,
|
||||
vote_moins_nickname: "",
|
||||
vote_moins_reason: ""
|
||||
plus_player_id: null,
|
||||
plus_nickname: "",
|
||||
plus_reason: "",
|
||||
minus_player_id: null,
|
||||
minus_nickname: "",
|
||||
minus_reason: ""
|
||||
}
|
||||
|
||||
let _ = load_page(0)
|
||||
@@ -20,43 +20,43 @@ async function load_page(id) {
|
||||
const buttons = document.createElement("div");
|
||||
buttons.className = "buttons";
|
||||
|
||||
const vote_id = document.createElement("h2");
|
||||
vote_id.textContent = "Pour qui votes-tu?"
|
||||
const vote_id_select = document.createElement("select");
|
||||
const vote_nickname = document.createElement("h2");
|
||||
vote_nickname.textContent = "As-tu un surnom à lui donner?";
|
||||
const vote_nickname_input = document.createElement("input");
|
||||
vote_nickname_input.inputMode = "text";
|
||||
vote_nickname_input.maxLength = 100;
|
||||
const vote_reason = document.createElement("h2");
|
||||
vote_reason.textContent = "Pourquoi votes-tu pour lui?";
|
||||
const vote_reason_input = document.createElement("textarea");
|
||||
vote_reason_input.maxLength = 1000;
|
||||
const idlbl = document.createElement("h2");
|
||||
idlbl.textContent = "Pour qui votes-tu?"
|
||||
const id_select = document.createElement("select");
|
||||
const nickname = document.createElement("h2");
|
||||
nickname.textContent = "As-tu un surnom à lui donner?";
|
||||
const nickname_input = document.createElement("input");
|
||||
nickname_input.inputMode = "text";
|
||||
nickname_input.maxLength = 100;
|
||||
const reason = document.createElement("h2");
|
||||
reason.textContent = "Pourquoi votes-tu pour lui?";
|
||||
const reason_input = document.createElement("textarea");
|
||||
reason_input.maxLength = 1000;
|
||||
|
||||
players.forEach((player) => {
|
||||
const player_option = document.createElement("option");
|
||||
player_option.value = player["id"];
|
||||
player_option.innerText = player["name"];
|
||||
vote_id_select.appendChild(player_option);
|
||||
id_select.appendChild(player_option);
|
||||
})
|
||||
|
||||
if (id) {
|
||||
vote_id_select.value = Vote.vote_moins_id;
|
||||
vote_nickname_input.value = Vote.vote_moins_nickname;
|
||||
vote_reason_input.value = Vote.vote_moins_reason;
|
||||
id_select.value = Vote.minus_player_id;
|
||||
nickname_input.value = Vote.minus_nickname;
|
||||
reason_input.value = Vote.minus_reason;
|
||||
header.textContent = "Vote -";
|
||||
let previous = document.createElement("button");
|
||||
previous.textContent = "Précédent";
|
||||
previous.addEventListener("click", () => {
|
||||
Vote.vote_moins_id = vote_id_select.value;
|
||||
Vote.vote_moins_nickname = vote_nickname_input.value;
|
||||
Vote.vote_moins_reason = vote_reason_input.value;
|
||||
Vote.minus_player_id = id_select.value;
|
||||
Vote.minus_nickname = nickname_input.value;
|
||||
Vote.minus_reason = reason_input.value;
|
||||
load_page(0)
|
||||
});
|
||||
let submit = document.createElement("button");
|
||||
submit.textContent = "A Voté";
|
||||
submit.addEventListener("click", async () => {
|
||||
if (vote.vote_plus_id === null || vote.vote_moins_id === null) {
|
||||
if (Vote.plus_id === null || id_select.value === "") {
|
||||
const popUp = document.createElement("div");
|
||||
popUp.className = "popup";
|
||||
const message = document.createElement("h2");
|
||||
@@ -65,9 +65,9 @@ async function load_page(id) {
|
||||
popUp.append(message);
|
||||
page.append(popUp);
|
||||
} else {
|
||||
Vote.vote_moins_id = vote_id_select.value;
|
||||
Vote.vote_moins_nickname = vote_nickname_input.value;
|
||||
Vote.vote_moins_reason = vote_reason_input.value;
|
||||
Vote.minus_player_id = id_select.value;
|
||||
Vote.minus_nickname = nickname_input.value;
|
||||
Vote.minus_reason = reason_input.value;
|
||||
if (await send_vote(Vote)) {
|
||||
confirm_popup();
|
||||
save_state();
|
||||
@@ -78,16 +78,16 @@ async function load_page(id) {
|
||||
previous.className = "left";
|
||||
buttons.append(previous, submit);
|
||||
} else {
|
||||
vote_id_select.value = Vote.vote_plus_id;
|
||||
vote_nickname_input.value = Vote.vote_plus_nickname;
|
||||
vote_reason_input.value = Vote.vote_plus_reason;
|
||||
id_select.value = Vote.plus_player_id;
|
||||
nickname_input.value = Vote.plus_nickname;
|
||||
reason_input.value = Vote.plus_reason;
|
||||
header.textContent = "Vote +";
|
||||
let next = document.createElement("button");
|
||||
next.innerText = "Suivant";
|
||||
next.addEventListener("click", () => {
|
||||
Vote.vote_plus_id = vote_id_select.value;
|
||||
Vote.vote_plus_nickname = vote_nickname_input.value;
|
||||
Vote.vote_plus_reason = vote_reason_input.value;
|
||||
Vote.plus_player_id = id_select.value;
|
||||
Vote.plus_nickname = nickname_input.value;
|
||||
Vote.plus_reason = reason_input.value;
|
||||
load_page(1)
|
||||
});
|
||||
next.className = "right";
|
||||
@@ -97,7 +97,7 @@ async function load_page(id) {
|
||||
|
||||
const div = document.getElementById("app");
|
||||
div.innerHTML = "";
|
||||
div.append(header, vote_id, vote_id_select, vote_nickname, vote_nickname_input, vote_reason, vote_reason_input, buttons);
|
||||
div.append(header, idlbl, id_select, nickname, nickname_input, reason, reason_input, buttons);
|
||||
}
|
||||
|
||||
function confirm_popup() {
|
||||
@@ -124,8 +124,8 @@ function get_state() {
|
||||
return cookie.includes("hasvoted=true");
|
||||
}
|
||||
async function send_vote(vote) {
|
||||
vote.vote_plus_id = parseInt(vote.vote_plus_id, 10);
|
||||
vote.vote_moins_id = parseInt(vote.vote_moins_id, 10);
|
||||
vote.plus_player_id = parseInt(vote.plus_player_id, 10);
|
||||
vote.minus_player_id = parseInt(vote.minus_player_id, 10);
|
||||
let body = JSON.stringify(vote);
|
||||
let result = await fetch(window.location.href + "post", {method: "POST", body: body}).then(r => r.status);
|
||||
return result === 200;
|
||||
|
||||
Reference in New Issue
Block a user