Utilisation d'un modal pour l'ajout et la modification d'options/questions

This commit is contained in:
Tom Hubrecht 2021-05-28 11:04:39 +02:00
parent b1488c7c8a
commit 6abfd035d7
4 changed files with 77 additions and 58 deletions

View file

@ -7,11 +7,23 @@
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
var $modalButtons = document.querySelectorAll('.modal-button') || []; var $modalButtons = document.querySelectorAll('.modal-button') || [];
$modalButtons.forEach(function($el) { $modalButtons.forEach($el => {
$el.addEventListener('click', function() { $el.addEventListener('click', () => {
var $target = document.getElementById($el.dataset.target); var $target = document.getElementById($el.dataset.target);
$target_form = $target.querySelector("form"); var $target_form = $target.querySelector("form");
var modal_title = '';
$target_form.action = $el.dataset.post_url; $target_form.action = $el.dataset.post_url;
$target.querySelector('.modal-card-title').innerHTML = $el.dataset.title;
if ($el.classList.contains('question')) {
$target_form.querySelector('#id_text_fr').value = $el.dataset.q_fr || '';
$target_form.querySelector('#id_text_en').value = $el.dataset.q_en || '';
$target_form.querySelector('#id_type').value = $el.dataset.type || 'assentiment';
} else if ($el.classList.contains('option')) {
$target_form.querySelector('#id_text_fr').value = $el.dataset.o_fr || '';
$target_form.querySelector('#id_text_en').value = $el.dataset.o_en || '';
$target_form.querySelector('#id_abbreviation').value = $el.dataset.abbr || '';
}
}); });
}); });
}); });
@ -179,7 +191,7 @@
</span> </span>
</a> </a>
<a class="tag is-outlined is-light is-info ml-1" href="{% url 'election.mod-question' q.pk %}"> <a class="tag is-outlined is-light is-info ml-1 modal-button question" data-post_url="{% url 'election.mod-question' q.pk %}" data-target="modal-question" data-type="{{ q.type }}" data-q_en="{{ q.text_en }}" data-q_fr="{{ q.text_fr }}" data-title="{% trans "Modifier la question" %}">
<span class="icon-text"> <span class="icon-text">
<span class="icon"> <span class="icon">
<i class="fas fa-edit"></i> <i class="fas fa-edit"></i>
@ -207,7 +219,8 @@
<i class="fas fa-times"></i> <i class="fas fa-times"></i>
</span> </span>
</a> </a>
<a class="tag is-info is-light is-outlined has-tooltip-primary mb-0" data-tooltip="{% trans "Modifier" %}" href="{% url 'election.mod-option' o.pk %}">
<a class="tag is-info is-light is-outlined has-tooltip-primary mb-0 modal-button option" data-tooltip="{% trans "Modifier" %}" data-post_url="{% url 'election.mod-option' o.pk %}" data-target="modal-option" data-o_en="{{ o.text_en }}" data-o_fr="{{ o.text_fr }}" data-abbr="{{ o.abbreviation }}" data-title="{% trans "Modifier l'option" %}">
<span class="icon"> <span class="icon">
<i class="fas fa-edit"></i> <i class="fas fa-edit"></i>
</span> </span>
@ -246,7 +259,7 @@
{# Rajout d'une option #} {# Rajout d'une option #}
{% if election.start_date > current_time %} {% if election.start_date > current_time %}
<div class="panel-block"> <div class="panel-block">
<button class="button modal-button is-primary is-outlined is-fullwidth" data-post_url="{% url 'election.add-option' q.pk %}" data-target="modal-add_option"> <button class="button modal-button is-primary is-outlined is-fullwidth option" data-post_url="{% url 'election.add-option' q.pk %}" data-target="modal-option" data-title="{% trans "Rajouter une option" %}">
<span class="icon"> <span class="icon">
<i class="fas fa-plus"></i> <i class="fas fa-plus"></i>
</span> </span>
@ -262,16 +275,15 @@
{# Rajout d'une option #} {# Rajout d'une option #}
{% trans "Rajouter une option" as modal_title %} {% trans "Rajouter une option" as modal_title %}
{% include "forms/modal-form.html" with modal_id="add_option" form=o_form %} {% include "forms/modal-form.html" with modal_id="option" form=o_form %}
{# Rajout d'une question #} {# Rajout d'une question #}
{% trans "Rajouter une question" as modal_title %} {% trans "Rajouter une question" as modal_title %}
{% include "forms/modal-form.html" with modal_id="add_question" form=q_form %} {% include "forms/modal-form.html" with modal_id="question" form=q_form %}
<div class="columns is-centered" id="q_add"> <div class="columns is-centered" id="q_add">
<div class="column is-two-thirds"> <div class="column is-two-thirds">
<button class="button modal-button is-primary is-outlined is-fullwidth" data-post_url="{% url 'election.add-question' election.pk %}" data-target="modal-add_question"> <button class="button modal-button is-primary is-outlined is-fullwidth question" data-post_url="{% url 'election.add-question' election.pk %}" data-target="modal-question" data-title="{% trans "Rajouter une question" %}">
<span class="icon"> <span class="icon">
<i class="fas fa-question"></i> <i class="fas fa-question"></i>
</span> </span>

View file

@ -13,8 +13,8 @@
$del_buttons.forEach($del => { $del_buttons.forEach($del => {
$del.addEventListener('click', () => { $del.addEventListener('click', () => {
$del_form.action = $del.dataset['post_url']; $del_form.action = $del.dataset.post_url;
$del_title.innerHTML = $del.dataset['tooltip']; $del_title.innerHTML = $del.dataset.tooltip;
}); });
}); });
}); });

