fix js, html

This commit is contained in:
Mateusz Gruszczyński
2025-07-26 12:30:29 +02:00
parent f2811148f1
commit 8db5cd82ac
2 changed files with 27 additions and 9 deletions

View File

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