diff --git a/elections/forms.py b/elections/forms.py
index faa23af..9682e81 100644
--- a/elections/forms.py
+++ b/elections/forms.py
@@ -63,13 +63,16 @@ class OptionForm(forms.ModelForm):
class DeleteVoteForm(forms.Form):
def __init__(self, **kwargs):
- voter = kwargs.pop("voter")
+ voter = kwargs.pop("voter", None)
super().__init__(**kwargs)
- self.fields["delete"].label = _("Supprimer le vote de {} ({}) ?").format(
- voter.full_name, voter.get_username()
- )
+ if voter is not None:
+ self.fields["delete"].label = _("Supprimer le vote de {} ({}) ?").format(
+ voter.full_name, voter.get_username()
+ )
- delete = forms.ChoiceField(choices=(("non", _("Non")), ("oui", _("Oui"))))
+ delete = forms.ChoiceField(
+ label=_("Supprimer"), choices=(("non", _("Non")), ("oui", _("Oui")))
+ )
class SelectVoteForm(forms.ModelForm):
diff --git a/elections/templates/elections/election_voters.html b/elections/templates/elections/election_voters.html
index 2159fc9..30a2618 100644
--- a/elections/templates/elections/election_voters.html
+++ b/elections/templates/elections/election_voters.html
@@ -52,7 +52,6 @@
- {% with voters=election.voters.all %}
{% if election.restricted %}
{% for v in election.registered_voters.all %}
@@ -79,18 +78,21 @@
{% if can_delete %}
-
+ {% url 'election.delete-vote' election.pk v.pk forloop.counter as post_url %}
+ {% blocktrans with v_name=v.full_name asvar modal_title %}Supprimer le vote de {{ v_name }}{% endblocktrans %}
+
+ {% include "forms/modal-form.html" with modal_id=forloop.counter form=v.form %}
{% endif %}
|
{% endfor %}
{% endif %}
- {% endwith %}
+
{% endblock %}
diff --git a/elections/views.py b/elections/views.py
index 36215fc..aff3b25 100644
--- a/elections/views.py
+++ b/elections/views.py
@@ -430,14 +430,22 @@ class ElectionVotersView(NotArchivedMixin, DetailView):
user = self.request.user
context = super().get_context_data(**kwargs)
election = context["election"]
+ voters = list(election.voters.all())
if user.is_authenticated:
- context["can_delete"] = (
+ can_delete = (
not election.restricted
and election.created_by == user
and election.end_date < timezone.now()
and not election.tallied
)
+ if can_delete:
+ # On rajoute le formulaire pour supprimer le vote
+ for v in voters:
+ v.form = DeleteVoteForm()
+
+ context["voters"] = voters
+ context["can_delete"] = can_delete
return context
diff --git a/shared/templates/base.html b/shared/templates/base.html
index 33c0497..e4dd889 100644
--- a/shared/templates/base.html
+++ b/shared/templates/base.html
@@ -45,14 +45,43 @@
});
});
+ // Interact with modals
+ var $modals = document.querySelectorAll('.modal') || [];
+ var $modalButtons = document.querySelectorAll('.modal-button') || [];
+ var $modalCloses = document.querySelectorAll('.modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button-close') || [];
+
+ $modalButtons.forEach(function($el) {
+ $el.addEventListener('click', function() {
+ var target = $el.dataset.target;
+ var $target = document.getElementById(target);
+ document.documentElement.classList.add('is-clipped');
+ $target.classList.add('is-active');
+ });
+ });
+
+ $modalCloses.forEach(function($el) {
+ $el.addEventListener('click', (event) => {
+ event.stopPropagation();
+ document.documentElement.classList.remove('is-clipped');
+ $modals.forEach(function($el) {
+ $el.classList.remove('is-active');
+ });
+ });
+ });
+
document.addEventListener('keydown', (event) => {
var e = event || window.event;
if (e.keyCode === 27) {
$dropdowns.forEach(($dropdown) => {
$dropdown.classList.remove('is-active');
});
+ document.documentElement.classList.remove('is-clipped');
+ $modals.forEach(function($el) {
+ $el.classList.remove('is-active');
+ });
}
});
+
});
diff --git a/shared/templates/forms/modal-form.html b/shared/templates/forms/modal-form.html
new file mode 100644
index 0000000..69c5d13
--- /dev/null
+++ b/shared/templates/forms/modal-form.html
@@ -0,0 +1,35 @@
+{% load i18n %}
+
+