Skip to content

Commit 9f7fad9

Browse files
committed
WebUI: Support specifying tags when adding torrent
Signed-off-by: Thomas Piccirello <[email protected]>
1 parent b317cee commit 9f7fad9

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/webui/www/private/addtorrent.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
<link rel="stylesheet" type="text/css" href="css/dynamicTable.css?v=${CACHEID}">
88
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
99
<link rel="stylesheet" href="css/Window.css?v=${CACHEID}" type="text/css">
10+
<link rel="stylesheet" href="css/vanillaSelectBox.css" type="text/css">
1011
<script defer src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
1112
<script defer src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
13+
<script defer src="scripts/lib/vanillaSelectBox.js"></script>
1214
<script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
1315
<script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
1416
<script defer src="scripts/addtorrent.js?locale=${LANG}&v=${CACHEID}"></script>
@@ -109,6 +111,10 @@
109111
}
110112
}
111113

114+
#btn-group-tagsSelect button {
115+
background-color: initial;
116+
}
117+
112118
</style>
113119
</head>
114120

@@ -192,6 +198,17 @@
192198
</div>
193199
</td>
194200
</tr>
201+
<tr>
202+
<td class="noWrap">
203+
<label id="tagsLabel" for="tagsSelect">QBT_TR(Tags:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
204+
</td>
205+
<td class="fullWidth">
206+
<div>
207+
<input type="hidden" id="tags" name="tags">
208+
<select id="tagsSelect" name="tagsSelect" multiple></select>
209+
</div>
210+
</td>
211+
</tr>
195212
<tr>
196213
<td class="noWrap">
197214
<label for="startTorrent">QBT_TR(Start torrent)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>

src/webui/www/private/scripts/addtorrent.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ window.qBittorrent.AddTorrent ??= (() => {
3838
};
3939

4040
let categories = {};
41+
let tags = [];
4142
let defaultSavePath = "";
4243
let defaultTempPath = "";
4344
let windowId = "";
@@ -68,6 +69,38 @@ window.qBittorrent.AddTorrent ??= (() => {
6869
});
6970
};
7071

72+
const getTags = () => {
73+
fetch("api/v2/torrents/tags", {
74+
method: "GET",
75+
cache: "no-store"
76+
})
77+
.then(async (response) => {
78+
if (!response.ok)
79+
return;
80+
81+
const data = await response.json();
82+
83+
tags = data;
84+
const tagsSelect = document.getElementById("tagsSelect");
85+
for (const tag of tags) {
86+
const option = document.createElement("option");
87+
option.value = tag;
88+
option.textContent = tag;
89+
tagsSelect.appendChild(option);
90+
}
91+
92+
new vanillaSelectBox("#tagsSelect", {
93+
maxHeight: 200,
94+
search: false,
95+
disableSelectAll: true,
96+
translations: {
97+
all: tags.length === 0 ? "" : "QBT_TR(All)QBT_TR[CONTEXT=AddNewTorrentDialog]",
98+
},
99+
keepInlineStyles: false
100+
});
101+
});
102+
};
103+
71104
const getPreferences = () => {
72105
const pref = window.parent.qBittorrent.Cache.preferences.get();
73106

@@ -132,6 +165,11 @@ window.qBittorrent.AddTorrent ??= (() => {
132165
}
133166
};
134167

168+
const changeTagsSelect = (element) => {
169+
const tags = [...element.options].filter(opt => opt.selected).map(opt => opt.value);
170+
document.getElementById("tags").value = tags.join(",");
171+
};
172+
135173
const changeTMM = (item) => {
136174
const savepath = document.getElementById("savepath");
137175
const useDownloadPath = document.getElementById("useDownloadPath");
@@ -266,10 +304,12 @@ window.qBittorrent.AddTorrent ??= (() => {
266304

267305
getPreferences();
268306
getCategories();
307+
getTags();
269308
});
270309

271310
window.addEventListener("DOMContentLoaded", (event) => {
272311
document.getElementById("useDownloadPath").addEventListener("change", (e) => changeUseDownloadPath(e.target.checked));
312+
document.getElementById("tagsSelect").addEventListener("change", (e) => changeTagsSelect(e.target));
273313
});
274314

275315
return exports();

0 commit comments

Comments
 (0)