2017-11-23 21:07:16 +11:00
{#
Eos - Verifiable elections
2018-01-08 22:02:37 +11:00
Copyright © 2017-18 RunasSudo (Yingtong Li)
2017-11-23 21:07:16 +11:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see < http: / / www . gnu . org / licenses / > .
#}
2017-11-25 23:16:29 +11:00
< h2 > {{ questionNum + 1 }}. {{ election.questions.__getitem__(questionNum).prompt }}< / h2 >
2017-11-23 21:07:16 +11:00
2018-01-05 20:12:23 +11:00
< p > < small >
Vote for
{% if election.questions.__getitem__(questionNum).min_choices == election.questions.__getitem__(questionNum).max_choices %}
exactly {{ election.questions.__getitem__(questionNum).min_choices }}
{% else %}
between {{ election.questions.__getitem__(questionNum).min_choices }} and {{ election.questions.__getitem__(questionNum).max_choices }}
{% endif %}
choices. Click the check-boxes to the left of the choices to make your selection, then click the ‘Continue’ button. If you make a mistake, click the check-boxes again to clear your selection.
< / small > < / p >
2017-11-23 21:07:16 +11:00
2018-01-08 22:02:37 +11:00
{% set is_radio = election.questions.__getitem__(questionNum).max_choices == 1 %}
2017-11-23 21:07:16 +11:00
< div id = "question-choices" class = "ui form" style = "margin-bottom: 1em;" >
< div class = "grouped fields" >
2017-12-11 13:00:41 +11:00
{% for choice in election.questions.__getitem__(questionNum).randomised_choices().impl %}
2017-11-23 21:07:16 +11:00
< div class = "field" >
2018-01-08 22:02:37 +11:00
< div class = "ui{% if is_radio %} radio{% endif %} checkbox" >
< input
{% if is_radio %}
name="question-choices"
type="radio"
{% else %}
type="checkbox"
{% endif %}
id="question-choice-{{ election.questions.__getitem__(questionNum).choices.impl.indexOf(choice) }}" onchange="choicesChanged();">
2017-12-11 13:00:41 +11:00
< label for = "question-choice-{{ election.questions.__getitem__(questionNum).choices.impl.indexOf(choice) }}" > {{ choice.name }}{% if choice.party %} – {{ choice.party }}{% endif %}< / label >
2017-11-23 21:07:16 +11:00
< / div >
< / div >
{% endfor %}
2018-01-08 22:02:37 +11:00
{% if is_radio and election.questions.__getitem__(questionNum).min_choices == 0 %}
< div class = "field" >
< div class = "ui{% if is_radio %} radio{% endif %} checkbox" >
< input name = "question-choices" type = "radio" id = "question-choice-none" onchange = "choicesChanged();" checked >
< label for = "question-choice-none" > < i > None of the above< / i > < / label >
< / div >
< / div >
{% endif %}
2017-11-23 21:07:16 +11:00
< / div >
< / div >
< div class = "ui hidden message" id = "message-max-choices" >
2017-11-27 22:56:43 +11:00
< p > You have now selected the maximum allowed number of choices. If you wish to change your selections, you must first use the check-boxes to deselect a choice.< / p >
2017-11-23 21:07:16 +11:00
< / div >
< script >
function choicesChanged() {
2018-01-08 22:02:37 +11:00
{% if not is_radio %}
var numChoices = $("#question-choices input:checked").length;
if (numChoices >= election.questions.__getitem__(booth.questionNum).max_choices) {
// Prevent making any more selections
$("#question-choices input:not(:checked)").prop("disabled", true);
$("#message-max-choices").removeClass("hidden");
} else {
$("#question-choices input").prop("disabled", false);
$("#message-max-choices").addClass("hidden");
}
{% endif %}
2017-11-23 21:07:16 +11:00
}
// Fill in ballot with previous selections
2017-11-23 23:10:57 +11:00
if (booth.answers[booth.questionNum]) {
2017-11-27 22:56:43 +11:00
for (var selection of booth.answers[booth.questionNum].value.choices) { // Answer already serialised
2017-11-23 21:07:16 +11:00
$("#question-choice-" + selection).prop("checked", true);
}
choicesChanged();
}
function saveSelections() {
selections = [];
$("#question-choices input:checked").each(function(i, el) {
2018-01-08 22:02:37 +11:00
if (el.id !== "question-choice-none") {
selections.push(parseInt(el.id.substring("question-choice-".length)));
}
2017-11-23 21:07:16 +11:00
});
2018-01-05 20:12:23 +11:00
if (selections.length < election.questions.__getitem__ ( booth . questionNum ) . min_choices ) {
if (!window.confirm('You have selected fewer than the minimum required number of choices. If you proceed to cast this ballot, it will **NOT** be counted. If this was not your intention, please click the "Cancel" button below now, and correct your selections.')) {
return false;
}
}
2017-11-23 23:10:57 +11:00
answer = eosjs.eos.base.election.__all__.ApprovalAnswer(eosjs.__kwargtrans__({choices: selections}));
booth.answers[booth.questionNum] = eosjs.eos.core.objects.__all__.EosObject.serialise_and_wrap(answer);
2018-01-05 20:12:23 +11:00
return true;
2017-11-23 21:07:16 +11:00
}
< / script >