Repo Cleanup
This commit is contained in:
@@ -56,13 +56,23 @@ async function load_page(id) {
|
||||
let submit = document.createElement("button");
|
||||
submit.textContent = "A Voté";
|
||||
submit.addEventListener("click", async () => {
|
||||
Vote.vote_moins_id = vote_id_select.value;
|
||||
Vote.vote_moins_nickname = vote_nickname_input.value;
|
||||
Vote.vote_moins_reason = vote_reason_input.value;
|
||||
if (await send_vote(Vote)) {
|
||||
confirm_popup();
|
||||
save_state();
|
||||
}
|
||||
if (vote.vote_plus_id === null || vote.vote_moins_id === null) {
|
||||
const popUp = document.createElement("div");
|
||||
popUp.className = "popup";
|
||||
const message = document.createElement("h2");
|
||||
message.textContent = "Tu dois dire pour qui tu vote!";
|
||||
const page = document.body;
|
||||
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;
|
||||
if (await send_vote(Vote)) {
|
||||
confirm_popup();
|
||||
save_state();
|
||||
}
|
||||
}
|
||||
})
|
||||
submit.className = "right";
|
||||
previous.className = "left";
|
||||
@@ -113,13 +123,10 @@ function get_state() {
|
||||
let cookie = document.cookie;
|
||||
return cookie.includes("hasvoted=true");
|
||||
}
|
||||
async function send_vote(vote) {
|
||||
if (vote.vote_plus_id === null || vote.vote_moins_id === null) {
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
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