From d66ea020f67a14ef46128dc6748bd6e1031f0c29 Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Mon, 29 Dec 2025 01:31:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B8=D0=BA=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F=20=D0=BA?= =?UTF-8?q?=D0=BD=D0=BE=D0=BF=D0=BE=D0=BA=20"=D0=A1=D0=B5=D0=B3=D0=BE?= =?UTF-8?q?=D0=B4=D0=BD=D1=8F",=20"=D0=97=D0=B0=D0=B2=D1=82=D1=80=D0=B0"?= =?UTF-8?q?=20=D0=B8=20"=D0=A1=D0=B1=D1=80=D0=BE=D1=81=D0=B8=D1=82=D1=8C"?= =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B5=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BF=D0=BE=20=D0=B4=D0=B0=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orders/static/orders/js/date_filter.js | 74 ++++++++++++++++--- .../orders/components/date_range_filter.html | 12 +++ 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/myproject/orders/static/orders/js/date_filter.js b/myproject/orders/static/orders/js/date_filter.js index 6f8f7ad..2182aeb 100644 --- a/myproject/orders/static/orders/js/date_filter.js +++ b/myproject/orders/static/orders/js/date_filter.js @@ -336,20 +336,34 @@ class DateCarousel { } /** - * Подключение обработчика для кнопки "Сегодня" + * Подключение обработчиков для кнопок "Сегодня", "Завтра" и "Сбросить" * Вынесено в отдельный метод, чтобы можно было вызывать после полной отрисовки компонента */ attachTodayHandler() { - // Ищем кнопку "Сегодня" в общем контейнере фильтра, используя атрибуты данных - const todayBtn = this.container.closest('.date-range-filter').querySelector('.today-btn'); + const filterContainer = this.container.closest('.date-range-filter'); + // Кнопка "Сегодня" + const todayBtn = filterContainer.querySelector('.today-btn'); if (todayBtn) { - todayBtn.removeEventListener('click', this.boundGoToToday); // Удаляем предыдущий обработчик, если был + todayBtn.removeEventListener('click', this.boundGoToToday); this.boundGoToToday = this.goToToday.bind(this); todayBtn.addEventListener('click', this.boundGoToToday); - console.log('Today button handler attached'); - } else { - console.error('Today button not found when trying to attach handler'); + } + + // Кнопка "Завтра" + const tomorrowBtn = filterContainer.querySelector('.tomorrow-btn'); + if (tomorrowBtn) { + tomorrowBtn.removeEventListener('click', this.boundGoToTomorrow); + this.boundGoToTomorrow = this.goToTomorrow.bind(this); + tomorrowBtn.addEventListener('click', this.boundGoToTomorrow); + } + + // Кнопка "Сбросить" + const clearBtn = filterContainer.querySelector('.clear-date-btn'); + if (clearBtn) { + clearBtn.removeEventListener('click', this.boundClearDate); + this.boundClearDate = this.clearDate.bind(this); + clearBtn.addEventListener('click', this.boundClearDate); } } @@ -392,10 +406,50 @@ class DateCarousel { // Автоматическая отправка формы const form = this.minInput.closest('form'); if (form) { - console.log('Submitting form'); form.submit(); - } else { - console.error('Form not found!'); + } + } + + /** + * Переход к завтрашней дате + */ + goToTomorrow() { + const tomorrow = new Date(); + tomorrow.setHours(0, 0, 0, 0); + tomorrow.setDate(tomorrow.getDate() + 1); + + const formattedDate = this.formatDate(tomorrow); + this.minInput.value = formattedDate; + this.maxInput.value = formattedDate; + + this.centerDate = tomorrow; + this.saveCenterDate(); + this.render(); + this.attachTodayHandler(); + + const form = this.minInput.closest('form'); + if (form) { + form.submit(); + } + } + + /** + * Сброс фильтра по дате + */ + clearDate() { + this.minInput.value = ''; + this.maxInput.value = ''; + + // Возвращаем карусель к сегодняшней дате + this.centerDate = new Date(); + this.centerDate.setHours(0, 0, 0, 0); + this.saveCenterDate(); + this.render(); + this.attachTodayHandler(); + + const form = this.minInput.closest('form'); + if (form) { + form.submit(); } } diff --git a/myproject/orders/templates/orders/components/date_range_filter.html b/myproject/orders/templates/orders/components/date_range_filter.html index 6840578..96746b1 100644 --- a/myproject/orders/templates/orders/components/date_range_filter.html +++ b/myproject/orders/templates/orders/components/date_range_filter.html @@ -26,6 +26,18 @@ title="Сегодня"> Сегодня + +