From efeb39620482aa32007c64a9c57cc44dff931eec Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Fri, 7 Nov 2025 20:37:17 +0300 Subject: [PATCH] Add 'Today' button next to date filter label --- .../orders/static/orders/js/date_filter.js | 35 +++++++++++++++++++ .../orders/components/date_range_filter.html | 17 ++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/myproject/orders/static/orders/js/date_filter.js b/myproject/orders/static/orders/js/date_filter.js index c8ace57..ec9abd6 100644 --- a/myproject/orders/static/orders/js/date_filter.js +++ b/myproject/orders/static/orders/js/date_filter.js @@ -361,6 +361,7 @@ class DateCarousel { attachNavHandlers() { const prevBtn = this.container.parentElement.querySelector('.carousel-prev'); const nextBtn = this.container.parentElement.querySelector('.carousel-next'); + const todayBtn = this.container.parentElement.querySelector('.today-btn'); if (prevBtn) { prevBtn.addEventListener('click', () => this.shiftDays(-1)); @@ -369,6 +370,40 @@ class DateCarousel { if (nextBtn) { nextBtn.addEventListener('click', () => this.shiftDays(1)); } + + if (todayBtn) { + todayBtn.addEventListener('click', () => this.goToToday()); + } + } + + /** + * Переход к сегодняшней дате + */ + goToToday() { + const today = new Date(); + today.setHours(0, 0, 0, 0); + + // Устанавливаем сегодняшнюю дату в фильтр + const formattedDate = this.formatDate(today); + this.minInput.value = formattedDate; + this.maxInput.value = formattedDate; + + // Устанавливаем сегодняшнюю дату как центральную + this.centerDate = today; + + // Сохраняем новую центральную дату без смещения + this.saveCenterDate(); + + // Очищаем выделение с других кнопок и обновляем визуальное состояние + this.render(); + + console.log(`Navigated to today: ${formattedDate}`); + + // Автоматическая отправка формы + 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 a7ef96a..fc2e87f 100644 --- a/myproject/orders/templates/orders/components/date_range_filter.html +++ b/myproject/orders/templates/orders/components/date_range_filter.html @@ -14,10 +14,19 @@ {% load static %}
- +
+ + + +