mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-04 22:52:33 -06:00
Add save path and editing to WebUI new category dialog
This commit is contained in:
committed by
sledgehammer999
parent
c28cbe0a74
commit
c3f002a544
@@ -30,6 +30,9 @@
|
||||
CreateCategory: function(element, ref) {
|
||||
createCategoryFN();
|
||||
},
|
||||
EditCategory: function(element, ref) {
|
||||
editCategoryFN(element.id);
|
||||
},
|
||||
DeleteCategory: function(element, ref) {
|
||||
removeCategoryFN(element.id);
|
||||
},
|
||||
|
||||
@@ -143,6 +143,7 @@
|
||||
</ul>
|
||||
<ul id="categoriesFilterMenu" class="contextMenu">
|
||||
<li><a href="#CreateCategory"><img src="images/qbt-theme/list-add.svg" alt="QBT_TR(Add category...)QBT_TR[CONTEXT=CategoryFilterWidget]"/> QBT_TR(Add category...)QBT_TR[CONTEXT=CategoryFilterWidget]</a></li>
|
||||
<li><a href="#EditCategory"><img src="images/qbt-theme/document-edit.svg" alt="QBT_TR(Edit category...)QBT_TR[CONTEXT=CategoryFilterWidget]"/> QBT_TR(Edit category...)QBT_TR[CONTEXT=CategoryFilterWidget]</a></li>
|
||||
<li><a href="#DeleteCategory"><img src="images/qbt-theme/list-remove.svg" alt="QBT_TR(Remove category)QBT_TR[CONTEXT=CategoryFilterWidget]"/> QBT_TR(Remove category)QBT_TR[CONTEXT=CategoryFilterWidget]</a></li>
|
||||
<li><a href="#DeleteUnusedCategories"><img src="images/qbt-theme/list-remove.svg" alt="QBT_TR(Remove unused categories)QBT_TR[CONTEXT=CategoryFilterWidget]"/> QBT_TR(Remove unused categories)QBT_TR[CONTEXT=CategoryFilterWidget]</a></li>
|
||||
<li class="separator"><a href="#StartTorrentsByCategory"><img src="images/qbt-theme/media-playback-start.svg" alt="QBT_TR(Resume torrents)QBT_TR[CONTEXT=CategoryFilterWidget]"/> QBT_TR(Resume torrents)QBT_TR[CONTEXT=CategoryFilterWidget]</a></li>
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
||||
<script src="scripts/lib/mootools-1.2-core-yc.js"></script>
|
||||
<script src="scripts/lib/mootools-1.2-more.js"></script>
|
||||
<script src="scripts/misc.js"></script>
|
||||
<script>
|
||||
var newCategoryKeyboardEvents = new Keyboard({
|
||||
defaultEventType: 'keydown',
|
||||
events: {
|
||||
'enter': function(event) {
|
||||
$('newCategoryButton').click();
|
||||
$('categoryNameButton').click();
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
@@ -20,42 +21,99 @@
|
||||
newCategoryKeyboardEvents.activate();
|
||||
|
||||
window.addEvent('domready', function() {
|
||||
$('newCategory').focus();
|
||||
$('newCategoryButton').addEvent('click', function(e) {
|
||||
var uriAction = safeTrim(new URI().getData('action'));
|
||||
var uriHashes = safeTrim(new URI().getData('hashes'));
|
||||
var uriCategoryName = safeTrim(new URI().getData('categoryName'));
|
||||
var uriSavePath = safeTrim(new URI().getData('savePath'));
|
||||
|
||||
if (uriAction === "create") {
|
||||
$('categoryName').focus();
|
||||
}
|
||||
else if (uriAction === "edit") {
|
||||
if (!uriCategoryName)
|
||||
return false;
|
||||
|
||||
$('categoryName').set('disabled', true);
|
||||
$('categoryName').set('value', escapeHtml(uriCategoryName));
|
||||
$('savePath').set('value', escapeHtml(uriSavePath));
|
||||
$('savePath').focus();
|
||||
}
|
||||
|
||||
$('categoryNameButton').addEvent('click', function(e) {
|
||||
new Event(e).stop();
|
||||
// check field
|
||||
var categoryName = $('newCategory').value.trim();
|
||||
if (categoryName == null || categoryName == "")
|
||||
return false;
|
||||
if (categoryName.match("^([^\\\\\\/]|[^\\\\\\/]([^\\\\\\/]|\\/(?=[^\\/]))*[^\\\\\\/])$") === null) {
|
||||
alert("QBT_TR(Invalid category name:\nPlease do not use any special characters in the category name.)QBT_TR[CONTEXT=HttpServer]");
|
||||
return false;
|
||||
}
|
||||
var hashesList = new URI().getData('hashes');
|
||||
if (!hashesList) {
|
||||
new Request({
|
||||
url: 'api/v2/torrents/createCategory',
|
||||
method: 'post',
|
||||
data: {
|
||||
category: categoryName
|
||||
},
|
||||
onComplete: function() {
|
||||
window.parent.closeWindows();
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
else {
|
||||
new Request({
|
||||
url: 'api/v2/torrents/setCategory',
|
||||
method: 'post',
|
||||
data: {
|
||||
hashes: hashesList,
|
||||
category: categoryName
|
||||
},
|
||||
onComplete: function() {
|
||||
window.parent.closeWindows();
|
||||
}
|
||||
}).send();
|
||||
|
||||
var savePath = $('savePath').value.trim();
|
||||
var categoryName = $('categoryName').value.trim();
|
||||
|
||||
var verifyCategoryName = function(name) {
|
||||
if ((name === null) || (name === ""))
|
||||
return false;
|
||||
if (name.match("^([^\\\\\\/]|[^\\\\\\/]([^\\\\\\/]|\\/(?=[^\\/]))*[^\\\\\\/])$") === null) {
|
||||
alert("QBT_TR(Invalid category name:\nPlease do not use any special characters in the category name.)QBT_TR[CONTEXT=HttpServer]");
|
||||
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();
|
||||
},
|
||||
onError: function() {
|
||||
alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=HttpServer] " + 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;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -65,9 +123,11 @@
|
||||
<body>
|
||||
<div style="padding: 10px 10px 0px 10px;">
|
||||
<p style="font-weight: bold;">QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]:</p>
|
||||
<input type="text" id="newCategory" value="" maxlength="100" style="width: 220px;" />
|
||||
<input type="text" id="categoryName" value="" maxlength="100" style="width: 220px;" />
|
||||
<p style="font-weight: bold;">QBT_TR(Save path)QBT_TR[CONTEXT=TransferListWidget]:</p>
|
||||
<input type="text" id="savePath" value="" style="width: 220px;" />
|
||||
<div style="text-align: center; padding-top: 10px;">
|
||||
<input type="button" value="QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id="newCategoryButton" />
|
||||
<input type="button" value="QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id="categoryNameButton" />
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -327,19 +327,26 @@ window.addEvent('load', function() {
|
||||
syncMainDataLastResponseId = response['rid'];
|
||||
}
|
||||
if (response['categories']) {
|
||||
response['categories'].each(function(category) {
|
||||
var categoryHash = genHash(category.name);
|
||||
category_list[categoryHash] = {
|
||||
name: category.name,
|
||||
savePath: category.savePath,
|
||||
torrents: []
|
||||
};
|
||||
});
|
||||
for (var key in response['categories']) {
|
||||
var category = response['categories'][key];
|
||||
var categoryHash = genHash(key);
|
||||
if (category_list[categoryHash] !== undefined) {
|
||||
// only the save path can change for existing categories
|
||||
category_list[categoryHash].savePath = category.savePath;
|
||||
}
|
||||
else {
|
||||
category_list[categoryHash] = {
|
||||
name: category.name,
|
||||
savePath: category.savePath,
|
||||
torrents: []
|
||||
};
|
||||
}
|
||||
}
|
||||
update_categories = true;
|
||||
}
|
||||
if (response['categories_removed']) {
|
||||
response['categories_removed'].each(function(category) {
|
||||
var categoryHash = genHash(category.name);
|
||||
var categoryHash = genHash(category);
|
||||
delete category_list[categoryHash];
|
||||
});
|
||||
update_categories = true;
|
||||
|
||||
@@ -387,9 +387,13 @@ var CategoriesFilterContextMenu = new Class({
|
||||
Extends: ContextMenu,
|
||||
updateMenuItems: function() {
|
||||
var id = this.options.element.id;
|
||||
if (id != CATEGORIES_ALL && id != CATEGORIES_UNCATEGORIZED)
|
||||
if ((id != CATEGORIES_ALL) && (id != CATEGORIES_UNCATEGORIZED)) {
|
||||
this.showItem('EditCategory');
|
||||
this.showItem('DeleteCategory');
|
||||
else
|
||||
}
|
||||
else {
|
||||
this.hideItem('EditCategory');
|
||||
this.hideItem('DeleteCategory');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -120,3 +120,14 @@ function escapeHtml(str) {
|
||||
div.appendChild(document.createTextNode(str));
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function safeTrim(value) {
|
||||
try {
|
||||
return value.trim();
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof TypeError)
|
||||
return "";
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,20 +458,21 @@ initializeWindows = function() {
|
||||
};
|
||||
|
||||
torrentNewCategoryFN = function() {
|
||||
var action = "set";
|
||||
var hashes = torrentsTable.selectedRowsIds();
|
||||
if (hashes.length) {
|
||||
new MochaUI.Window({
|
||||
id: 'newCategoryPage',
|
||||
title: "QBT_TR(New Category)QBT_TR[CONTEXT=TransferListWidget]",
|
||||
loadMethod: 'iframe',
|
||||
contentURL: 'newcategory.html?hashes=' + hashes.join('|'),
|
||||
contentURL: 'newcategory.html?action=' + action + '&hashes=' + hashes.join('|'),
|
||||
scrollbars: false,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: 0,
|
||||
width: 250,
|
||||
height: 100
|
||||
height: 150
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -494,18 +495,39 @@ initializeWindows = function() {
|
||||
};
|
||||
|
||||
createCategoryFN = function() {
|
||||
var action = "create";
|
||||
new MochaUI.Window({
|
||||
id: 'newCategoryPage',
|
||||
title: "QBT_TR(New Category)QBT_TR[CONTEXT=CategoryFilterWidget]",
|
||||
loadMethod: 'iframe',
|
||||
contentURL: 'newcategory.html',
|
||||
contentURL: 'newcategory.html?action=' + action,
|
||||
scrollbars: false,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: 0,
|
||||
width: 250,
|
||||
height: 100
|
||||
height: 150
|
||||
});
|
||||
updateMainData();
|
||||
};
|
||||
|
||||
editCategoryFN = function(categoryHash) {
|
||||
var action = "edit";
|
||||
var categoryName = category_list[categoryHash].name;
|
||||
var savePath = category_list[categoryHash].savePath;
|
||||
new MochaUI.Window({
|
||||
id: 'editCategoryPage',
|
||||
title: "QBT_TR(Edit Category)QBT_TR[CONTEXT=TransferListWidget]",
|
||||
loadMethod: 'iframe',
|
||||
contentURL: 'newcategory.html?action=' + action + '&categoryName=' + categoryName + '&savePath=' + savePath,
|
||||
scrollbars: false,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: 0,
|
||||
width: 250,
|
||||
height: 150
|
||||
});
|
||||
updateMainData();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user