Browse Source

WebUI: Implement adding categories

adaptive-webui-19844
buinsky 9 years ago
parent
commit
a4dca52617
  1. 16
      src/webui/webapplication.cpp
  2. 1
      src/webui/webapplication.h
  3. 1
      src/webui/www/private/index.html
  4. 5
      src/webui/www/public/filters.html
  5. 37
      src/webui/www/public/newcategory.html
  6. 6
      src/webui/www/public/scripts/contextmenu.js
  7. 21
      src/webui/www/public/scripts/mocha-init.js

16
src/webui/webapplication.cpp

@ -115,6 +115,7 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
ADD_ACTION(command, bottomPrio); ADD_ACTION(command, bottomPrio);
ADD_ACTION(command, recheck); ADD_ACTION(command, recheck);
ADD_ACTION(command, setCategory); ADD_ACTION(command, setCategory);
ADD_ACTION(command, addCategory);
ADD_ACTION(command, getSavePath); ADD_ACTION(command, getSavePath);
ADD_ACTION(version, api); ADD_ACTION(version, api);
ADD_ACTION(version, api_min); 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() void WebApplication::action_command_getSavePath()
{ {
CHECK_URI(0); CHECK_URI(0);

1
src/webui/webapplication.h

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

1
src/webui/www/private/index.html

@ -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> <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>
<ul id="categoriesFilterMenu" class="contextMenu"> <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> </ul>
<div id="desktopFooterWrapper"> <div id="desktopFooterWrapper">
<div id="desktopFooter"> <div id="desktopFooter">

5
src/webui/www/public/filters.html

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

37
src/webui/www/public/newcategory.html

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

6
src/webui/www/public/scripts/contextmenu.js

@ -292,8 +292,8 @@ var TorrentsTableContextMenu = new Class({
updateCategoriesSubMenu : function (category_list) { updateCategoriesSubMenu : function (category_list) {
var categoryList = $('contextCategoryList'); var categoryList = $('contextCategoryList');
categoryList.empty(); 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: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: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:torrentSetCategoryFN(0);"><img src="theme/edit-clear" alt="QBT_TR(Reset)QBT_TR"/> QBT_TR(Reset)QBT_TR</a>'}));
var sortedCategories = [] var sortedCategories = []
Object.each(category_list, function (category) { Object.each(category_list, function (category) {
@ -304,7 +304,7 @@ var TorrentsTableContextMenu = new Class({
var first = true; var first = true;
Object.each(sortedCategories, function (categoryName) { Object.each(sortedCategories, function (categoryName) {
var categoryHash = genHash(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) { if (first) {
el.addClass('separator'); el.addClass('separator');
first = false; first = false;

21
src/webui/www/public/scripts/mocha-init.js

@ -304,7 +304,7 @@ initializeWindows = function() {
} }
}; };
newCategoryFN = function () { torrentNewCategoryFN = function () {
var h = torrentsTable.selectedRowsIds(); var h = torrentsTable.selectedRowsIds();
if (h.length) { if (h.length) {
new MochaUI.Window({ new MochaUI.Window({
@ -323,7 +323,7 @@ initializeWindows = function() {
} }
}; };
setCategoryFN = function (categoryHash) { torrentSetCategoryFN = function (categoryHash) {
var categoryName = ''; var categoryName = '';
if (categoryHash != 0) if (categoryHash != 0)
var categoryName = category_list[categoryHash].name; 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) { ['pauseAll', 'resumeAll'].each(function(item) {
addClickEvent(item, function(e) { addClickEvent(item, function(e) {
new Event(e).stop(); new Event(e).stop();

Loading…
Cancel
Save