fix(model-manager): replace window.confirm with in-app modal
Browsers suppress native confirm() dialogs after repeated use (the "prevent this page from creating additional dialogs" checkbox), which silently broke deletes. Add a promise-based in-app confirmation modal and use it for gallery photo and installed-model deletes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,33 @@ function fmtDate(epoch) {
|
||||
return new Date(epoch * 1000).toLocaleString();
|
||||
}
|
||||
|
||||
// In-app confirmation dialog (replaces window.confirm, which browsers can
|
||||
// suppress after repeated use). Returns a Promise<boolean>.
|
||||
function confirmDialog(message, okLabel = "Delete") {
|
||||
return new Promise((resolve) => {
|
||||
const overlay = $("#confirmModal");
|
||||
$("#confirmMsg").textContent = message;
|
||||
$("#confirmOk").textContent = okLabel;
|
||||
overlay.hidden = false;
|
||||
const done = (val) => {
|
||||
overlay.hidden = true;
|
||||
$("#confirmOk").onclick = null;
|
||||
$("#confirmCancel").onclick = null;
|
||||
overlay.onclick = null;
|
||||
document.removeEventListener("keydown", onKey);
|
||||
resolve(val);
|
||||
};
|
||||
function onKey(e) {
|
||||
if (e.key === "Escape") done(false);
|
||||
if (e.key === "Enter") done(true);
|
||||
}
|
||||
$("#confirmOk").onclick = () => done(true);
|
||||
$("#confirmCancel").onclick = () => done(false);
|
||||
overlay.onclick = (e) => { if (e.target === overlay) done(false); };
|
||||
document.addEventListener("keydown", onKey);
|
||||
});
|
||||
}
|
||||
|
||||
// ---- navigation -----------------------------------------------------------
|
||||
|
||||
function showView(name) {
|
||||
@@ -118,7 +145,7 @@ function renderModels(models) {
|
||||
}
|
||||
|
||||
async function deleteModel(m) {
|
||||
if (!confirm(`Delete ${m.name}?`)) return;
|
||||
if (!(await confirmDialog(`Delete ${m.name}?`))) return;
|
||||
try {
|
||||
await api("/api/models", {
|
||||
method: "DELETE",
|
||||
@@ -307,7 +334,7 @@ function renderPhotoCard(p) {
|
||||
}
|
||||
|
||||
async function deletePhoto(p, card) {
|
||||
if (!confirm(`Permanently delete ${p.name}?`)) return;
|
||||
if (!(await confirmDialog(`Permanently delete ${p.name}?`))) return;
|
||||
try {
|
||||
await api("/api/gallery", {
|
||||
method: "DELETE",
|
||||
|
||||
Reference in New Issue
Block a user