From 99be95aab11e6c68748f1ebece52a1057e4c0e17 Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Mon, 17 Nov 2025 16:34:40 +0300 Subject: [PATCH] POS search improvements: clear button, 600ms debounce, empty screen on clear --- myproject/pos/static/pos/js/terminal.js | 30 +++++++++++++++++++++-- myproject/pos/templates/pos/terminal.html | 7 +++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/myproject/pos/static/pos/js/terminal.js b/myproject/pos/static/pos/js/terminal.js index 6a3beed..3f96fae 100644 --- a/myproject/pos/static/pos/js/terminal.js +++ b/myproject/pos/static/pos/js/terminal.js @@ -1013,25 +1013,51 @@ function getCsrfToken() { // Обработчик поиска с debounce const searchInput = document.getElementById('searchInput'); +const clearSearchBtn = document.getElementById('clearSearchBtn'); + searchInput.addEventListener('input', (e) => { const query = e.target.value.trim(); + // Показываем/скрываем кнопку очистки + if (e.target.value.length > 0) { + clearSearchBtn.style.display = 'block'; + } else { + clearSearchBtn.style.display = 'none'; + } + // Отменяем предыдущий таймер if (searchDebounceTimer) { clearTimeout(searchDebounceTimer); } + // Если поле пустое — очищаем экран + if (query === '') { + currentSearchQuery = ''; + ITEMS = []; // Очистка + renderProducts(); // Пустой экран + return; + } + // Для витрины — мгновенная клиентская фильтрация if (isShowcaseView) { renderProducts(); return; } - // Для обычных товаров/комплектов — серверный поиск с debounce 300мс + // Для обычных товаров/комплектов — серверный поиск с debounce 600мс searchDebounceTimer = setTimeout(async () => { currentSearchQuery = query; await loadItems(); // Перезагрузка с серверным поиском - }, 300); + }, 600); +}); + +// Обработчик кнопки очистки поиска +clearSearchBtn.addEventListener('click', () => { + searchInput.value = ''; + clearSearchBtn.style.display = 'none'; + currentSearchQuery = ''; + ITEMS = []; + renderProducts(); // Пустой экран }); // Инициализация diff --git a/myproject/pos/templates/pos/terminal.html b/myproject/pos/templates/pos/terminal.html index 11d5798..ba75226 100644 --- a/myproject/pos/templates/pos/terminal.html +++ b/myproject/pos/templates/pos/terminal.html @@ -15,7 +15,12 @@
- +
+ + +