WebUI: Implement adding categories

This commit is contained in:
buinsky 2016-01-21 15:32:13 +03:00
parent a939fca4ac
commit a4dca52617
7 changed files with 71 additions and 16 deletions

View file

@ -115,6 +115,7 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
ADD_ACTION(command, bottomPrio);
ADD_ACTION(command, recheck);
ADD_ACTION(command, setCategory);
ADD_ACTION(command, addCategory);
ADD_ACTION(command, getSavePath);
ADD_ACTION(version, api);
ADD_ACTION(version, api_min);
@ -728,6 +729,21 @@ void WebApplication::action_command_setCategory()
}
}
void WebApplication::action_command_addCategory()
{
CHECK_URI(0);
CHECK_PARAMETERS("category");
QString category = request().posts["category"].trimmed();
if (!BitTorrent::Session::isValidCategoryName(category) && !category.isEmpty()) {
status(400, tr("Incorrect category name"));
return;
}
BitTorrent::Session::instance()->addCategory(category);
}
void WebApplication::action_command_getSavePath()
{
CHECK_URI(0);

View file

@ -88,6 +88,7 @@ private:
void action_command_bottomPrio();
void action_command_recheck();
void action_command_setCategory();
void action_command_addCategory();
void action_command_getSavePath();
void action_version_api();
void action_version_api_min();

View file

@ -126,6 +126,7 @@
<li class="separator"><a href="#ForceRecheck"><img src="theme/document-edit-verify" alt="QBT_TR(Force recheck)QBT_TR"/> QBT_TR(Force recheck)QBT_TR</a></li>
</ul>
<ul id="categoriesFilterMenu" class="contextMenu">
<li><a href="#CreateCategory"><img src="theme/list-add" alt="QBT_TR(Add category...)QBT_TR"/> QBT_TR(Add category...)QBT_TR</a></li>
</ul>
<div id="desktopFooterWrapper">
<div id="desktopFooter">

View file

@ -19,6 +19,11 @@
var categoriesFilterContextMenu = new CategoriesFilterContextMenu({
targets : '.categoriesFilterContextMenuTarget',
menu : 'categoriesFilterMenu',
actions : {
CreateCategory : function (element, ref) {
createCategoryFN();
}
},
offsets : {
x : -15,
y : 2

View file

@ -31,17 +31,32 @@
return false;
}
var hashesList = new URI().getData('hashes');
new Request({
url: 'command/setCategory',
method: 'post',
data: {
hashes: hashesList,
category: categoryName
},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
if (!hashesList) {
new Request({
url: 'command/addCategory',
method: 'post',
data: {
category: categoryName
},
onComplete: function () {
window.parent.closeWindows();
}
}).send();
}
else
{
new Request({
url: 'command/setCategory',
method: 'post',
data: {
hashes: hashesList,
category: categoryName
},
onComplete: function () {
window.parent.closeWindows();
}
}).send();
}
});
});
</script>

View file

@ -292,8 +292,8 @@ var TorrentsTableContextMenu = new Class({
updateCategoriesSubMenu : function (category_list) {
var categoryList = $('contextCategoryList');
categoryList.empty();
categoryList.appendChild(new Element('li', {html: '<a href="javascript:newCategoryFN();"><img src="theme/list-add" alt="QBT_TR(New...)QBT_TR"/> QBT_TR(New...)QBT_TR</a>'}));
categoryList.appendChild(new Element('li', {html: '<a href="javascript:setCategoryFN(0);"><img src="theme/edit-clear" alt="QBT_TR(Reset)QBT_TR"/> QBT_TR(Reset)QBT_TR</a>'}));
categoryList.appendChild(new Element('li', {html: '<a href="javascript:torrentNewCategoryFN();"><img src="theme/list-add" alt="QBT_TR(New...)QBT_TR"/> QBT_TR(New...)QBT_TR</a>'}));
categoryList.appendChild(new Element('li', {html: '<a href="javascript:torrentSetCategoryFN(0);"><img src="theme/edit-clear" alt="QBT_TR(Reset)QBT_TR"/> QBT_TR(Reset)QBT_TR</a>'}));
var sortedCategories = []
Object.each(category_list, function (category) {
@ -304,7 +304,7 @@ var TorrentsTableContextMenu = new Class({
var first = true;
Object.each(sortedCategories, function (categoryName) {
var categoryHash = genHash(categoryName);
var el = new Element('li', {html: '<a href="javascript:setCategoryFN(\'' + categoryHash + '\');"><img src="theme/inode-directory"/> ' + escapeHtml(categoryName) + '</a>'});
var el = new Element('li', {html: '<a href="javascript:torrentSetCategoryFN(\'' + categoryHash + '\');"><img src="theme/inode-directory"/> ' + escapeHtml(categoryName) + '</a>'});
if (first) {
el.addClass('separator');
first = false;

View file

@ -304,7 +304,7 @@ initializeWindows = function() {
}
};
newCategoryFN = function () {
torrentNewCategoryFN = function () {
var h = torrentsTable.selectedRowsIds();
if (h.length) {
new MochaUI.Window({
@ -323,7 +323,7 @@ initializeWindows = function() {
}
};
setCategoryFN = function (categoryHash) {
torrentSetCategoryFN = function (categoryHash) {
var categoryName = '';
if (categoryHash != 0)
var categoryName = category_list[categoryHash].name;
@ -340,6 +340,23 @@ initializeWindows = function() {
}
};
createCategoryFN = function () {
new MochaUI.Window({
id: 'newCategoryPage',
title: "QBT_TR(New Category)QBT_TR",
loadMethod: 'iframe',
contentURL: 'newcategory.html',
scrollbars: false,
resizable: false,
maximizable: false,
paddingVertical: 0,
paddingHorizontal: 0,
width: 250,
height: 100
});
updateMainData();
};
['pauseAll', 'resumeAll'].each(function(item) {
addClickEvent(item, function(e) {
new Event(e).stop();