From cf268523d8835e4ab3c9a80f4566cd6fef0937e3 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Wed, 13 Nov 2024 00:17:40 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20l'interface=20des=20fi?= =?UTF-8?q?ltre=20Voir=20issue=20#185?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/static/js/filters.js | 90 ------------------- src/agenda_culturel/static/style.scss | 54 ++++++++++- .../templates/agenda_culturel/filter-inc.html | 30 +++++-- .../forms/category-checkbox.html | 14 --- .../forms/checkbox-option.html | 4 - .../agenda_culturel/forms/tag-checkbox.html | 14 --- .../templates/agenda_culturel/page-month.html | 1 - .../agenda_culturel/page-upcoming.html | 1 - .../templates/agenda_culturel/page-week.html | 1 - src/agenda_culturel/views.py | 15 +--- 10 files changed, 79 insertions(+), 145 deletions(-) delete mode 100644 src/agenda_culturel/static/js/filters.js delete mode 100644 src/agenda_culturel/templates/agenda_culturel/forms/category-checkbox.html delete mode 100644 src/agenda_culturel/templates/agenda_culturel/forms/checkbox-option.html delete mode 100644 src/agenda_culturel/templates/agenda_culturel/forms/tag-checkbox.html diff --git a/src/agenda_culturel/static/js/filters.js b/src/agenda_culturel/static/js/filters.js deleted file mode 100644 index f9b968a..0000000 --- a/src/agenda_culturel/static/js/filters.js +++ /dev/null @@ -1,90 +0,0 @@ -let underToggle = false; - -const toggleElement = (event) => { - console.log(event.currentTarget.getAttribute("data-target")); - container = document.getElementById(event.currentTarget.getAttribute("data-target")); - setFilterClasses(container); -}; - - -// Toggle select all elements -const toggleSelectAllFilterElements = (event) => { - event.preventDefault(); - - selectAllFilterElementsFromCheckbox(event.currentTarget); -}; - -const selectAllFilterElementsFromCheckbox = (checkbox) => { - const container = document.getElementById(checkbox.getAttribute("data-target")); - active = checkbox.checked; - - Array.prototype.forEach.call(container.children, function(child) { - Array.prototype.forEach.call(child.getElementsByTagName("input"), function(elem) { - elem.checked = active; - }); - }); - setFilterClasses(container); -}; - -const setFilterClasses = (container) => { - if (!underToggle) { - underToggle = true; - selectionButtom = document.getElementById(container.getAttribute("data-button")); - checkboxes = container.getElementsByTagName("input"); - // count the number of selected elements - nbElemsChecked = 0; - for (i = 0; i < checkboxes.length; i++) { - if (checkboxes[i].checked) { - nbElemsChecked++; - } - } - - // count the number of elements - nbElems = checkboxes.length; - - // if all elements are deselected, the class "no-selected" is removed and the all selection button is deselected - if (nbElemsChecked == 0) { - Array.prototype.forEach.call(checkboxes, function(checkbox) { - checkbox.parentNode.parentNode.classList.remove("no-selected"); - }); - selectionButtom.checked = false; - selectionButtom.indeterminate = false; - } - else { - // otherwise, for each filter element, set "no-selected" class if required - Array.prototype.forEach.call(checkboxes, function(checkbox) { - if (checkbox.checked) - checkbox.parentNode.parentNode.classList.remove("no-selected"); - else - checkbox.parentNode.parentNode.classList.add("no-selected"); - }); - - // if all elements are selected, the all selection button is selected, otherwise its set to "indeterminate" - if (nbElems == nbElemsChecked) { - selectionButtom.checked = true; - selectionButtom.indeterminate = false; - } else { - selectionButtom.indeterminate = true; - selectionButtom.checked = false; - } - } - - underToggle = false; - } -} - -document.addEventListener("DOMContentLoaded", function(e) { - Array.prototype.forEach.call(document.getElementsByClassName("buttons-filter"), function(buttongroup) { - buttongroup.style.display = "inline-block"; - }); - - const buttonsAll = document.getElementsByClassName("all-elements"); - - Array.prototype.forEach.call(buttonsAll, function(button) { - const container = document.getElementById(button.getAttribute("data-target")); - setFilterClasses(container); - }); - - -}); - \ No newline at end of file diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index fd68e07..ec918c6 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -1152,7 +1152,7 @@ img.preview { overflow-y: scroll; } -.choices { +.choices[data-type=select-one] { .choices__inner { @extend [role="button"], .large; .choices__item { @@ -1211,13 +1211,63 @@ img.preview { } -.choices.is-open { +.choices[data-type=select-one].is-open { .choices__inner { .choices__item::after { transform: rotate(0); } } } + +.choices[data-type=select-multiple] { + .choices__input { + width: 100% !important; + } + .choices__item { + @extend [role="button"]; + background: transparent; + color: var(--primary); + font-size: 90%; + padding: 0.15em 0.4em 0.3em 0.4em; + display: inline-block; + margin: 0.2em !important; + height: 2.6em; + line-height: 2.2em; + + button { + @extend .outline; + display: inline-block; + border: 0; + background: transparent; + text-indent: -9999px; + padding: 0; + appearance: none; + width: 1.3em; + height: 1.3em; + margin-top: 0.25em; + vertical-align: middle; + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='#{to-rgb($primary-700)}' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='15' y1='9' x2='9' y2='15'%3E%3C/line%3E%3Cline x1='9' y1='9' x2='15' y2='15'%3E%3C/line%3E%3C/svg%3E"); + background-position: right; + background-repeat: no-repeat; + } + } + .choices__list--dropdown { + display: none; + will-change: display; + position: relative; + max-height: 300px; + overflow: auto; + -webkit-overflow-scrolling: touch; + will-change: scroll-position; + } + .choices__list--dropdown.is-active { + display: block; + } +} + + + + article { .stick-bottom { background: var(--card-sectionning-background-color); diff --git a/src/agenda_culturel/templates/agenda_culturel/filter-inc.html b/src/agenda_culturel/templates/agenda_culturel/filter-inc.html index b55e5a7..b897be5 100644 --- a/src/agenda_culturel/templates/agenda_culturel/filter-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/filter-inc.html @@ -74,12 +74,32 @@ diff --git a/src/agenda_culturel/templates/agenda_culturel/forms/category-checkbox.html b/src/agenda_culturel/templates/agenda_culturel/forms/category-checkbox.html deleted file mode 100644 index 888ac5f..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/forms/category-checkbox.html +++ /dev/null @@ -1,14 +0,0 @@ -{% load cat_extra %} -
- -
-{% with container_id=widget.attrs.id %} -
{% for group, options, index in widget.optgroups %}{% if group %} -
{% endif %}{% for widget in options %}
- {{ widget.value.instance | circle_cat }}{% include widget.template_name %}
{% endfor %}{% if group %} -
{% endif %}{% endfor %} -
-{% endwith %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/forms/checkbox-option.html b/src/agenda_culturel/templates/agenda_culturel/forms/checkbox-option.html deleted file mode 100644 index 4d4260c..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/forms/checkbox-option.html +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/src/agenda_culturel/templates/agenda_culturel/forms/tag-checkbox.html b/src/agenda_culturel/templates/agenda_culturel/forms/tag-checkbox.html deleted file mode 100644 index 0f1154a..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/forms/tag-checkbox.html +++ /dev/null @@ -1,14 +0,0 @@ -{% load cat_extra %} -
- -
-{% with container_id=widget.attrs.id %} -
{% for group, options, index in widget.optgroups %}{% if group %} -
{% endif %}{% for widget in options %}
- {% include widget.template_name %}
{% endfor %}{% if group %} -
{% endif %}{% endfor %} -
-{% endwith %} diff --git a/src/agenda_culturel/templates/agenda_culturel/page-month.html b/src/agenda_culturel/templates/agenda_culturel/page-month.html index d879cac..e07907b 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-month.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-month.html @@ -13,7 +13,6 @@ {% block entete_header %} {% css_categories %} - {% endblock %} diff --git a/src/agenda_culturel/templates/agenda_culturel/page-upcoming.html b/src/agenda_culturel/templates/agenda_culturel/page-upcoming.html index 26236d2..7cd65e3 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-upcoming.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-upcoming.html @@ -12,7 +12,6 @@ {% block entete_header %} {% css_categories %} - {% endblock %} {% block ce_mois_ci_parameters %}{% block cette_semaine_parameters %}{% block a_venir_parameters %}?{{ filter.get_url }}{% endblock %}{% endblock %}{% endblock %} diff --git a/src/agenda_culturel/templates/agenda_culturel/page-week.html b/src/agenda_culturel/templates/agenda_culturel/page-week.html index 748542d..d4e7c0e 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-week.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-week.html @@ -12,7 +12,6 @@ {% block entete_header %} {% css_categories %} - {% endblock %} diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index e337ff9..67d2d83 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -158,17 +158,6 @@ def internal_server_error(request): def thank_you(request): return render(request, "agenda_culturel/thank_you.html") - -class CategoryCheckboxSelectMultiple(forms.CheckboxSelectMultiple): - template_name = "agenda_culturel/forms/category-checkbox.html" - option_template_name = "agenda_culturel/forms/checkbox-option.html" - - -class TagCheckboxSelectMultiple(forms.CheckboxSelectMultiple): - template_name = "agenda_culturel/forms/tag-checkbox.html" - option_template_name = "agenda_culturel/forms/checkbox-option.html" - - class EventFilter(django_filters.FilterSet): RECURRENT_CHOICES = [ ("remove_recurrent", "Masquer les événements récurrents"), @@ -198,7 +187,7 @@ class EventFilter(django_filters.FilterSet): lookup_expr="icontains", field_name="tags", exclude=True, - widget=TagCheckboxSelectMultiple, + widget=forms.SelectMultiple, ) tags = django_filters.MultipleChoiceFilter( @@ -207,7 +196,7 @@ class EventFilter(django_filters.FilterSet): lookup_expr="icontains", conjoined=True, field_name="tags", - widget=TagCheckboxSelectMultiple, + widget=forms.SelectMultiple, ) recurrences = django_filters.ChoiceFilter(