Files
rotatyvote/static/js/index.js
T
showdown e526edd75e RotatyVote: in-person anonymous voting with rotating QR enrollment
Starlette backend with sqlite, rotating HMAC QR tokens pushed to a
key-protected projector page, multi-scan enrollment, optional one-time
paper codes, anonymous ballots split from participation, live question
push over websockets, e2e tests over HTTP and TLS.
2026-11-16 12:58:26 +01:00

51 lines
1.8 KiB
JavaScript

import { $, api, toast } from "./common.js";
const cfg = await api("GET", "/api/config").catch(() => ({}));
$("#pw-box").hidden = !cfg.create_password;
function hint() {
const s = (+$("#interval").value * +$("#scans").value) / 1000;
$("#duration-hint").textContent = `≈ ${s.toLocaleString("fr-FR")} s de scan`;
}
$("#interval").addEventListener("change", hint);
$("#scans").addEventListener("input", hint);
hint();
$("#codes-on").addEventListener("change", (e) => { $("#codes-box").hidden = !e.target.checked; });
$("#form").addEventListener("submit", async (e) => {
e.preventDefault();
const btn = e.submitter;
btn.disabled = true;
try {
const res = await api("POST", "/api/polls", {
title: $("#title").value,
interval_ms: +$("#interval").value,
scans_required: +$("#scans").value,
expected: $("#expected").value ? +$("#expected").value : null,
max_voters: $("#maxv").value ? +$("#maxv").value : null,
require_code: $("#codes-on").checked,
codes: $("#codes-on").checked ? +$("#codes").value : 0,
password: $("#pw").value || undefined,
});
const admin = `${location.origin}/admin/${res.id}#${res.admin_key}`;
const screen = `${location.origin}/screen/${res.id}#${res.screen_key}`;
$("#admin-link").value = admin;
$("#screen-link").value = screen;
$("#go-admin").href = admin;
$("#create").hidden = true;
$("#done").hidden = false;
} catch (err) {
toast(err.code === "bad_password" ? "Mot de passe incorrect" : `Erreur : ${err.message}`, "bad");
} finally {
btn.disabled = false;
}
});
for (const [btn, input] of [["#copy-admin", "#admin-link"], ["#copy-screen", "#screen-link"]]) {
$(btn).addEventListener("click", async () => {
try { await navigator.clipboard.writeText($(input).value); toast("Copié", "ok"); }
catch { $(input).select(); }
});
}