|
|
@ -30,24 +30,29 @@ var alternativeSpeedLimits = false; |
|
|
|
var queueing_enabled = true; |
|
|
|
var queueing_enabled = true; |
|
|
|
var syncMainDataTimerPeriod = 1500; |
|
|
|
var syncMainDataTimerPeriod = 1500; |
|
|
|
|
|
|
|
|
|
|
|
selected_filter = getLocalStorageItem('selected_filter', 'all'); |
|
|
|
var LABELS_ALL = 1; |
|
|
|
selected_label = null; |
|
|
|
var LABELS_UNLABELLED = 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var label_list = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var selected_label = LABELS_ALL; |
|
|
|
|
|
|
|
var setLabelFilter = function(){}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var selected_filter = getLocalStorageItem('selected_filter', 'all'); |
|
|
|
|
|
|
|
var setFilter = function(){}; |
|
|
|
|
|
|
|
|
|
|
|
var loadSelectedLabel = function () { |
|
|
|
var loadSelectedLabel = function () { |
|
|
|
if (getLocalStorageItem('any_label', '1') == '0') |
|
|
|
selected_label = getLocalStorageItem('selected_label', LABELS_ALL); |
|
|
|
selected_label = getLocalStorageItem('selected_label', ''); |
|
|
|
}; |
|
|
|
else |
|
|
|
|
|
|
|
selected_label = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
loadSelectedLabel(); |
|
|
|
loadSelectedLabel(); |
|
|
|
|
|
|
|
|
|
|
|
var saveSelectedLabel = function () { |
|
|
|
function genHash(string) { |
|
|
|
if (selected_label == null) |
|
|
|
var hash = 0; |
|
|
|
localStorage.setItem('any_label', '1'); |
|
|
|
for (var i = 0; i < string.length; i++) { |
|
|
|
else { |
|
|
|
var c = string.charCodeAt(i); |
|
|
|
localStorage.setItem('any_label', '0'); |
|
|
|
hash = (c + hash * 31) | 0; |
|
|
|
localStorage.setItem('selected_label', selected_label); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return hash; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.addEvent('load', function () { |
|
|
|
window.addEvent('load', function () { |
|
|
@ -90,6 +95,14 @@ window.addEvent('load', function () { |
|
|
|
resizeLimit : [100, 300] |
|
|
|
resizeLimit : [100, 300] |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setLabelFilter = function(hash) { |
|
|
|
|
|
|
|
selected_label = hash; |
|
|
|
|
|
|
|
localStorage.setItem('selected_label', selected_label); |
|
|
|
|
|
|
|
highlightSelectedLabel(); |
|
|
|
|
|
|
|
if (typeof myTable.table != 'undefined') |
|
|
|
|
|
|
|
updateMainData(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
setFilter = function (f) { |
|
|
|
setFilter = function (f) { |
|
|
|
// Visually Select the right filter
|
|
|
|
// Visually Select the right filter
|
|
|
|
$("all_filter").removeClass("selectedFilter"); |
|
|
|
$("all_filter").removeClass("selectedFilter"); |
|
|
@ -148,6 +161,112 @@ window.addEvent('load', function () { |
|
|
|
var syncMainDataLastResponseId = 0; |
|
|
|
var syncMainDataLastResponseId = 0; |
|
|
|
var serverState = {}; |
|
|
|
var serverState = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var removeTorrentFromLabelList = function(hash) { |
|
|
|
|
|
|
|
if (hash == null || hash == "") |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
var removed = false; |
|
|
|
|
|
|
|
Object.each(label_list, function(label) { |
|
|
|
|
|
|
|
if (Object.contains(label.torrents, hash)) { |
|
|
|
|
|
|
|
removed = true; |
|
|
|
|
|
|
|
label.torrents.splice(label.torrents.indexOf(hash), 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return removed; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var addTorrentToLabelList = function(torrent) { |
|
|
|
|
|
|
|
var label = torrent['label']; |
|
|
|
|
|
|
|
if (label == null) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
if (label.length === 0) { // Empty label
|
|
|
|
|
|
|
|
removeTorrentFromLabelList(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']]); |
|
|
|
|
|
|
|
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 sortedLabels = [] |
|
|
|
|
|
|
|
Object.each(label_list, function(label) { |
|
|
|
|
|
|
|
sortedLabels.push(label.name); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
sortedLabels.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>'}); |
|
|
|
|
|
|
|
if (first) { |
|
|
|
|
|
|
|
el.addClass('separator'); |
|
|
|
|
|
|
|
first = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
labelList.appendChild(el); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var updateLabelList = function() { |
|
|
|
|
|
|
|
var labelList = $('filterLabelList'); |
|
|
|
|
|
|
|
if (!labelList) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
labelList.empty(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var create_link = function(hash, text, count) { |
|
|
|
|
|
|
|
var html = '<a href="#" onclick="setLabelFilter(' + hash + ');return false;">' + |
|
|
|
|
|
|
|
'<img src="theme/inode-directory"/>' + |
|
|
|
|
|
|
|
text + ' (' + count + ')' + '</a>'; |
|
|
|
|
|
|
|
return new Element('li', {id: hash, html: html}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var all = myTable.getRowIds().length; |
|
|
|
|
|
|
|
var unlabelled = 0; |
|
|
|
|
|
|
|
Object.each(myTable.rows, function(row) { |
|
|
|
|
|
|
|
if (row['full_data'].label.length === 0) |
|
|
|
|
|
|
|
unlabelled += 1; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
labelList.appendChild(create_link(LABELS_ALL, 'QBT_TR(All)QBT_TR', all)); |
|
|
|
|
|
|
|
labelList.appendChild(create_link(LABELS_UNLABELLED, 'QBT_TR(Unlabeled)QBT_TR', unlabelled)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sortedLabels = [] |
|
|
|
|
|
|
|
Object.each(label_list, function(label) { |
|
|
|
|
|
|
|
sortedLabels.push(label.name); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
sortedLabels.sort(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.each(sortedLabels, function(labelName) { |
|
|
|
|
|
|
|
var labelHash = genHash(labelName); |
|
|
|
|
|
|
|
var labelCount = label_list[labelHash].torrents.length; |
|
|
|
|
|
|
|
labelList.appendChild(create_link(labelHash, labelName, labelCount)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
highlightSelectedLabel(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var highlightSelectedLabel = function() { |
|
|
|
|
|
|
|
var labelList = $('filterLabelList'); |
|
|
|
|
|
|
|
if (!labelList) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
var childrens = labelList.childNodes; |
|
|
|
|
|
|
|
for (var i in childrens) { |
|
|
|
|
|
|
|
if (childrens[i].id == selected_label) |
|
|
|
|
|
|
|
childrens[i].className = "selectedFilter"; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
childrens[i].className = ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var syncMainDataTimer; |
|
|
|
var syncMainDataTimer; |
|
|
|
var syncMainData = function () { |
|
|
|
var syncMainData = function () { |
|
|
|
var url = new URI('sync/maindata'); |
|
|
|
var url = new URI('sync/maindata'); |
|
|
@ -164,19 +283,42 @@ window.addEvent('load', function () { |
|
|
|
onSuccess : function (response) { |
|
|
|
onSuccess : function (response) { |
|
|
|
$('error_div').set('html', ''); |
|
|
|
$('error_div').set('html', ''); |
|
|
|
if (response) { |
|
|
|
if (response) { |
|
|
|
|
|
|
|
var update_labels = false; |
|
|
|
var full_update = (response['full_update'] == true); |
|
|
|
var full_update = (response['full_update'] == true); |
|
|
|
if (full_update) |
|
|
|
if (full_update) { |
|
|
|
myTable.rows.erase(); |
|
|
|
myTable.rows.erase(); |
|
|
|
if (response['rid']) |
|
|
|
label_list = {}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (response['rid']) { |
|
|
|
syncMainDataLastResponseId = response['rid']; |
|
|
|
syncMainDataLastResponseId = response['rid']; |
|
|
|
if (response['torrents']) |
|
|
|
} |
|
|
|
|
|
|
|
if (response['labels']) { |
|
|
|
|
|
|
|
response['labels'].each(function(label) { |
|
|
|
|
|
|
|
var labelHash = genHash(label); |
|
|
|
|
|
|
|
label_list[labelHash] = {name: label, torrents: []}; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
update_labels = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (response['labels_removed']) { |
|
|
|
|
|
|
|
response['labels_removed'].each(function(label) { |
|
|
|
|
|
|
|
var labelHash = genHash(label); |
|
|
|
|
|
|
|
delete label_list[labelHash]; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
update_labels = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (response['torrents']) { |
|
|
|
for (var key in response['torrents']) { |
|
|
|
for (var key in response['torrents']) { |
|
|
|
response['torrents'][key]['hash'] = key; |
|
|
|
response['torrents'][key]['hash'] = key; |
|
|
|
myTable.updateRowData(response['torrents'][key]); |
|
|
|
myTable.updateRowData(response['torrents'][key]); |
|
|
|
|
|
|
|
if (addTorrentToLabelList(response['torrents'][key])) |
|
|
|
|
|
|
|
update_labels = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (response['torrents_removed']) |
|
|
|
if (response['torrents_removed']) |
|
|
|
response['torrents_removed'].each(function (hash) { |
|
|
|
response['torrents_removed'].each(function (hash) { |
|
|
|
myTable.removeRow(hash); |
|
|
|
myTable.removeRow(hash); |
|
|
|
|
|
|
|
removeTorrentFromLabelList(hash); |
|
|
|
|
|
|
|
update_labels = true; // Allways to update All label
|
|
|
|
}); |
|
|
|
}); |
|
|
|
myTable.updateTable(full_update); |
|
|
|
myTable.updateTable(full_update); |
|
|
|
myTable.altRow(); |
|
|
|
myTable.altRow(); |
|
|
@ -186,6 +328,10 @@ window.addEvent('load', function () { |
|
|
|
serverState[key] = tmp[key]; |
|
|
|
serverState[key] = tmp[key]; |
|
|
|
processServerState(); |
|
|
|
processServerState(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (update_labels) { |
|
|
|
|
|
|
|
updateLabelList(); |
|
|
|
|
|
|
|
updateContextMenu(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
clearTimeout(syncMainDataTimer); |
|
|
|
clearTimeout(syncMainDataTimer); |
|
|
|
syncMainDataTimer = syncMainData.delay(syncMainDataTimerPeriod); |
|
|
|
syncMainDataTimer = syncMainData.delay(syncMainDataTimerPeriod); |
|
|
|