70 lines
2.9 KiB
HTML
70 lines
2.9 KiB
HTML
{#
|
|
Eos - Verifiable elections
|
|
Copyright © 2017 RunasSudo (Yingtong Li)
|
|
|
|
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/>.
|
|
#}
|
|
|
|
<h2>{{ questionNum + 1 }}. {{ election.questions[questionNum].prompt }}</h2>
|
|
|
|
<p><small>Vote for between {{ election.questions[questionNum].min_choices }} and {{ election.questions[questionNum].max_choices }} candidates. Click the check-boxes to the left of the candidates' names 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>
|
|
|
|
<div id="question-choices" class="ui form" style="margin-bottom: 1em;">
|
|
<div class="grouped fields">
|
|
{% for choice in election.questions[questionNum].choices %}
|
|
<div class="field">
|
|
<div class="ui checkbox">
|
|
<input type="checkbox" id="question-choice-{{ loop.index0 }}" onchange="choicesChanged();">
|
|
<label for="question-choice-{{ loop.index0 }}">{{ choice }}</label>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="ui hidden message" id="message-max-choices">
|
|
<p>You have now selected the maximum allowed number of candidates. If you wish to change your selections, you must first use the check-boxes to deselect a candidate.</p>
|
|
</div>
|
|
|
|
<script>
|
|
function choicesChanged() {
|
|
var numChoices = $("#question-choices input:checked").length;
|
|
if (numChoices >= election.questions[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");
|
|
}
|
|
}
|
|
|
|
// Fill in ballot with previous selections
|
|
if (booth.answers[booth.questionNum]) {
|
|
for (var selection of booth.answers[booth.questionNum].value.choices) { // Answer already serialised
|
|
$("#question-choice-" + selection).prop("checked", true);
|
|
}
|
|
choicesChanged();
|
|
}
|
|
|
|
function saveSelections() {
|
|
selections = [];
|
|
$("#question-choices input:checked").each(function(i, el) {
|
|
selections.push(parseInt(el.id.substring("question-choice-".length)))
|
|
});
|
|
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);
|
|
}
|
|
</script>
|