qbittorrent-webui-cjratliff.../private/newcategory.html
2023-06-18 23:32:21 -03:00

146 lines
5.9 KiB
HTML

<!DOCTYPE html>
<html lang="${LANG}">
<head>
<meta charset="UTF-8" />
<title>New Category</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/Core.css?v=${CACHEID}" />
<script src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
<script src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
<script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
<script>
'use strict';
new Keyboard({
defaultEventType: 'keydown',
events: {
'Enter': function(event) {
$('categoryNameButton').click();
event.preventDefault();
},
'Escape': function(event) {
window.parent.closeWindows();
event.preventDefault();
},
'Esc': function(event) {
window.parent.closeWindows();
event.preventDefault();
}
}
}).activate();
window.addEvent('domready', function() {
const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData('action'));
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData('hashes'));
const uriCategoryName = window.qBittorrent.Misc.safeTrim(new URI().getData('categoryName'));
const uriSavePath = window.qBittorrent.Misc.safeTrim(new URI().getData('savePath'));
if (uriAction === "edit") {
if (!uriCategoryName)
return false;
$('categoryName').set('disabled', true);
$('categoryName').set('value', window.qBittorrent.Misc.escapeHtml(uriCategoryName));
$('savePath').set('value', window.qBittorrent.Misc.escapeHtml(uriSavePath));
$('savePath').focus();
}
else {
$('categoryName').focus();
}
$('categoryNameButton').addEvent('click', function(e) {
new Event(e).stop();
const savePath = $('savePath').value.trim();
const categoryName = $('categoryName').value.trim();
const verifyCategoryName = function(name) {
if ((name === null) || (name === ""))
return false;
if (name.match("^([^\\\\\\/]|[^\\\\\\/]([^\\\\\\/]|\\/(?=[^\\/]))*[^\\\\\\/])$") === null) {
alert("Invalid category name:\nPlease do not use any special characters in the category name.");
return false;
}
return true;
};
switch (uriAction) {
case "set":
if ((uriHashes === "") || !verifyCategoryName(categoryName))
return;
new Request({
url: 'api/v2/torrents/createCategory',
method: 'post',
data: {
category: categoryName,
savePath: savePath
},
onSuccess: function() {
new Request({
url: 'api/v2/torrents/setCategory',
method: 'post',
data: {
hashes: uriHashes,
category: categoryName
},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
},
onFailure: function() {
alert("Unable to create category " + window.qBittorrent.Misc.escapeHtml(categoryName));
}
}).send();
break;
case "create":
if (!verifyCategoryName(categoryName))
return;
new Request({
url: 'api/v2/torrents/createCategory',
method: 'post',
data: {
category: categoryName,
savePath: savePath
},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
break;
case "edit":
new Request({
url: 'api/v2/torrents/editCategory',
method: 'post',
data: {
category: uriCategoryName, // category name can't be changed
savePath: savePath
},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
break;
}
});
});
</script>
</head>
<body>
<div style="padding: 10px 10px 0px 10px;">
<p style="font-weight: bold;">Category:</p>
<input type="text" id="categoryName" style="width: 99%;" />
<p style="font-weight: bold;">Save path:</p>
<input type="text" id="savePath" style="width: 99%;" />
<div style="text-align: center; padding-top: 10px;">
<input class="button" type="button" value="Add" id="categoryNameButton" />
</div>
</div>
</body>
</html>