diff --git a/itou/static/css/itou.css b/itou/static/css/itou.css index 7d5bf6d8515..74bf4e1834a 100644 --- a/itou/static/css/itou.css +++ b/itou/static/css/itou.css @@ -148,11 +148,6 @@ margin-left: 2px; } -.c-aside-filters .select2-container--bootstrap-5 { - width: auto !important; - display: block !important; -} - /* Force the display of `.invalid-feedback` for Duet Date Picker with Bootstrap 4. See also `duet_date_picker.html`. @@ -466,3 +461,8 @@ an input field being invalid, generating an uncontrolled red box-shadow. */ border-top-left-radius: 0.5rem; border-top-right-radius: 0.5rem; } + +/* Fix for form.company and form.job_seeker width */ +.w-lg-400px .select2-selection__rendered { + white-space: nowrap !important; +} diff --git a/itou/static/js/htmx_dropdown_filter.js b/itou/static/js/htmx_dropdown_filter.js index f39105ef961..23c7d5b7269 100644 --- a/itou/static/js/htmx_dropdown_filter.js +++ b/itou/static/js/htmx_dropdown_filter.js @@ -1,10 +1,49 @@ -htmx.onLoad((target) => { +(function() { + const filtersContentId = "offcanvasApplyFiltersContent"; + const filtersContent = document.getElementById(filtersContentId); + const filtersCount = document.getElementById("all-filters-btn"); + + function fieldHasValue(container) { + return ( + container.querySelector('input:checked:not([value=""])') + || container.querySelector('input[value]:not([type=checkbox]):not([type=radio]):not([value=""])') + || container.querySelector('duet-date-picker[value]:not([value=""])') + || container.querySelector("select > option:not([value=''])[selected]") + ); + } + function toggleHasSelectedItem() { const dropdown = this.closest('.dropdown'); - this.classList.toggle('has-selected-item', dropdown.querySelector('input:checked:not([value=""])')); + this.classList.toggle('has-selected-item', fieldHasValue(dropdown)); + this.classList.toggle('font-weight-bold', fieldHasValue(dropdown)); + } + + function initFilters(sidebar) { + let activeFiltersCount = 0; + Array.from(sidebar.querySelectorAll(".collapsed")).forEach((collapse) => { + const collapseTarget = document.querySelector(collapse.dataset.bsTarget); + if (fieldHasValue(collapseTarget)) { + activeFiltersCount++; + bootstrap.Collapse.getOrCreateInstance(collapseTarget, { delay: 0 }).show(); + } + }); + if (filtersCount) { + filtersCount.textContent = activeFiltersCount ? ` (${activeFiltersCount})` : ""; + } + } + + function onLoad(target) { + target.querySelectorAll('.btn-dropdown-filter.dropdown-toggle').forEach((dropdownFilter) => { + dropdownFilter.addEventListener('hide.bs.dropdown', toggleHasSelectedItem); + toggleHasSelectedItem.call(dropdownFilter); + }); + if (target.id === filtersContentId) { + initFilters(target); + } + } + + if (filtersContent) { + initFilters(filtersContent); } - target.querySelectorAll('.btn-dropdown-filter.dropdown-toggle').forEach((dropdownFilter) => { - dropdownFilter.addEventListener('hide.bs.dropdown', toggleHasSelectedItem); - toggleHasSelectedItem.call(dropdownFilter); - }); -}); + htmx.onLoad(onLoad); +})(); diff --git a/itou/templates/search/includes/siaes_search_filters.html b/itou/templates/search/includes/siaes_search_filters.html deleted file mode 100644 index bdd844bf9c8..00000000000 --- a/itou/templates/search/includes/siaes_search_filters.html +++ /dev/null @@ -1,37 +0,0 @@ -{% load django_bootstrap5 %} - - diff --git a/itou/templates/search/includes/siaes_search_filters_company.html b/itou/templates/search/includes/siaes_search_filters_company.html deleted file mode 100644 index 2fccf9e5f0d..00000000000 --- a/itou/templates/search/includes/siaes_search_filters_company.html +++ /dev/null @@ -1,9 +0,0 @@ -{% load django_bootstrap5 %} -