On rajoute la confirmation pour les votes classés
This commit is contained in:
parent
9a785da53d
commit
325014aeef
2 changed files with 51 additions and 1 deletions
|
@ -11,7 +11,7 @@
|
|||
|
||||
var selected_rows = '';
|
||||
|
||||
(document.querySelectorAll('.checkbox input') || []).forEach(($checkbox) => {
|
||||
(document.querySelectorAll('.checkbox input') || []).forEach($checkbox => {
|
||||
if ($checkbox.checked) {
|
||||
let option_text = $checkbox.nextSibling.textContent.trim();
|
||||
selected_rows += '<tr><td>' + option_text + '</td></tr>\n';
|
||||
|
@ -35,6 +35,55 @@
|
|||
</script>
|
||||
{% elif question.vote_type == 'rank' %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.getElementById('confirm-button').addEventListener('click', () => {
|
||||
var $modal_body = document.getElementById('modal-body');
|
||||
|
||||
var ranks = new Array({{ nb_options }} + 1);
|
||||
|
||||
(document.querySelectorAll('.control .input') || []).forEach($input => {
|
||||
var rank = parseInt($input.value);
|
||||
if ($input.value == '') {
|
||||
rank = {{ nb_options }};
|
||||
}
|
||||
|
||||
var option = $input.closest('.field').querySelector('.label label').innerHTML;
|
||||
option = option.substring(0, option.length - 1).trim();
|
||||
|
||||
if (rank > 0 && rank <= {{ nb_options }}) {
|
||||
ranks[rank] = (ranks[rank] || []).concat([option]); // TODO: chercher une meilleure méthode
|
||||
}
|
||||
});
|
||||
|
||||
var table_rows = '';
|
||||
|
||||
for (let i = 1; i <= {{ nb_options }}; i++) {
|
||||
var option_list = '';
|
||||
|
||||
if (!(typeof ranks[i] === 'undefined')) {
|
||||
for (option of ranks[i]) {
|
||||
option_list += `${option}<br>`;
|
||||
}
|
||||
}
|
||||
table_rows += `<tr><th>${i}</th><td><div>${option_list}</div></td></tr>\n`
|
||||
}
|
||||
|
||||
$modal_body.innerHTML = `
|
||||
<table class="table is-fullwidth is-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Classement" %}</th>
|
||||
<th>{% trans "Option(s) selectionnée(s)" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${table_rows}
|
||||
</tbody>
|
||||
</table>`;
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -476,6 +476,7 @@ class VoteView(OpenElectionOnlyMixin, DetailView):
|
|||
context["q_index"] = questions.index(self.object) + 1
|
||||
context["q_total"] = len(questions)
|
||||
context["vote_rule"] = VOTE_RULES[self.object.type]
|
||||
context["nb_options"] = self.object.options.count()
|
||||
return context
|
||||
|
||||
def get_object(self):
|
||||
|
|
Loading…
Reference in a new issue