6 <title>QBT_TR(New Category)QBT_TR[CONTEXT=TransferListWidget]
</title>
7 <link rel=
"stylesheet" href=
"css/style.css?v=${CACHEID}" type=
"text/css">
8 <script src=
"scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
9 <script src=
"scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
10 <script src=
"scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
11 <script src=
"scripts/pathAutofill.js?v=${CACHEID}"></script>
16 defaultEventType
: "keydown",
18 "Enter": function(event
) {
19 $("categoryNameButton").click();
20 event
.preventDefault();
22 "Escape": function(event
) {
23 window
.parent
.qBittorrent
.Client
.closeWindows();
24 event
.preventDefault();
26 "Esc": function(event
) {
27 window
.parent
.qBittorrent
.Client
.closeWindows();
28 event
.preventDefault();
33 window
.addEventListener("DOMContentLoaded", () => {
34 const uriAction
= window
.qBittorrent
.Misc
.safeTrim(new URI().getData("action"));
35 const uriHashes
= window
.qBittorrent
.Misc
.safeTrim(new URI().getData("hashes"));
36 const uriCategoryName
= window
.qBittorrent
.Misc
.safeTrim(new URI().getData("categoryName"));
37 const uriSavePath
= window
.qBittorrent
.Misc
.safeTrim(new URI().getData("savePath"));
39 if (uriAction
=== "edit") {
43 $("categoryName").disabled
= true;
44 $("categoryName").value
= window
.qBittorrent
.Misc
.escapeHtml(uriCategoryName
);
45 $("savePath").value
= window
.qBittorrent
.Misc
.escapeHtml(uriSavePath
);
46 $("savePath").focus();
48 else if (uriAction
=== "createSubcategory") {
49 $("categoryName").value
= window
.qBittorrent
.Misc
.escapeHtml(uriCategoryName
);
50 $("categoryName").focus();
53 $("categoryName").focus();
56 $("categoryNameButton").addEventListener("click", (e
) => {
60 const savePath
= $("savePath").value
.trim();
61 const categoryName
= $("categoryName").value
.trim();
63 const verifyCategoryName = function(name
) {
64 if ((name
=== null) || (name
=== ""))
66 if (name
.match("^([^\\\\\\/]|[^\\\\\\/]([^\\\\\\/]|\\/(?=[^\\/]))*[^\\\\\\/])$") === null) {
67 alert("QBT_TR(Invalid category name:\nPlease do not use any special characters in the category name.)QBT_TR[CONTEXT=HttpServer]");
75 if ((uriHashes
=== "") || !verifyCategoryName(categoryName
))
79 url
: "api/v2/torrents/createCategory",
82 category
: categoryName
,
85 onSuccess: function() {
87 url
: "api/v2/torrents/setCategory",
91 category
: categoryName
93 onSuccess: function() {
94 window
.parent
.updateMainData();
95 window
.parent
.qBittorrent
.Client
.closeWindows();
97 onFailure: function() {
98 alert("QBT_TR(Unable to set category)QBT_TR[CONTEXT=Category]");
102 onFailure: function() {
103 alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category] " + window
.qBittorrent
.Misc
.escapeHtml(categoryName
));
108 case "createSubcategory":
109 if (!verifyCategoryName(categoryName
))
113 url
: "api/v2/torrents/createCategory",
116 category
: categoryName
,
119 onSuccess: function() {
120 window
.parent
.updateMainData();
121 window
.parent
.qBittorrent
.Client
.closeWindows();
123 onFailure: function() {
124 alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category]");
130 url
: "api/v2/torrents/editCategory",
133 category
: uriCategoryName
, // category name can't be changed
136 onSuccess: function() {
137 window
.parent
.updateMainData();
138 window
.parent
.qBittorrent
.Client
.closeWindows();
140 onFailure: function() {
141 alert("QBT_TR(Unable to edit category)QBT_TR[CONTEXT=Category]");
149 window
.qBittorrent
.pathAutofill
.attachPathAutofill();
154 <div style=
"padding: 10px 10px 0px 10px;">
155 <label for=
"categoryName" style=
"font-weight: bold;">QBT_TR(Category:)QBT_TR[CONTEXT=TransferListWidget]
</label>
156 <input type=
"text" id=
"categoryName" style=
"width: 99%;">
157 <label for=
"savePath" style=
"font-weight: bold;">QBT_TR(Save path:)QBT_TR[CONTEXT=TransferListWidget]
</label>
158 <input type=
"text" id=
"savePath" class=
"pathDirectory" style=
"width: 99%;">
159 <div style=
"text-align: center; padding-top: 10px;">
160 <input type=
"button" value=
"QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id=
"categoryNameButton">