diff --git a/app/modules/telefoni/templates/log.html b/app/modules/telefoni/templates/log.html index 24edc0b..1560638 100644 --- a/app/modules/telefoni/templates/log.html +++ b/app/modules/telefoni/templates/log.html @@ -850,6 +850,27 @@ function hasExistingCallRows(tbody) { return Boolean(tbody && tbody.querySelector('tr[data-call-id]')); } +function cacheInitialSsrRows(tbody) { + if (!tbody) return; + if (tbody.dataset.initialRowsCached === '1') return; + tbody.dataset.initialRowsHtml = tbody.innerHTML; + tbody.dataset.initialRowsCached = '1'; +} + +function restoreInitialSsrRows(tbody) { + if (!tbody) return false; + const initialHtml = String(tbody.dataset.initialRowsHtml || '').trim(); + if (!initialHtml) return false; + if (!initialHtml.includes('data-call-id')) return false; + + tbody.innerHTML = initialHtml; + tbody.classList.remove('d-none'); + tbody.style.display = ''; + tbody.style.visibility = ''; + tbody.style.opacity = ''; + return true; +} + function hasActiveCallFilters() { const userId = document.getElementById('filterUser')?.value; const from = document.getElementById('filterFrom')?.value; @@ -862,6 +883,7 @@ async function loadCalls(options = {}) { const preserveOnEmpty = Boolean(options.preserveOnEmpty); const skipLoadingState = Boolean(options.skipLoadingState); const tbody = document.getElementById('telefoniRows'); + cacheInitialSsrRows(tbody); const hadRowsBeforeLoad = hasExistingCallRows(tbody); const noActiveFilters = !hasActiveCallFilters(); @@ -888,6 +910,10 @@ async function loadCalls(options = {}) { console.warn('Telefoni: bevarer SSR-rækker efter tom/fejlende auto-refresh'); return; } + if (preserveOnEmpty && noActiveFilters && restoreInitialSsrRows(tbody)) { + console.warn('Telefoni: gendannede SSR-rækker efter API-fejl under auto-refresh'); + return; + } tbody.innerHTML = `