View file

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 0.1\n" "Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-05-27 00:24+0200\n" "POT-Creation-Date: 2021-05-28 10:58+0200\n"
"PO-Revision-Date: 2021-05-27 00:26+0200\n" "PO-Revision-Date: 2021-05-28 10:59+0200\n"
"Last-Translator: Test Translator <test@translator>\n" "Last-Translator: Test Translator <test@translator>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: en\n" "Language: en\n"
@ -56,9 +56,9 @@ msgstr ""
msgid "Supprimer le vote de {} ({}) ?" msgid "Supprimer le vote de {} ({}) ?"
msgstr "Delete the vote of {} ({}) ?" msgstr "Delete the vote of {} ({}) ?"
#: elections/forms.py:110 elections/templates/elections/election_admin.html:178 #: elections/forms.py:110 elections/templates/elections/election_admin.html:191
#: elections/templates/elections/election_admin.html:205 #: elections/templates/elections/election_admin.html:218
#: elections/templates/elections/election_voters.html:57 #: elections/templates/elections/election_voters.html:82
msgid "Supprimer" msgid "Supprimer"
msgstr "Delete" msgstr "Delete"
@ -261,7 +261,7 @@ msgstr ""
"received by e-mail." "received by e-mail."
#: elections/templates/elections/election.html:132 #: elections/templates/elections/election.html:132
#: elections/templates/elections/election_voters.html:44 #: elections/templates/elections/election_voters.html:65
msgid "" msgid ""
"Pour voter lors de cette élection, vous devez vous connecter à l'aide du CAS " "Pour voter lors de cette élection, vous devez vous connecter à l'aide du CAS "
"élève, d'autres restrictions peuvent s'appliquer et votre vote pourra être " "élève, d'autres restrictions peuvent s'appliquer et votre vote pourra être "
@ -284,59 +284,68 @@ msgstr "Login via CAS"
msgid "A voté" msgid "A voté"
msgstr "Voted" msgstr "Voted"
#: elections/templates/elections/election_admin.html:40 #: elections/templates/elections/election_admin.html:21
#: elections/templates/elections/election_admin.html:282
#: elections/templates/elections/election_admin.html:291
msgid "Rajouter une question"
msgstr "Add a question"
#: elections/templates/elections/election_admin.html:21
msgid "Modifier la question"
msgstr "Change the question"
#: elections/templates/elections/election_admin.html:26
#: elections/templates/elections/election_admin.html:267
#: elections/templates/elections/election_admin.html:278
msgid "Rajouter une option"
msgstr "Add an option"
#: elections/templates/elections/election_admin.html:26
msgid "Modifier l'option"
msgstr "Change the option"
#: elections/templates/elections/election_admin.html:53
msgid "Actions" msgid "Actions"
msgstr "Actions" msgstr "Actions"
#: elections/templates/elections/election_admin.html:52 #: elections/templates/elections/election_admin.html:65
msgid "Exporter les votant·e·s" msgid "Exporter les votant·e·s"
msgstr "Export the list of voters" msgstr "Export the list of voters"
#: elections/templates/elections/election_admin.html:61 #: elections/templates/elections/election_admin.html:74
#: elections/templates/elections/election_admin.html:187 #: elections/templates/elections/election_admin.html:200
#: elections/templates/elections/election_admin.html:210 #: elections/templates/elections/election_admin.html:224
msgid "Modifier" msgid "Modifier"
msgstr "Edit" msgstr "Edit"
#: elections/templates/elections/election_admin.html:70 #: elections/templates/elections/election_admin.html:83
#: elections/templates/elections/upload_voters.html:27 #: elections/templates/elections/upload_voters.html:27
msgid "Gestion de la liste de votant·e·s" msgid "Gestion de la liste de votant·e·s"
msgstr "Management of the voters' list" msgstr "Management of the voters' list"
#: elections/templates/elections/election_admin.html:82 #: elections/templates/elections/election_admin.html:95
#: elections/templates/elections/election_voters.html:27 #: elections/templates/elections/election_voters.html:48
msgid "Liste des votant·e·s" msgid "Liste des votant·e·s"
msgstr "Voters' list" msgstr "Voters' list"
#: elections/templates/elections/election_admin.html:90 #: elections/templates/elections/election_admin.html:103
msgid "Dépouiller" msgid "Dépouiller"
msgstr "Count" msgstr "Count"
#: elections/templates/elections/election_admin.html:102 #: elections/templates/elections/election_admin.html:115
msgid "Publier" msgid "Publier"
msgstr "Publish" msgstr "Publish"
#: elections/templates/elections/election_admin.html:104 #: elections/templates/elections/election_admin.html:117
msgid "Dépublier" msgid "Dépublier"
msgstr "De-publish" msgstr "De-publish"
#: elections/templates/elections/election_admin.html:115 #: elections/templates/elections/election_admin.html:128
msgid "Archiver" msgid "Archiver"
msgstr "Archive" msgstr "Archive"
#: elections/templates/elections/election_admin.html:253
#: elections/templates/elections/election_admin.html:264
msgid "Rajouter une option"
msgstr "Add an option"
#: elections/templates/elections/election_admin.html:268
#: elections/templates/elections/election_admin.html:278
msgid "Rajouter une question"
msgstr "Add a question"
#: elections/templates/elections/election_ballots.html:18 #: elections/templates/elections/election_ballots.html:18
#: elections/templates/elections/election_voters.html:19 #: elections/templates/elections/election_voters.html:40
#: elections/templates/elections/option_update.html:37
#: elections/templates/elections/upload_voters.html:48 #: elections/templates/elections/upload_voters.html:48
#: elections/templates/elections/vote.html:49 #: elections/templates/elections/vote.html:49
#: shared/templates/auth/election_login.html:34 #: shared/templates/auth/election_login.html:34
@ -354,17 +363,6 @@ msgstr "List of ballots"
msgid "Création d'une élection" msgid "Création d'une élection"
msgstr "Creating an election" msgstr "Creating an election"
#: elections/templates/elections/election_create.html:41
#: elections/templates/elections/option_update.html:29
#: elections/templates/elections/vote.html:40
#: shared/templates/auth/create-user.html:23
#: shared/templates/auth/election_login.html:25
#: shared/templates/authens/pwd_login.html:25
#: shared/templates/authens/pwd_reset_confirm.html:25
#: shared/templates/forms/modal-form.html:23
msgid "Enregistrer"
msgstr "Save"
#: elections/templates/elections/election_list.html:10 #: elections/templates/elections/election_list.html:10
msgid "Liste des élections" msgid "Liste des élections"
msgstr "List of elections" msgstr "List of elections"
@ -389,7 +387,7 @@ msgstr "Archived election"
msgid "Modification d'une élection" msgid "Modification d'une élection"
msgstr "Editing an election" msgstr "Editing an election"
#: elections/templates/elections/election_voters.html:42 #: elections/templates/elections/election_voters.html:63
msgid "" msgid ""
"Seules les personnes présentes sur cette liste peuvent voter, vous avez dû " "Seules les personnes présentes sur cette liste peuvent voter, vous avez dû "
"recevoir un mail avec vos identifiants de connexion." "recevoir un mail avec vos identifiants de connexion."
@ -397,16 +395,16 @@ msgstr ""
"Only people on this list can vote, you should have received an e-mail with " "Only people on this list can vote, you should have received an e-mail with "
"your login credentials." "your login credentials."
#: elections/templates/elections/election_voters.html:54 #: elections/templates/elections/election_voters.html:79
#: elections/templates/elections/upload_voters.html:107 #: elections/templates/elections/upload_voters.html:107
msgid "Nom" msgid "Nom"
msgstr "Name" msgstr "Name"
#: elections/templates/elections/election_voters.html:55 #: elections/templates/elections/election_voters.html:80
msgid "Vote enregistré" msgid "Vote enregistré"
msgstr "Recorded vote" msgstr "Recorded vote"
#: elections/templates/elections/election_voters.html:89 #: elections/templates/elections/election_voters.html:113
#, python-format #, python-format
msgid "Supprimer le vote de %(v_name)s" msgid "Supprimer le vote de %(v_name)s"
msgstr "Delete the vote of %(v_name)s" msgstr "Delete the vote of %(v_name)s"
@ -499,6 +497,15 @@ msgstr "E-mail"
msgid "Vote pour la question :" msgid "Vote pour la question :"
msgstr "Vote for the question:" msgstr "Vote for the question:"
#: elections/templates/elections/vote.html:40
#: shared/templates/auth/create-user.html:23
#: shared/templates/auth/election_login.html:25
#: shared/templates/authens/pwd_login.html:25
#: shared/templates/authens/pwd_reset_confirm.html:25
#: shared/templates/forms/modal-form.html:23
msgid "Enregistrer"
msgstr "Save"
#: elections/templates/elections/vote.html:57 #: elections/templates/elections/vote.html:57
msgid "Confirmation du vote" msgid "Confirmation du vote"
msgstr "Confirmation of the vote" msgstr "Confirmation of the vote"
@ -631,7 +638,7 @@ msgstr "Option successfully modified!"
msgid "Option supprimée !" msgid "Option supprimée !"
msgstr "Option deleted!" msgstr "Option deleted!"
#: elections/views.py:568 #: elections/views.py:566
msgid "Votre choix a bien été enregistré !" msgid "Votre choix a bien été enregistré !"
msgstr "Your choice has been recorded!" msgstr "Your choice has been recorded!"