55 lines
2.2 KiB
JavaScript
55 lines
2.2 KiB
JavaScript
import { $, api, toast } from "./common.js";
|
|
|
|
const cfg = await api("GET", "/api/config").catch(() => ({}));
|
|
$("#pw-box").hidden = !cfg.create_password;
|
|
|
|
$("#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,
|
|
code_style: $("#code-style").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;
|
|
$("#go-screen").href = screen;
|
|
$("#go-present").href = `${location.origin}/present/${res.id}#${res.admin_key}`;
|
|
$("#create").hidden = true;
|
|
$("#try-link").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(); }
|
|
});
|
|
}
|
|
|
|
// a real window, not a tab: it can be dragged onto the projected display and put full screen there
|
|
$("#go-screen").addEventListener("click", (e) => {
|
|
const w = window.open($("#go-screen").href, "_blank", "popup,width=1280,height=720");
|
|
// blocked popup: the plain link still opens a tab
|
|
if (w) { w.opener = null; e.preventDefault(); }
|
|
});
|