Добавлено подключение обработчиков для кнопок "Сегодня", "Завтра" и "Сбросить" в компоненте фильтрации по датам

This commit is contained in:
2025-12-29 01:31:14 +03:00
parent 1f8fd54c10
commit d66ea020f6
2 changed files with 76 additions and 10 deletions

View File

@@ -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();
}
}

View File

@@ -26,6 +26,18 @@
title="Сегодня">
Сегодня
</button>
<button type="button" class="btn btn-sm btn-outline-primary ms-1 tomorrow-btn"
data-min-input="{{ field_after.id_for_label }}"
data-max-input="{{ field_before.id_for_label }}"
title="Завтра">
Завтра
</button>
<button type="button" class="btn btn-sm btn-outline-secondary ms-1 clear-date-btn"
data-min-input="{{ field_after.id_for_label }}"
data-max-input="{{ field_before.id_for_label }}"
title="Сбросить дату">
<i class="bi bi-x-lg"></i>
</button>
</div>
<!-- Скрытые поля для хранения дат -->