From a4dca52617190d282927083c3b9a9dbcc866c7d1 Mon Sep 17 00:00:00 2001 From: buinsky Date: Thu, 21 Jan 2016 15:32:13 +0300 Subject: [PATCH] WebUI: Implement adding categories --- src/webui/webapplication.cpp | 16 +++++++++ src/webui/webapplication.h | 1 + src/webui/www/private/index.html | 1 + src/webui/www/public/filters.html | 5 +++ src/webui/www/public/newcategory.html | 37 +++++++++++++++------ src/webui/www/public/scripts/contextmenu.js | 6 ++-- src/webui/www/public/scripts/mocha-init.js | 21 ++++++++++-- 7 files changed, 71 insertions(+), 16 deletions(-) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index f95e387e2..5f7a1c5df 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -115,6 +115,7 @@ QMap > 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); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index a87acc8f8..efa446531 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -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(); diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 76f1cc3f9..2f894f140 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -126,6 +126,7 @@
  • QBT_TR(Force recheck)QBT_TR QBT_TR(Force recheck)QBT_TR
  • diff --git a/src/webui/www/public/filters.html b/src/webui/www/public/filters.html index 617af522e..a1bba5e3d 100644 --- a/src/webui/www/public/filters.html +++ b/src/webui/www/public/filters.html @@ -19,6 +19,11 @@ var categoriesFilterContextMenu = new CategoriesFilterContextMenu({ targets : '.categoriesFilterContextMenuTarget', menu : 'categoriesFilterMenu', + actions : { + CreateCategory : function (element, ref) { + createCategoryFN(); + } + }, offsets : { x : -15, y : 2 diff --git a/src/webui/www/public/newcategory.html b/src/webui/www/public/newcategory.html index cca0929fa..177186af3 100644 --- a/src/webui/www/public/newcategory.html +++ b/src/webui/www/public/newcategory.html @@ -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(); + } }); }); diff --git a/src/webui/www/public/scripts/contextmenu.js b/src/webui/www/public/scripts/contextmenu.js index 51d1d818e..717e4d5b5 100644 --- a/src/webui/www/public/scripts/contextmenu.js +++ b/src/webui/www/public/scripts/contextmenu.js @@ -292,8 +292,8 @@ var TorrentsTableContextMenu = new Class({ updateCategoriesSubMenu : function (category_list) { var categoryList = $('contextCategoryList'); categoryList.empty(); - categoryList.appendChild(new Element('li', {html: 'QBT_TR(New...)QBT_TR QBT_TR(New...)QBT_TR'})); - categoryList.appendChild(new Element('li', {html: 'QBT_TR(Reset)QBT_TR QBT_TR(Reset)QBT_TR'})); + categoryList.appendChild(new Element('li', {html: 'QBT_TR(New...)QBT_TR QBT_TR(New...)QBT_TR'})); + categoryList.appendChild(new Element('li', {html: 'QBT_TR(Reset)QBT_TR QBT_TR(Reset)QBT_TR'})); 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: ' ' + escapeHtml(categoryName) + ''}); + var el = new Element('li', {html: ' ' + escapeHtml(categoryName) + ''}); if (first) { el.addClass('separator'); first = false; diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js index 86895c5dc..ae2e6a704 100644 --- a/src/webui/www/public/scripts/mocha-init.js +++ b/src/webui/www/public/scripts/mocha-init.js @@ -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();