UI: Nextcloud gumb \u2014 optimistic feedback. Takoj ob kliku gumb postane oran\u017een "\u23f3 Po\u0161iljam...", disabled, cursor:wait. Po uspe\u0161nem upload-u refreshJobs() zamenja v zelen \u2713 Nextcloud. Pri napaki vrne original state.
This commit is contained in:
parent
6a9e20da19
commit
48bf0cf050
@ -1236,18 +1236,30 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function uploadToNextcloud(id, title) {
|
async function uploadToNextcloud(id, title) {
|
||||||
|
// Optimistic UI: takoj zamrzni vse Nextcloud gumbe za ta job in pokazi "Posiljam..."
|
||||||
|
const btns = document.querySelectorAll(`button[data-action="nextcloud"][data-id="${id}"]`);
|
||||||
|
const orig = [];
|
||||||
|
btns.forEach(b => {
|
||||||
|
orig.push({ btn: b, html: b.innerHTML, disabled: b.disabled, style: b.getAttribute("style") || "" });
|
||||||
|
b.disabled = true;
|
||||||
|
b.innerHTML = '⏳ Pošiljam...';
|
||||||
|
b.setAttribute("style", "border-color:#f59e0b; color:#f59e0b; opacity:0.85; cursor:wait;");
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
const r = await fetch(`/api/jobs/${id}/upload-nextcloud`, { method: "POST" });
|
const r = await fetch(`/api/jobs/${id}/upload-nextcloud`, { method: "POST" });
|
||||||
if (!r.ok) {
|
if (!r.ok) {
|
||||||
const err = await r.json().catch(() => ({}));
|
const err = await r.json().catch(() => ({}));
|
||||||
alert("❌ Napaka: " + (err.detail || r.status));
|
alert("❌ Napaka: " + (err.detail || r.status));
|
||||||
|
// Vrni original state pri napaki
|
||||||
|
orig.forEach(o => { o.btn.disabled = o.disabled; o.btn.innerHTML = o.html; o.btn.setAttribute("style", o.style); });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = await r.json();
|
await r.json();
|
||||||
// Status will update via SSE / refresh
|
// refreshJobs() bo zamenjal gumb v zelen ✓
|
||||||
refreshJobs();
|
await refreshJobs();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert("❌ Napaka: " + e.message);
|
alert("❌ Napaka: " + e.message);
|
||||||
|
orig.forEach(o => { o.btn.disabled = o.disabled; o.btn.innerHTML = o.html; o.btn.setAttribute("style", o.style); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user