mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
parent
d05d5a85a5
commit
dd34663224
59 changed files with 1796 additions and 1280 deletions
|
@ -38,21 +38,21 @@ var alternativeSpeedLimits = false;
|
|||
var queueing_enabled = true;
|
||||
var syncMainDataTimerPeriod = 1500;
|
||||
|
||||
var LABELS_ALL = 1;
|
||||
var LABELS_UNLABELLED = 2;
|
||||
var CATEGORIES_ALL = 1;
|
||||
var CATEGORIES_UNCATEGORIZED = 2;
|
||||
|
||||
var label_list = {};
|
||||
var category_list = {};
|
||||
|
||||
var selected_label = LABELS_ALL;
|
||||
var setLabelFilter = function(){};
|
||||
var selected_category = CATEGORIES_ALL;
|
||||
var setCategoryFilter = function(){};
|
||||
|
||||
var selected_filter = getLocalStorageItem('selected_filter', 'all');
|
||||
var setFilter = function(){};
|
||||
|
||||
var loadSelectedLabel = function () {
|
||||
selected_label = getLocalStorageItem('selected_label', LABELS_ALL);
|
||||
var loadSelectedCategory = function () {
|
||||
selected_category = getLocalStorageItem('selected_category', CATEGORIES_ALL);
|
||||
};
|
||||
loadSelectedLabel();
|
||||
loadSelectedCategory();
|
||||
|
||||
function genHash(string) {
|
||||
var hash = 0;
|
||||
|
@ -103,10 +103,10 @@ window.addEvent('load', function () {
|
|||
resizeLimit : [100, 300]
|
||||
});
|
||||
|
||||
setLabelFilter = function(hash) {
|
||||
selected_label = hash;
|
||||
localStorage.setItem('selected_label', selected_label);
|
||||
highlightSelectedLabel();
|
||||
setCategoryFilter = function(hash) {
|
||||
selected_category = hash;
|
||||
localStorage.setItem('selected_category', selected_category);
|
||||
highlightSelectedCategory();
|
||||
if (typeof torrentsTable.table != 'undefined')
|
||||
updateMainData();
|
||||
};
|
||||
|
@ -170,59 +170,59 @@ window.addEvent('load', function () {
|
|||
var syncMainDataLastResponseId = 0;
|
||||
var serverState = {};
|
||||
|
||||
var removeTorrentFromLabelList = function(hash) {
|
||||
var removeTorrentFromCategoryList = function(hash) {
|
||||
if (hash == null || hash == "")
|
||||
return false;
|
||||
var removed = false;
|
||||
Object.each(label_list, function(label) {
|
||||
if (Object.contains(label.torrents, hash)) {
|
||||
Object.each(category_list, function(category) {
|
||||
if (Object.contains(category.torrents, hash)) {
|
||||
removed = true;
|
||||
label.torrents.splice(label.torrents.indexOf(hash), 1);
|
||||
category.torrents.splice(category.torrents.indexOf(hash), 1);
|
||||
}
|
||||
});
|
||||
return removed;
|
||||
};
|
||||
|
||||
var addTorrentToLabelList = function(torrent) {
|
||||
var label = torrent['label'];
|
||||
if (label == null)
|
||||
var addTorrentToCategoryList = function(torrent) {
|
||||
var category = torrent['category'];
|
||||
if (category == null)
|
||||
return false;
|
||||
if (label.length === 0) { // Empty label
|
||||
removeTorrentFromLabelList(torrent['hash']);
|
||||
if (category.length === 0) { // Empty category
|
||||
removeTorrentFromCategoryList(torrent['hash']);
|
||||
return true;
|
||||
}
|
||||
var labelHash = genHash(label);
|
||||
if (label_list[labelHash] == null) // This should not happen
|
||||
label_list[labelHash] = {name: label, torrents: []};
|
||||
if (!Object.contains(label_list[labelHash].torrents, torrent['hash'])) {
|
||||
removeTorrentFromLabelList(torrent['hash']);
|
||||
label_list[labelHash].torrents = label_list[labelHash].torrents.combine([torrent['hash']]);
|
||||
var categoryHash = genHash(category);
|
||||
if (category_list[categoryHash] == null) // This should not happen
|
||||
category_list[categoryHash] = {name: category, torrents: []};
|
||||
if (!Object.contains(category_list[categoryHash].torrents, torrent['hash'])) {
|
||||
removeTorrentFromCategoryList(torrent['hash']);
|
||||
category_list[categoryHash].torrents = category_list[categoryHash].torrents.combine([torrent['hash']]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
var updateContextMenu = function () {
|
||||
var labelList = $('contextLabelList');
|
||||
labelList.empty();
|
||||
labelList.appendChild(new Element('li', {html: '<a href="javascript:newLabelFN();"><img src="theme/list-add" alt="QBT_TR(New...)QBT_TR"/> QBT_TR(New...)QBT_TR</a>'}));
|
||||
labelList.appendChild(new Element('li', {html: '<a href="javascript:updateLabelFN(0);"><img src="theme/edit-clear" alt="QBT_TR(Reset)QBT_TR"/> QBT_TR(Reset)QBT_TR</a>'}));
|
||||
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:updateCategoryFN(0);"><img src="theme/edit-clear" alt="QBT_TR(Reset)QBT_TR"/> QBT_TR(Reset)QBT_TR</a>'}));
|
||||
|
||||
var sortedLabels = []
|
||||
Object.each(label_list, function(label) {
|
||||
sortedLabels.push(label.name);
|
||||
var sortedCategories = []
|
||||
Object.each(category_list, function(category) {
|
||||
sortedCategories.push(category.name);
|
||||
});
|
||||
sortedLabels.sort();
|
||||
sortedCategories.sort();
|
||||
|
||||
var first = true;
|
||||
Object.each(sortedLabels, function(labelName) {
|
||||
var labelHash = genHash(labelName);
|
||||
var el = new Element('li', {html: '<a href="javascript:updateLabelFN(\'' + labelHash + '\');"><img src="theme/inode-directory"/> ' + labelName + '</a>'});
|
||||
Object.each(sortedCategories, function(categoryName) {
|
||||
var categoryHash = genHash(categoryName);
|
||||
var el = new Element('li', {html: '<a href="javascript:updateCategoryFN(\'' + categoryHash + '\');"><img src="theme/inode-directory"/> ' + categoryName + '</a>'});
|
||||
if (first) {
|
||||
el.addClass('separator');
|
||||
first = false;
|
||||
}
|
||||
labelList.appendChild(el);
|
||||
categoryList.appendChild(el);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -242,50 +242,50 @@ window.addEvent('load', function () {
|
|||
updateFilter('errored', 'QBT_TR(Errored (%1))QBT_TR');
|
||||
};
|
||||
|
||||
var updateLabelList = function() {
|
||||
var labelList = $('filterLabelList');
|
||||
if (!labelList)
|
||||
var updateCategoryList = function() {
|
||||
var categoryList = $('filterCategoryList');
|
||||
if (!categoryList)
|
||||
return;
|
||||
labelList.empty();
|
||||
categoryList.empty();
|
||||
|
||||
var create_link = function(hash, text, count) {
|
||||
var html = '<a href="#" onclick="setLabelFilter(' + hash + ');return false;">' +
|
||||
var html = '<a href="#" onclick="setCategoryFilter(' + hash + ');return false;">' +
|
||||
'<img src="theme/inode-directory"/>' +
|
||||
text + ' (' + count + ')' + '</a>';
|
||||
return new Element('li', {id: hash, html: html});
|
||||
};
|
||||
|
||||
var all = torrentsTable.getRowIds().length;
|
||||
var unlabelled = 0;
|
||||
var uncategorized = 0;
|
||||
Object.each(torrentsTable.rows, function(row) {
|
||||
if (row['full_data'].label.length === 0)
|
||||
unlabelled += 1;
|
||||
if (row['full_data'].category.length === 0)
|
||||
uncategorized += 1;
|
||||
});
|
||||
labelList.appendChild(create_link(LABELS_ALL, 'QBT_TR(All (0))QBT_TR'.replace(' (0)', ''), all));
|
||||
labelList.appendChild(create_link(LABELS_UNLABELLED, 'QBT_TR(Unlabeled (0))QBT_TR'.replace(' (0)', ''), unlabelled));
|
||||
categoryList.appendChild(create_link(CATEGORIES_ALL, 'QBT_TR(All (0))QBT_TR'.replace(' (0)', ''), all));
|
||||
categoryList.appendChild(create_link(CATEGORIES_UNCATEGORIZED, 'QBT_TR(Uncategorized (0))QBT_TR'.replace(' (0)', ''), uncategorized));
|
||||
|
||||
var sortedLabels = []
|
||||
Object.each(label_list, function(label) {
|
||||
sortedLabels.push(label.name);
|
||||
var sortedCategories = []
|
||||
Object.each(category_list, function(category) {
|
||||
sortedCategories.push(category.name);
|
||||
});
|
||||
sortedLabels.sort();
|
||||
sortedCategories.sort();
|
||||
|
||||
Object.each(sortedLabels, function(labelName) {
|
||||
var labelHash = genHash(labelName);
|
||||
var labelCount = label_list[labelHash].torrents.length;
|
||||
labelList.appendChild(create_link(labelHash, labelName, labelCount));
|
||||
Object.each(sortedCategories, function(categoryName) {
|
||||
var categoryHash = genHash(categoryName);
|
||||
var categoryCount = category_list[categoryHash].torrents.length;
|
||||
categoryList.appendChild(create_link(categoryHash, categoryName, categoryCount));
|
||||
});
|
||||
|
||||
highlightSelectedLabel();
|
||||
highlightSelectedCategory();
|
||||
};
|
||||
|
||||
var highlightSelectedLabel = function() {
|
||||
var labelList = $('filterLabelList');
|
||||
if (!labelList)
|
||||
var highlightSelectedCategory = function() {
|
||||
var categoryList = $('filterCategoryList');
|
||||
if (!categoryList)
|
||||
return;
|
||||
var childrens = labelList.childNodes;
|
||||
var childrens = categoryList.childNodes;
|
||||
for (var i in childrens) {
|
||||
if (childrens[i].id == selected_label)
|
||||
if (childrens[i].id == selected_category)
|
||||
childrens[i].className = "selectedFilter";
|
||||
else
|
||||
childrens[i].className = "";
|
||||
|
@ -308,43 +308,43 @@ window.addEvent('load', function () {
|
|||
onSuccess : function (response) {
|
||||
$('error_div').set('html', '');
|
||||
if (response) {
|
||||
var update_labels = false;
|
||||
var update_categories = false;
|
||||
var full_update = (response['full_update'] == true);
|
||||
if (full_update) {
|
||||
torrentsTable.clear();
|
||||
label_list = {};
|
||||
category_list = {};
|
||||
}
|
||||
if (response['rid']) {
|
||||
syncMainDataLastResponseId = response['rid'];
|
||||
}
|
||||
if (response['labels']) {
|
||||
response['labels'].each(function(label) {
|
||||
var labelHash = genHash(label);
|
||||
label_list[labelHash] = {name: label, torrents: []};
|
||||
if (response['categories']) {
|
||||
response['categories'].each(function(category) {
|
||||
var categoryHash = genHash(category);
|
||||
category_list[categoryHash] = {name: category, torrents: []};
|
||||
});
|
||||
update_labels = true;
|
||||
update_categories = true;
|
||||
}
|
||||
if (response['labels_removed']) {
|
||||
response['labels_removed'].each(function(label) {
|
||||
var labelHash = genHash(label);
|
||||
delete label_list[labelHash];
|
||||
if (response['categories_removed']) {
|
||||
response['categories_removed'].each(function(category) {
|
||||
var categoryHash = genHash(category);
|
||||
delete category_list[categoryHash];
|
||||
});
|
||||
update_labels = true;
|
||||
update_categories = true;
|
||||
}
|
||||
if (response['torrents']) {
|
||||
for (var key in response['torrents']) {
|
||||
response['torrents'][key]['hash'] = key;
|
||||
response['torrents'][key]['rowId'] = key;
|
||||
torrentsTable.updateRowData(response['torrents'][key]);
|
||||
if (addTorrentToLabelList(response['torrents'][key]))
|
||||
update_labels = true;
|
||||
if (addTorrentToCategoryList(response['torrents'][key]))
|
||||
update_categories = true;
|
||||
}
|
||||
}
|
||||
if (response['torrents_removed'])
|
||||
response['torrents_removed'].each(function (hash) {
|
||||
torrentsTable.removeRow(hash);
|
||||
removeTorrentFromLabelList(hash);
|
||||
update_labels = true; // Allways to update All label
|
||||
removeTorrentFromCategoryList(hash);
|
||||
update_categories = true; // Allways to update All category
|
||||
});
|
||||
torrentsTable.updateTable(full_update);
|
||||
torrentsTable.altRow();
|
||||
|
@ -355,8 +355,8 @@ window.addEvent('load', function () {
|
|||
processServerState();
|
||||
}
|
||||
updateFiltersList();
|
||||
if (update_labels) {
|
||||
updateLabelList();
|
||||
if (update_categories) {
|
||||
updateCategoryList();
|
||||
updateContextMenu();
|
||||
}
|
||||
}
|
||||
|
@ -683,4 +683,4 @@ var loadTorrentPeersData = function(){
|
|||
updateTorrentPeersData = function(){
|
||||
clearTimeout(loadTorrentPeersTimer);
|
||||
loadTorrentPeersData();
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue