Hand-added votes per question (paper, show of hands): counted in the turnout and shown hatched orange at the end of each result bar, kept apart from phone ballots
This commit is contained in:
+32
-3
@@ -116,13 +116,14 @@ function questionCard(q) {
|
||||
actions.push(act("Lancer le vote", "open", "small go"));
|
||||
actions.push(act("Supprimer", "delete", "small danger", "Supprimer ce brouillon ?"));
|
||||
} else if (q.state === "open") {
|
||||
actions.push(act("Clore le vote", "close", "small primary", `Clore le vote (${q.participants} vote${q.participants > 1 ? "s" : ""}) ?`));
|
||||
actions.push(act("Clore le vote", "close", "small primary", `Clore le vote (${q.participants + q.extra_ballots} vote${q.participants + q.extra_ballots > 1 ? "s" : ""}) ?`));
|
||||
} else {
|
||||
actions.push(q.results_public
|
||||
? act("Masquer les résultats", "unpublish")
|
||||
: act("Publier les résultats", "publish", "small primary", "Publier les résultats ? Le vote ne pourra plus être rouvert."));
|
||||
if (!q.shown) actions.push(act("Rouvrir le vote", "reopen"));
|
||||
}
|
||||
if (q.state !== "draft") actions.push(h("button", { class: "small", type: "button", onclick: () => editExtra(q) }, "Votes en plus"));
|
||||
if (q.state !== "draft" && !focused) actions.push(act([icon("screen", 15), "Afficher à l'écran"], "focus"));
|
||||
|
||||
const badges = [h("span", { class: `badge ${q.state}` }, STATE_LABEL[q.state])];
|
||||
@@ -132,17 +133,45 @@ function questionCard(q) {
|
||||
|
||||
return h("article", { class: `q ${q.state}` },
|
||||
h("div", { class: "q-head" }, h("div", {}, badges),
|
||||
q.state !== "draft" ? h("span", { class: "q-meta" }, `${q.participants} / ${voters}`) : null),
|
||||
q.state !== "draft" ? h("span", { class: "q-meta" }, `${q.participants} / ${voters}`,
|
||||
q.extra_ballots ? h("span", { class: "extra-note" }, ` + ${q.extra_ballots}`) : null) : null),
|
||||
h("div", { class: "q-text" }, q.text),
|
||||
q.state === "closed"
|
||||
? resultsView(q)
|
||||
: h("div", { class: "chips" }, q.options.map((o) => h("span", { class: "chip" }, o)),
|
||||
q.allow_blank ? h("span", { class: "chip ghost" }, "Blanc") : null),
|
||||
q.state === "open" ? h("div", { class: "progress" }, fill(pct(q.participants, voters), "")) : null,
|
||||
q.state === "open" ? h("div", { class: "progress" }, fill(pct(q.participants, voters + q.extra_ballots), ""),
|
||||
q.extra_ballots ? fill(pct(q.extra_ballots, voters + q.extra_ballots), "p-extra") : null) : null,
|
||||
h("div", { class: "actions" }, actions),
|
||||
);
|
||||
}
|
||||
|
||||
// votes added by hand, in a dialog: the question list re-renders on every incoming vote
|
||||
async function editExtra(q) {
|
||||
const dlg = $("#extra-dlg"), e = q.extra, inputs = [];
|
||||
const field = (label, value) => {
|
||||
const inp = h("input", { type: "number", min: 0, max: 100000, value: String(value), inputmode: "numeric" });
|
||||
inputs.push(inp);
|
||||
return h("label", { class: "extra-row" }, h("span", {}, label), inp);
|
||||
};
|
||||
$("#extra-q").textContent = q.text;
|
||||
$("#extra-fields").replaceChildren(...[
|
||||
...q.options.map((o, i) => field(o, e.counts[i] || 0)),
|
||||
q.allow_blank ? field("Blanc", e.blank) : null,
|
||||
q.kind === "multi" ? field("Bulletins (choix multiple)", e.ballots) : null,
|
||||
].filter(Boolean));
|
||||
dlg.returnValue = "";
|
||||
dlg.showModal();
|
||||
await new Promise((res) => dlg.addEventListener("close", res, { once: true }));
|
||||
if (dlg.returnValue !== "ok") return;
|
||||
const vals = inputs.map((i) => Math.max(0, Math.floor(+i.value || 0)));
|
||||
const n = q.options.length;
|
||||
const payload = { counts: vals.slice(0, n), blank: q.allow_blank ? vals[n] : 0 };
|
||||
if (q.kind === "multi") payload.ballots = vals[vals.length - 1];
|
||||
try { await call("POST", `/questions/${q.id}/extra`, payload); toast("Votes ajoutés", "ok"); }
|
||||
catch (err) { toast(err.code === "bad_extra" ? "Nombre de bulletins incohérent" : errMsg(err), "bad"); }
|
||||
}
|
||||
|
||||
// composer
|
||||
|
||||
const composer = $("#composer");
|
||||
|
||||
Reference in New Issue
Block a user