{{end}}
{{define "restore_banner"}}
{{end}}
{{define "restore_banner_js"}}
// Part B: restore-progress banner. Polls the async restore op-status every 3s. Shows a neutral
// "in progress" while running (including on a fresh page load mid-op), success on completion, and the
// error state ONLY on failure. Stops polling when idle after a terminal result was shown.
(function(){
var banner = document.getElementById('restore-banner');
if (!banner) return;
var sawRunning = false;
function opLabel(op){ return op === 'tier2-restore' ? '{{T "backups_shared.fajl_visszaallitas"}}'
: op === 'offbox-restore' ? '{{T "backups_shared.tavoli_visszaallitas"}}' : '{{T "backups_shared.visszaallitas"}}'; }
function render(st){
if (st.running) {
sawRunning = true;
banner.className = 'flash';
banner.style.display = 'block';
banner.textContent = opLabel(st.op) + ' {{T "backups_shared.folyamatban"}}' + (st.stack ? ': ' + st.stack : '') + '…';
return;
}
// R-351: `sawRunning` alone showed a terminal result ONLY to a page that watched the op
// happen. A restore that finished before this page was opened — or inside one poll interval
// — was shown to nobody, which is how a completed restore became unknowable from any screen.
// `last_recent` is the server's verdict, using the one window in internal/backup.
if (st.last && (sawRunning || st.last_recent)) {
banner.style.display = 'block';
if (st.last.ok) {
banner.className = 'flash flash-success';
banner.textContent = st.last.message || (opLabel(st.last.op) + ' {{T "backups_shared.kesz"}}');
} else {
banner.className = 'flash flash-error';
banner.textContent = st.last.message || (opLabel(st.last.op) + ' {{T "backups_shared.sikertelen"}}');
}
}
}
function poll(){
fetch('/api/backup/restore-status', {headers: {'Accept':'application/json'}})
.then(function(r){ return r.json(); })
.then(function(j){ if (j && j.data) render(j.data); })
.catch(function(){});
}
poll();
setInterval(poll, 3000);
})();
{{end}}