WebUI: simplify close window implementation

The caller site now take the responsibility to ensure the element is valid.

PR #21892.
This commit is contained in:
Chocobo1 2024-11-26 00:40:05 +08:00 committed by GitHub
parent 3ebdb50457
commit e1bd1038c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 22 additions and 23 deletions

View file

@ -19,7 +19,7 @@
$("cancelBtn").addEventListener("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
window.parent.MochaUI.closeWindow(window.parent.$("clearRulesPage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
}); });
$("confirmBtn").addEventListener("click", (e) => { $("confirmBtn").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
@ -31,7 +31,7 @@
++completionCount; ++completionCount;
if (completionCount === rules.length) { if (completionCount === rules.length) {
window.parent.qBittorrent.RssDownloader.updateRulesList(); window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.MochaUI.closeWindow(window.parent.$("clearRulesPage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
}); });
}); });

View file

@ -19,7 +19,7 @@
$("cancelBtn").addEventListener("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
window.parent.MochaUI.closeWindow(window.parent.$("removeRulePage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
}); });
$("confirmBtn").addEventListener("click", (e) => { $("confirmBtn").addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
@ -37,7 +37,7 @@
++completionCount; ++completionCount;
if (completionCount === rules.length) { if (completionCount === rules.length) {
window.parent.qBittorrent.RssDownloader.updateRulesList(); window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.MochaUI.closeWindow(window.parent.$("removeRulePage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
} }
}).send(); }).send();

View file

@ -22,11 +22,11 @@
}, },
"Escape": (event) => { "Escape": (event) => {
event.preventDefault(); event.preventDefault();
window.parent.qBittorrent.Client.closeWindow("editFeedURL"); window.parent.qBittorrent.Client.closeFrameWindow(window);
}, },
"Esc": (event) => { "Esc": (event) => {
event.preventDefault(); event.preventDefault();
window.parent.qBittorrent.Client.closeWindow("editFeedURL"); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
} }
}).activate(); }).activate();
@ -65,7 +65,7 @@
}, },
onSuccess: (response) => { onSuccess: (response) => {
window.parent.qBittorrent.Rss.updateRssFeedList(); window.parent.qBittorrent.Rss.updateRssFeedList();
window.parent.qBittorrent.Client.closeWindow("editFeedURL"); window.parent.qBittorrent.Client.closeFrameWindow(window);
}, },
onFailure: (response) => { onFailure: (response) => {
if (response.status === 409) if (response.status === 409)

View file

@ -21,11 +21,11 @@
event.preventDefault(); event.preventDefault();
}, },
"Escape": (event) => { "Escape": (event) => {
window.parent.MochaUI.closeWindow(window.parent.$("newRulePage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault(); event.preventDefault();
}, },
"Esc": (event) => { "Esc": (event) => {
window.parent.MochaUI.closeWindow(window.parent.$("newRulePage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault(); event.preventDefault();
} }
} }
@ -52,7 +52,7 @@
}, },
onSuccess: (response) => { onSuccess: (response) => {
window.parent.qBittorrent.RssDownloader.updateRulesList(); window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.MochaUI.closeWindow(window.parent.$("newRulePage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
}).send(); }).send();
}); });

View file

@ -21,11 +21,11 @@
event.preventDefault(); event.preventDefault();
}, },
"Escape": (event) => { "Escape": (event) => {
window.parent.MochaUI.closeWindow(window.parent.$("renameRulePage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault(); event.preventDefault();
}, },
"Esc": (event) => { "Esc": (event) => {
window.parent.MochaUI.closeWindow(window.parent.$("renameRulePage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault(); event.preventDefault();
} }
} }
@ -63,7 +63,7 @@
}, },
onSuccess: (response) => { onSuccess: (response) => {
window.parent.qBittorrent.RssDownloader.updateRulesList(); window.parent.qBittorrent.RssDownloader.updateRulesList();
window.parent.MochaUI.closeWindow(window.parent.$("renameRulePage")); window.parent.qBittorrent.Client.closeFrameWindow(window);
} }
}).send(); }).send();
}); });

View file

@ -64,15 +64,12 @@ window.qBittorrent.Client ??= (() => {
} }
}; };
const closeWindow = (windowID) => { const closeWindow = (window) => {
const window = document.getElementById(windowID);
if (!window)
return;
MochaUI.closeWindow(window); MochaUI.closeWindow(window);
}; };
const closeFrameWindow = (window) => { const closeFrameWindow = (window) => {
closeWindow(window.frameElement.closest("div.mocha").id); MochaUI.closeWindow(window.frameElement.closest("div.mocha"));
}; };
const getSyncMainDataInterval = () => { const getSyncMainDataInterval = () => {

View file

@ -24,7 +24,9 @@
confirmText.textContent = "QBT_TR(Are you sure you want to recheck the selected torrent(s)?)QBT_TR[CONTEXT=confirmRecheckDialog]"; confirmText.textContent = "QBT_TR(Are you sure you want to recheck the selected torrent(s)?)QBT_TR[CONTEXT=confirmRecheckDialog]";
cancelButton.addEventListener("click", (e) => { window.qBittorrent.Client.closeWindow("confirmRecheckDialog"); }); cancelButton.addEventListener("click", (e) => {
window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog"));
});
confirmButton.addEventListener("click", (e) => { confirmButton.addEventListener("click", (e) => {
new Request({ new Request({
url: "api/v2/torrents/recheck", url: "api/v2/torrents/recheck",
@ -34,7 +36,7 @@
}, },
onSuccess: () => { onSuccess: () => {
updateMainData(); updateMainData();
window.qBittorrent.Client.closeWindow("confirmRecheckDialog"); window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog"));
}, },
onFailure: () => { onFailure: () => {
alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]"); alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]");
@ -51,7 +53,7 @@
confirmButton.click(); confirmButton.click();
break; break;
case "Escape": case "Escape":
window.qBittorrent.Client.closeWindow("confirmRecheckDialog"); window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog"));
break; break;
} }
}); });

View file

@ -137,7 +137,7 @@
alert(error); alert(error);
}, },
onSuccess: (response) => { onSuccess: (response) => {
window.qBittorrent.Client.closeWindow("cookiesPage"); window.qBittorrent.Client.closeWindow(document.getElementById("cookiesPage"));
} }
}).send(); }).send();
}; };

View file

@ -114,7 +114,7 @@
}; };
const closeSearchWindow = (id) => { const closeSearchWindow = (id) => {
window.parent.MochaUI.closeWindow(window.parent.$(id)); window.parent.qBittorrent.Client.closeWindow(window.parent.$(id));
}; };
const installPlugin = (path) => { const installPlugin = (path) => {