refactor: use ListFilter component in employees list template

- Replaced custom applyFilter() function in employees_list.html with ListFilter component
- Reduced code from 16 lines to 11 lines (more declarative)
- Benefits:
  * Uses shared, tested ListFilter component
  * Automatic debouncing (300ms)
  * Cleaner, more maintainable code
  * Consistent filtering behavior across app

Analysis of other applyFilter() usage:
- department_scripts.html (2 instances): Complex logic with item selection, form interaction - kept as-is
- search/results.html: Multi-section filtering with radio buttons - kept as-is
- document_list.html: Array filtering, not DOM filtering - kept as-is

ListFilter component is ready for use in new features and templates.

Tests: All 17 tests passing ✅
This commit is contained in:
admin i 2025-10-28 08:43:57 +03:00
parent 3e1e618a62
commit baf06fb02f

View File

@ -238,22 +238,17 @@
</div>
</div>
<script>
(function () {
const input = document.getElementById('empFilter');
const clearBtn = document.querySelector('.ios-search-clear');
const list = document.getElementById('empList');
function applyFilter(){
const q = (input?.value || '').trim().toLowerCase();
list.querySelectorAll('.emp-row').forEach(row => {
const hay = [(row.dataset.name||''), (row.dataset.depts||'')].join(' ').toLowerCase();
row.style.display = (!q || hay.includes(q)) ? '' : 'none';
});
}
input?.addEventListener('input', applyFilter);
clearBtn?.addEventListener('click', () => { input.value=''; input.focus(); input.dispatchEvent(new Event('input')); });
applyFilter();
})();
<script type="module">
import { ListFilter, createDataAttrMatcher } from '{% static "js/components/listFilter.js" %}';
// Используем ListFilter вместо кастомной функции applyFilter()
new ListFilter({
listSelector: '#empList',
itemSelector: '.emp-row',
searchInputSelector: '#empFilter',
clearButtonSelector: '.ios-search-clear',
matchFn: createDataAttrMatcher(['name', 'depts']),
debounceMs: 300
});
</script>
{% endblock %}