From 6abfd035d741458c6214df2931a09a321e2ffb41 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Fri, 28 May 2021 11:04:39 +0200 Subject: [PATCH] Utilisation d'un modal pour l'ajout et la modification d'options/questions --- .../templates/elections/election_admin.html | 32 ++++-- .../templates/elections/election_voters.html | 4 +- shared/locale/en/LC_MESSAGES/django.mo | Bin 14036 -> 14145 bytes shared/locale/en/LC_MESSAGES/django.po | 99 ++++++++++-------- 4 files changed, 77 insertions(+), 58 deletions(-) diff --git a/elections/templates/elections/election_admin.html b/elections/templates/elections/election_admin.html index bb16f08..6460df5 100644 --- a/elections/templates/elections/election_admin.html +++ b/elections/templates/elections/election_admin.html @@ -7,11 +7,23 @@ document.addEventListener('DOMContentLoaded', () => { var $modalButtons = document.querySelectorAll('.modal-button') || []; - $modalButtons.forEach(function($el) { - $el.addEventListener('click', function() { + $modalButtons.forEach($el => { + $el.addEventListener('click', () => { 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.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 @@ - + @@ -207,7 +219,8 @@ - + + @@ -246,7 +259,7 @@ {# Rajout d'une option #} {% if election.start_date > current_time %}
-