WebUI: Add confirm dialog for Auto TMM

Just like in GUI, confirmation dialog shows up if it's possible to enable Auto TMM for any selected torrent. Right now it's not possible to properly test all cases in the WebUI because context menu completely hides TMM option when some torrents have it enabled and some not (no tri-state) - but that's something to add in another PR.

PR #21378.
This commit is contained in:
skomerko 2024-10-04 16:39:08 +02:00 committed by GitHub
parent dc02a0fc56
commit 4ff0687b94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 95 additions and 17 deletions

View file

@ -555,22 +555,36 @@ const initializeWindows = function() {
autoTorrentManagementFN = function() {
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
let enable = false;
hashes.each((hash, index) => {
const row = torrentsTable.getRow(hash);
if (!row.full_data.auto_tmm)
enable = true;
});
new Request({
url: "api/v2/torrents/setAutoManagement",
method: "post",
data: {
hashes: hashes.join("|"),
enable: enable
}
}).send();
updateMainData();
if (hashes.length > 0) {
const enableAutoTMM = hashes.some((hash) => !(torrentsTable.getRow(hash).full_data.auto_tmm));
if (enableAutoTMM) {
new MochaUI.Modal({
...window.qBittorrent.Dialog.baseModalOptions,
id: "confirmAutoTMMDialog",
title: "QBT_TR(Enable automatic torrent management)QBT_TR[CONTEXT=confirmAutoTMMDialog]",
data: {
hashes: hashes,
enable: enableAutoTMM
},
contentURL: "views/confirmAutoTMM.html"
});
}
else {
new Request({
url: "api/v2/torrents/setAutoManagement",
method: "post",
data: {
hashes: hashes.join("|"),
enable: enableAutoTMM
},
onSuccess: () => {
updateMainData();
},
onFailure: () => {
alert("QBT_TR(Unable to set Auto Torrent Management for the selected torrents.)QBT_TR[CONTEXT=HttpServer]");
}
}).send();
}
}
};