On utilise un seul modal pour supprimer des votes

This commit is contained in:
Tom Hubrecht 2021-05-27 19:54:39 +02:00
parent 50453a799a
commit b1488c7c8a
3 changed files with 31 additions and 9 deletions

View file

@ -2,6 +2,27 @@
{% load i18n %} {% load i18n %}
{% block extra_head %}
<script>
document.addEventListener('DOMContentLoaded', () => {
const $del_modal = document.getElementById('modal-delete');
const $del_title = $del_modal.querySelector('.modal-card-title');
const $del_form = $del_modal.querySelector('form');
$del_buttons = document.querySelectorAll('.modal-button.delete-vote')
$del_buttons.forEach($del => {
$del.addEventListener('click', () => {
$del_form.action = $del.dataset['post_url'];
$del_title.innerHTML = $del.dataset['tooltip'];
});
});
});
</script>
{% endblock %}
{% block content %} {% block content %}
<div class="level"> <div class="level">
@ -48,6 +69,10 @@
<div class="columns is-centered"> <div class="columns is-centered">
<div class="column is-two-thirds"> <div class="column is-two-thirds">
{% if can_delete %}
{% include "forms/modal-form.html" with modal_id="delete" form=d_form %}
{% endif %}
<table class="table is-striped is-fullwidth"> <table class="table is-striped is-fullwidth">
<thead> <thead>
<tr> <tr>
@ -85,19 +110,18 @@
</td> </td>
{% if can_delete %} {% if can_delete %}
<td class="has-text-centered"> <td class="has-text-centered">
{% url 'election.delete-vote' election.pk v.pk forloop.counter as post_url %} {% blocktrans with v_name=v.full_name asvar v_delete %}Supprimer le vote de {{ v_name }}{% endblocktrans %}
{% blocktrans with v_name=v.full_name asvar modal_title %}Supprimer le vote de {{ v_name }}{% endblocktrans %} <a class="tag is-danger has-tooltip-primary modal-button delete-vote" data-target="modal-delete" data-tooltip="{{ v_delete }}" data-post_url="{% url 'election.delete-vote' election.pk v.pk forloop.counter %}">
<a class="tag is-danger has-tooltip-primary modal-button" data-target="modal-{{ forloop.counter }}" data-tooltip="{{ modal_title }}">
<span class="icon"> <span class="icon">
<i class="fas fa-user-minus"></i> <i class="fas fa-user-minus"></i>
</span> </span>
</a> </a>
{% include "forms/modal-form.html" with modal_id=forloop.counter form=v.form %}
{% endif %} {% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</table> </table>
</div> </div>
</div> </div>

View file

@ -479,9 +479,7 @@ class ElectionVotersView(NotArchivedMixin, DetailView):
and not election.tallied and not election.tallied
) )
if can_delete: if can_delete:
# On rajoute le formulaire pour supprimer le vote context["d_form"] = DeleteVoteForm()
for v in voters:
v.form = DeleteVoteForm()
context["can_delete"] = can_delete context["can_delete"] = can_delete
context["voters"] = voters context["voters"] = voters

View file

@ -4,8 +4,8 @@
{{ field.label_tag }} {{ field.label_tag }}
</label> </label>
<div class="control"> <div class="control is-expanded">
<span class="select{% if field|is_multiple_select %} is-multiple{% endif %}{% if field.errors|length > 0 %} is-danger{% endif %}"> <span class="select is-fullwidth{% if field|is_multiple_select %} is-multiple{% endif %}{% if field.errors|length > 0 %} is-danger{% endif %}">
{{ field }} {{ field }}
</span> </span>