WebUI: Allow setting default category when adding torrent

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

View file

@ -204,10 +204,17 @@
<select id="categorySelect" onchange="qBittorrent.AddTorrent.changeCategorySelect(this)"> <select id="categorySelect" onchange="qBittorrent.AddTorrent.changeCategorySelect(this)">
<option selected value="\other"></option> <option selected value="\other"></option>
</select> </select>
<input type="text" name="category" aria-labelledby="categoryLabel"> <input type="text" name="category" id="category" aria-labelledby="categoryLabel">
</div> </div>
</td> </td>
</tr> </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> <tr>
<td class="noWrap"> <td class="noWrap">
<label id="tagsLabel" for="tagsSelect">QBT_TR(Tags:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label> <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 windowId = "";
let source = ""; let source = "";
const LocalPreferences = new window.qBittorrent.LocalPreferences.LocalPreferences();
const getCategories = () => { 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()) { for (const name of window.parent.qBittorrent.Client.categoryMap.keys()) {
const option = document.createElement("option"); const option = document.createElement("option");
option.value = name; option.value = name;
option.textContent = name; option.textContent = name;
document.getElementById("categorySelect").appendChild(option); option.selected = name === defaultCategory;
categorySelect.appendChild(option);
} }
if (defaultCategory !== "")
changeCategorySelect(categorySelect);
}; };
const getTags = () => { const getTags = () => {
@ -301,6 +309,13 @@ window.qBittorrent.AddTorrent ??= (() => {
document.getElementById("loadingSpinner").style.display = "block"; 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) => { window.addEventListener("load", async (event) => {