diff --git a/static/js/user_expense_lists.js b/static/js/user_expense_lists.js index 7c7460f..f7ef99d 100644 --- a/static/js/user_expense_lists.js +++ b/static/js/user_expense_lists.js @@ -1,13 +1,21 @@ document.addEventListener('DOMContentLoaded', () => { const checkboxes = document.querySelectorAll('.list-checkbox'); const totalEl = document.getElementById('listsTotal'); - const filterButtons = document.querySelectorAll('.filter-btn'); + const filterButtons = document.querySelectorAll('.range-btn'); const rows = document.querySelectorAll('#listsTableBody tr'); const onlyWith = document.getElementById('onlyWithExpenses'); const customStart = document.getElementById('customStart'); const customEnd = document.getElementById('customEnd'); + // Przywróć zapisane daty + if (localStorage.getItem('customStart')) { + customStart.value = localStorage.getItem('customStart'); + } + if (localStorage.getItem('customEnd')) { + customEnd.value = localStorage.getItem('customEnd'); + } + function updateTotal() { let total = 0; checkboxes.forEach(cb => { @@ -32,6 +40,10 @@ document.addEventListener('DOMContentLoaded', () => { btn.classList.add('active'); const range = btn.dataset.range; + // Czyść lokalne daty przy kliknięciu zakresu + localStorage.removeItem('customStart'); + localStorage.removeItem('customEnd'); + const now = new Date(); const todayStr = now.toISOString().slice(0, 10); const year = now.getFullYear(); @@ -58,7 +70,6 @@ document.addEventListener('DOMContentLoaded', () => { }); }); - // ISO week helper function getISOWeek(date) { const target = new Date(date.valueOf()); const dayNr = (date.getDay() + 6) % 7; @@ -68,11 +79,14 @@ document.addEventListener('DOMContentLoaded', () => { return 1 + Math.floor(dayDiff / 7); } - // Zakres dat: kliknij „Zastosuj zakres” document.getElementById('applyCustomRange').addEventListener('click', () => { const start = customStart.value; const end = customEnd.value; + // Zapamiętaj daty + localStorage.setItem('customStart', start); + localStorage.setItem('customEnd', end); + filterButtons.forEach(b => b.classList.remove('active')); rows.forEach(row => { @@ -85,7 +99,6 @@ document.addEventListener('DOMContentLoaded', () => { updateTotal(); }); - // Filtrowanie tylko list z wydatkami if (onlyWith) { onlyWith.addEventListener('change', () => { applyExpenseFilter(); @@ -100,6 +113,12 @@ document.addEventListener('DOMContentLoaded', () => { if (amt <= 0) row.style.display = 'none'; }); } + + // Domyślnie kliknij „Miesiąc” + const defaultBtn = document.querySelector('.range-btn[data-range="month"]'); + if (defaultBtn && !customStart.value && !customEnd.value) { + defaultBtn.click(); + } }); document.addEventListener("DOMContentLoaded", function () { @@ -138,4 +157,4 @@ document.getElementById("showAllLists").addEventListener("change", function () { url.searchParams.delete("show_all"); } window.location.href = url.toString(); -}); \ No newline at end of file +}); diff --git a/templates/user_expenses.html b/templates/user_expenses.html index f991dd6..77a149c 100644 --- a/templates/user_expenses.html +++ b/templates/user_expenses.html @@ -38,14 +38,13 @@