Allow to refresh existing search
[qBittorrent.git] / src / webui / www / private / views / confirmdeletion.html
blob80f976682db0f9a5d15aeeac88dc81c4ba3110b6
1 <div id="confirmDeletionDialog">
2 <div class="confirmDeletionGrid">
3 <span class="deletionGridItem confirmDialogWarning"></span>
4 <span class="deletionGridItem dialogMessage" id="deleteTorrentMessage"></span>
5 <span class="deletionGridItem">
6 <button class="disabled" type="button" id="rememberBtn" title="QBT_TR(Remember choice)QBT_TR[CONTEXT=HttpServer]" aria-label="QBT_TR(Remember choice)QBT_TR[CONTEXT=HttpServer]" disabled></button>
7 </span>
8 <span class="deletionGridItem">
9 <input type="checkbox" id="deleteFromDiskCB">
10 <label for="deleteFromDiskCB">
11 <em>QBT_TR(Also remove the content files)QBT_TR[CONTEXT=confirmDeletionDlg]</em>
12 </label>
13 </span>
14 </div>
15 </div>
16 <div>
17 <input type="button" value="QBT_TR(Remove)QBT_TR[CONTEXT=MainWindow]" id="confirmDeletionButton">
18 <input type="button" value="QBT_TR(Cancel)QBT_TR[CONTEXT=MainWindow]" id="cancelDeletionButton">
19 </div>
21 <script>
22 "use strict";
24 (() => {
25 const setRememberBtnEnabled = (enable) => {
26 rememberButton.disabled = !enable;
27 rememberButton.classList.toggle("disabled", !enable);
30 const confirmButton = document.getElementById("confirmDeletionButton");
31 const cancelButton = document.getElementById("cancelDeletionButton");
32 const rememberButton = document.getElementById("rememberBtn");
33 const deleteCB = document.getElementById("deleteFromDiskCB");
34 const deletionText = document.getElementById("deleteTorrentMessage");
36 const {
37 hashes,
38 isDeletingVisibleTorrents = false,
39 forceDeleteFiles = false,
40 } = window.MUI.Windows.instances["confirmDeletionPage"].options.data;
41 let prefDeleteContentFiles = window.qBittorrent.Cache.preferences.get().delete_torrent_content_files;
42 deleteCB.checked = forceDeleteFiles || prefDeleteContentFiles;
44 let deleteMessage;
45 if (hashes.length === 1) {
46 const { full_data: { name } } = torrentsTable.getRow(hashes[0]);
47 deleteMessage = "QBT_TR(Are you sure you want to remove %1 from the transfer list?)QBT_TR[CONTEXT=HttpServer]".replace("%1", `"${name}"`);
49 else {
50 deleteMessage = "QBT_TR(Are you sure you want to remove these %1 torrents from the transfer list?)QBT_TR[CONTEXT=HttpServer]".replace("%1", hashes.length);
53 deletionText.textContent = deleteMessage;
55 // Enable "Remember" button if the current choice is different from the saved preference
56 deleteCB.addEventListener("click", (e) => { setRememberBtnEnabled(deleteCB.checked !== prefDeleteContentFiles); });
58 // Set current "Delete files" choice as the default
59 rememberButton.addEventListener("click", (e) => {
60 window.qBittorrent.Cache.preferences.set({
61 data: {
62 delete_torrent_content_files: deleteCB.checked
64 onSuccess: () => {
65 prefDeleteContentFiles = deleteCB.checked;
66 setRememberBtnEnabled(false);
68 });
69 });
71 cancelButton.focus();
72 cancelButton.addEventListener("click", (e) => { window.qBittorrent.Client.closeWindow(document.getElementById("confirmDeletionPage")); });
74 confirmButton.addEventListener("click", (e) => {
75 // Some torrents might be removed when waiting for user input, so refetch the torrent list
76 const hashes = isDeletingVisibleTorrents
77 ? torrentsTable.getFilteredTorrentsHashes(selectedStatus, selectedCategory, selectedTag, selectedTracker)
78 : torrentsTable.selectedRowsIds();
80 fetch("api/v2/torrents/delete", {
81 method: "POST",
82 body: new URLSearchParams({
83 hashes: hashes.join("|"),
84 deleteFiles: deleteCB.checked
87 .then((response) => {
88 if (!response.ok) {
89 alert("QBT_TR(Unable to delete torrents.)QBT_TR[CONTEXT=HttpServer]");
90 return;
93 torrentsTable.deselectAll();
94 updateMainData();
95 updatePropertiesPanel();
96 window.qBittorrent.Client.closeWindow(document.getElementById("confirmDeletionPage"));
97 });
98 });
99 })();
100 </script>