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 @@ -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() @@ -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);

1
src/webui/webapplication.h

@ -88,6 +88,7 @@ private: @@ -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();

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

@ -126,6 +126,7 @@ @@ -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">

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

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

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

@ -31,17 +31,32 @@ @@ -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>

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

@ -292,8 +292,8 @@ var TorrentsTableContextMenu = new Class({ @@ -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({ @@ -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;

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

@ -304,7 +304,7 @@ initializeWindows = function() { @@ -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() { @@ -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() { @@ -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();

Loading…
Cancel
Save