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

View file

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

View file

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

View file

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

View file

@ -64,15 +64,12 @@ window.qBittorrent.Client ??= (() => {
}
};
const closeWindow = (windowID) => {
const window = document.getElementById(windowID);
if (!window)
return;
const closeWindow = (window) => {
MochaUI.closeWindow(window);
};
const closeFrameWindow = (window) => {
closeWindow(window.frameElement.closest("div.mocha").id);
MochaUI.closeWindow(window.frameElement.closest("div.mocha"));
};
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]";
cancelButton.addEventListener("click", (e) => { window.qBittorrent.Client.closeWindow("confirmRecheckDialog"); });
cancelButton.addEventListener("click", (e) => {
window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog"));
});
confirmButton.addEventListener("click", (e) => {
new Request({
url: "api/v2/torrents/recheck",
@ -34,7 +36,7 @@
},
onSuccess: () => {
updateMainData();
window.qBittorrent.Client.closeWindow("confirmRecheckDialog");
window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog"));
},
onFailure: () => {
alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]");
@ -51,7 +53,7 @@
confirmButton.click();
break;
case "Escape":
window.qBittorrent.Client.closeWindow("confirmRecheckDialog");
window.qBittorrent.Client.closeWindow(document.getElementById("confirmRecheckDialog"));
break;
}
});

View file

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

View file

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