Each vote can require N fresh codes read off the projector (default 3, off for rooms without a projector); voters enrolled with a paper or rescue code are exempt. Rescue codes enroll a phone without camera. Projector keeps the QR up while such a vote is open. Server pings every socket every 25s so proxies keep them open. Composer no longer closes on enter. Schema migrates existing databases.
52 lines
1.9 KiB
JavaScript
52 lines
1.9 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,
|
|
vote_scans: $("#vote-scans-on").checked ? 3 : 0,
|
|
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(); }
|
|
});
|
|
}
|