Enable customizing the save statistics time interval
[qBittorrent.git] / src / webui / www / private / newcategory.html
blob224afa3acfcb080114d289b7f775f25c5390fc13
1 <!DOCTYPE html>
2 <html lang="${LANG}">
4 <head>
5 <meta charset="UTF-8">
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>
12 <script>
13 "use strict";
15 new Keyboard({
16 defaultEventType: "keydown",
17 events: {
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();
31 }).activate();
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") {
40 if (!uriCategoryName)
41 return;
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();
52 else {
53 $("categoryName").focus();
56 $("categoryNameButton").addEventListener("click", (e) => {
57 e.preventDefault();
58 e.stopPropagation();
60 const savePath = $("savePath").value.trim();
61 const categoryName = $("categoryName").value.trim();
63 const verifyCategoryName = function(name) {
64 if ((name === null) || (name === ""))
65 return false;
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]");
68 return false;
70 return true;
73 switch (uriAction) {
74 case "set":
75 if ((uriHashes === "") || !verifyCategoryName(categoryName))
76 return;
78 new Request({
79 url: "api/v2/torrents/createCategory",
80 method: "post",
81 data: {
82 category: categoryName,
83 savePath: savePath
85 onSuccess: function() {
86 new Request({
87 url: "api/v2/torrents/setCategory",
88 method: "post",
89 data: {
90 hashes: uriHashes,
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]");
100 }).send();
102 onFailure: function() {
103 alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=Category] " + window.qBittorrent.Misc.escapeHtml(categoryName));
105 }).send();
106 break;
107 case "create":
108 case "createSubcategory":
109 if (!verifyCategoryName(categoryName))
110 return;
112 new Request({
113 url: "api/v2/torrents/createCategory",
114 method: "post",
115 data: {
116 category: categoryName,
117 savePath: savePath
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]");
126 }).send();
127 break;
128 case "edit":
129 new Request({
130 url: "api/v2/torrents/editCategory",
131 method: "post",
132 data: {
133 category: uriCategoryName, // category name can't be changed
134 savePath: savePath
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]");
143 }).send();
144 break;
149 window.qBittorrent.pathAutofill.attachPathAutofill();
150 </script>
151 </head>
153 <body>
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">
161 </div>
162 </div>
163 </body>
165 </html>