WebUI: Allow setting default category when adding torrent

This commit is contained in:
Thomas Piccirello 2025-07-01 07:13:16 -07:00
commit 5b814cf149
No known key found for this signature in database
2 changed files with 24 additions and 2 deletions

View file

@ -195,10 +195,17 @@
<select id="categorySelect" onchange="qBittorrent.AddTorrent.changeCategorySelect(this)">
<option selected value="\other"></option>
</select>
<input type="text" name="category" aria-labelledby="categoryLabel">
<input type="text" name="category" id="category" aria-labelledby="categoryLabel">
</div>
</td>
</tr>
<tr>
<td class="noWrap"></td>
<td class="fullWidth">
<input type="checkbox" id="setDefaultCategory">
<label for="setDefaultCategory">QBT_TR(Set as default category)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
</td>
</tr>
<tr>
<td class="noWrap">
<label id="tagsLabel" for="tagsSelect">QBT_TR(Tags:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>

View file

@ -43,13 +43,21 @@ window.qBittorrent.AddTorrent ??= (() => {
let windowId = "";
let source = "";
const LocalPreferences = new window.qBittorrent.LocalPreferences.LocalPreferences();
const getCategories = () => {
const defaultCategory = LocalPreferences.get("add_torrent_default_category", "");
const categorySelect = document.getElementById("categorySelect");
for (const name of window.parent.qBittorrent.Client.categoryMap.keys()) {
const option = document.createElement("option");
option.value = name;
option.textContent = name;
document.getElementById("categorySelect").appendChild(option);
option.selected = name === defaultCategory;
categorySelect.appendChild(option);
}
if (defaultCategory !== "")
changeCategorySelect(categorySelect);
};
const getTags = () => {
@ -299,6 +307,13 @@ window.qBittorrent.AddTorrent ??= (() => {
document.getElementById("loadingSpinner").style.display = "block";
if (document.getElementById("setDefaultCategory").checked) {
const category = document.getElementById("category").value.trim();
if (category.length === 0)
LocalPreferences.remove("add_torrent_default_category");
else
LocalPreferences.set("add_torrent_default_category", category);
}
};
window.addEventListener("load", async (event) => {