diff --git a/templates/adults.html b/templates/adults.html index 8087338..47b0394 100644 --- a/templates/adults.html +++ b/templates/adults.html @@ -923,6 +923,8 @@ } // Month range filter + var maxMonthIdx; + function applyMonthFilter() { var fromIdx = parseInt(document.getElementById('fromMonth').value); var toIdx = parseInt(document.getElementById('toMonth').value); @@ -940,17 +942,41 @@ var fromSelect = document.getElementById('fromMonth'); var toSelect = document.getElementById('toMonth'); fromSelect.value = 0; - toSelect.value = fromSelect.options.length - 1; + toSelect.value = maxMonthIdx; applyMonthFilter(); } - // Set defaults (last 5 months) and apply on load + // Remove future months from selects, set defaults, apply on load (function() { + var now = new Date(); + var currentMonth = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0'); + maxMonthIdx = sortedMonths.length - 1; + for (var i = 0; i < sortedMonths.length; i++) { + if (sortedMonths[i] > currentMonth) { + maxMonthIdx = i - 1; + break; + } + } + var fromSelect = document.getElementById('fromMonth'); var toSelect = document.getElementById('toMonth'); - var defaultFrom = Math.max(0, fromSelect.options.length - 5); + + // Remove future month options + for (var i = fromSelect.options.length - 1; i > maxMonthIdx; i--) { + fromSelect.remove(i); + toSelect.remove(i); + } + + // Hide future month columns permanently + document.querySelectorAll('[data-month-idx]').forEach(function(el) { + if (parseInt(el.getAttribute('data-month-idx')) > maxMonthIdx) { + el.classList.add('month-hidden'); + } + }); + + var defaultFrom = Math.max(0, maxMonthIdx - 4); fromSelect.value = defaultFrom; - toSelect.value = fromSelect.options.length - 1; + toSelect.value = maxMonthIdx; applyMonthFilter(); })(); diff --git a/templates/juniors.html b/templates/juniors.html index c177cf7..055700f 100644 --- a/templates/juniors.html +++ b/templates/juniors.html @@ -904,6 +904,8 @@ } // Month range filter + var maxMonthIdx; + function applyMonthFilter() { var fromIdx = parseInt(document.getElementById('fromMonth').value); var toIdx = parseInt(document.getElementById('toMonth').value); @@ -921,17 +923,41 @@ var fromSelect = document.getElementById('fromMonth'); var toSelect = document.getElementById('toMonth'); fromSelect.value = 0; - toSelect.value = fromSelect.options.length - 1; + toSelect.value = maxMonthIdx; applyMonthFilter(); } - // Set defaults (last 5 months) and apply on load + // Remove future months from selects, set defaults, apply on load (function() { + var now = new Date(); + var currentMonth = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0'); + maxMonthIdx = sortedMonths.length - 1; + for (var i = 0; i < sortedMonths.length; i++) { + if (sortedMonths[i] > currentMonth) { + maxMonthIdx = i - 1; + break; + } + } + var fromSelect = document.getElementById('fromMonth'); var toSelect = document.getElementById('toMonth'); - var defaultFrom = Math.max(0, fromSelect.options.length - 5); + + // Remove future month options + for (var i = fromSelect.options.length - 1; i > maxMonthIdx; i--) { + fromSelect.remove(i); + toSelect.remove(i); + } + + // Hide future month columns permanently + document.querySelectorAll('[data-month-idx]').forEach(function(el) { + if (parseInt(el.getAttribute('data-month-idx')) > maxMonthIdx) { + el.classList.add('month-hidden'); + } + }); + + var defaultFrom = Math.max(0, maxMonthIdx - 4); fromSelect.value = defaultFrom; - toSelect.value = fromSelect.options.length - 1; + toSelect.value = maxMonthIdx; applyMonthFilter(); })();