2014-12-08 23:00:00 +03:00
|
|
|
var is_seed = true;
|
|
|
|
var current_hash = "";
|
|
|
|
|
|
|
|
if (!(Browser.name == "ie" && Browser.version < 9)) {
|
|
|
|
$("all_files_cb").removeClass("tristate");
|
|
|
|
$("all_files_cb").removeClass("partial");
|
|
|
|
$("all_files_cb").removeClass("checked");
|
|
|
|
$("tristate_cb").style.display = "inline";
|
|
|
|
}
|
|
|
|
|
|
|
|
var setCBState = function(state) {
|
|
|
|
if (Browser.name == "ie" && Browser.version < 9) {
|
|
|
|
if (state == "partial") {
|
|
|
|
if (!$("all_files_cb").hasClass("partial")) {
|
|
|
|
$("all_files_cb").removeClass("checked");
|
|
|
|
$("all_files_cb").addClass("partial");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (state == "checked") {
|
|
|
|
if (!$("all_files_cb").hasClass("checked")) {
|
|
|
|
$("all_files_cb").removeClass("partial");
|
|
|
|
$("all_files_cb").addClass("checked");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$("all_files_cb").removeClass("partial");
|
|
|
|
$("all_files_cb").removeClass("checked");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (state == "partial") {
|
|
|
|
$("tristate_cb").indeterminate = true;
|
|
|
|
}
|
|
|
|
else if (state == "checked") {
|
|
|
|
$("tristate_cb").indeterminate = false;
|
|
|
|
$("tristate_cb").checked = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("tristate_cb").indeterminate = false;
|
|
|
|
$("tristate_cb").checked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var switchCBState = function() {
|
|
|
|
// Uncheck
|
|
|
|
if ($("all_files_cb").hasClass("partial")) {
|
|
|
|
$("all_files_cb").removeClass("partial");
|
|
|
|
// Uncheck all checkboxes
|
|
|
|
$$('input.DownloadedCB').each(function(item, index) {
|
|
|
|
item.erase("checked");
|
|
|
|
setFilePriority(index, 0);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($("all_files_cb").hasClass("checked")) {
|
|
|
|
$("all_files_cb").removeClass("checked");
|
|
|
|
// Uncheck all checkboxes
|
|
|
|
$$('input.DownloadedCB').each(function(item, index) {
|
|
|
|
item.erase("checked");
|
|
|
|
setFilePriority(index, 0);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Check
|
|
|
|
$("all_files_cb").addClass("checked");
|
|
|
|
// Check all checkboxes
|
|
|
|
$$('input.DownloadedCB').each(function(item, index) {
|
|
|
|
item.set("checked", "checked");
|
|
|
|
setFilePriority(index, 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var allCBChecked = function() {
|
|
|
|
var CBs = $$('input.DownloadedCB');
|
|
|
|
for (var i = 0; i < CBs.length; i += 1) {
|
|
|
|
var item = CBs[i];
|
|
|
|
if (!$defined(item.get('checked')) || !item.get('checked'))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var allCBUnchecked = function() {
|
|
|
|
var CBs = $$('input.DownloadedCB');
|
|
|
|
for (var i = 0; i < CBs.length; i += 1) {
|
|
|
|
var item = CBs[i];
|
|
|
|
if ($defined(item.get('checked')) && item.get('checked'))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var setFilePriority = function(id, priority) {
|
|
|
|
if (current_hash == "") return;
|
|
|
|
new Request({
|
|
|
|
url: 'command/setFilePrio',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
'hash': current_hash,
|
|
|
|
'id': id,
|
|
|
|
'priority': priority
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
// Display or add combobox
|
|
|
|
if (priority > 0) {
|
|
|
|
$('comboPrio' + id).set("value", 1);
|
|
|
|
$('comboPrio' + id).removeClass("invisible");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('comboPrio' + id).addClass("invisible");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var createDownloadedCB = function(id, downloaded) {
|
|
|
|
var CB = new Element('input');
|
|
|
|
CB.set('type', 'checkbox');
|
|
|
|
if (downloaded)
|
|
|
|
CB.set('checked', 'checked');
|
|
|
|
CB.set('id', 'cbPrio' + id);
|
|
|
|
CB.set('class', 'DownloadedCB');
|
|
|
|
CB.addEvent('change', function(e) {
|
|
|
|
var checked = 0;
|
|
|
|
if ($defined($('cbPrio' + id).get('checked')) && $('cbPrio' + id).get('checked'))
|
|
|
|
checked = 1;
|
|
|
|
setFilePriority(id, checked);
|
|
|
|
if (allCBChecked()) {
|
|
|
|
setCBState("checked");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (allCBUnchecked()) {
|
|
|
|
setCBState("unchecked");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setCBState("partial");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return CB;
|
|
|
|
}
|
|
|
|
|
|
|
|
var createPriorityCombo = function(id, selected_prio) {
|
|
|
|
var select = new Element('select');
|
|
|
|
select.set('id', 'comboPrio' + id);
|
|
|
|
select.addEvent('change', function(e) {
|
|
|
|
var new_prio = $('comboPrio' + id).get('value');
|
|
|
|
setFilePriority(id, new_prio);
|
|
|
|
});
|
|
|
|
var opt = new Element("option");
|
|
|
|
opt.set('value', '1')
|
2014-12-17 14:58:32 +03:00
|
|
|
opt.set('html', "QBT_TR(Normal)QBT_TR");
|
2014-12-08 23:00:00 +03:00
|
|
|
if (selected_prio <= 1)
|
|
|
|
opt.setAttribute('selected', '');
|
|
|
|
opt.injectInside(select);
|
|
|
|
opt = new Element("option");
|
|
|
|
opt.set('value', '2')
|
2014-12-17 14:58:32 +03:00
|
|
|
opt.set('html', "QBT_TR(High)QBT_TR");
|
2014-12-08 23:00:00 +03:00
|
|
|
if (selected_prio == 2)
|
|
|
|
opt.setAttribute('selected', '');
|
|
|
|
opt.injectInside(select);
|
|
|
|
opt = new Element("option");
|
|
|
|
opt.set('value', '7')
|
2014-12-17 14:58:32 +03:00
|
|
|
opt.set('html', "QBT_TR(Maximum)QBT_TR");
|
2014-12-08 23:00:00 +03:00
|
|
|
if (selected_prio == 7)
|
|
|
|
opt.setAttribute('selected', '');
|
|
|
|
opt.injectInside(select);
|
|
|
|
if (is_seed || selected_prio < 1) {
|
|
|
|
select.addClass("invisible");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
select.removeClass("invisible");
|
|
|
|
}
|
|
|
|
select.addClass("combo_priority");
|
|
|
|
return select;
|
|
|
|
}
|
|
|
|
|
|
|
|
var filesDynTable = new Class({
|
|
|
|
|
|
|
|
initialize: function() {},
|
|
|
|
|
|
|
|
setup: function(table) {
|
|
|
|
this.table = $(table);
|
|
|
|
this.rows = new Hash();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeRow: function(id) {
|
|
|
|
if (this.rows.has(id)) {
|
|
|
|
var tr = this.rows.get(id);
|
|
|
|
tr.dispose();
|
|
|
|
this.rows.erase(id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeAllRows: function() {
|
|
|
|
this.rows.each(function(tr, id) {
|
|
|
|
this.removeRow(id);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
updateRow: function(tr, row, id) {
|
|
|
|
var tds = tr.getElements('td');
|
|
|
|
for (var i = 0; i < row.length; i++) {
|
|
|
|
if (i == 3) {
|
|
|
|
$('pbf_' + id).setValue(row[i].toFloat());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i == 0) {
|
|
|
|
if (row[i] > 0)
|
|
|
|
tds[i].getChildren('input')[0].set('checked', 'checked');
|
|
|
|
else
|
|
|
|
tds[i].getChildren('input')[0].removeProperty('checked')
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i == 4) {
|
|
|
|
if (!is_seed && row[i] > 0) {
|
|
|
|
tds[i].getChildren('select').set('value', row[i]);
|
|
|
|
$('comboPrio' + id).removeClass("invisible");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!$('comboPrio' + id).hasClass("invisible"))
|
|
|
|
$('comboPrio' + id).addClass("invisible");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tds[i].set('html', row[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
insertRow: function(id, row) {
|
|
|
|
if (this.rows.has(id)) {
|
|
|
|
var tr = this.rows.get(id);
|
|
|
|
this.updateRow(tr, row, id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//this.removeRow(id);
|
|
|
|
var tr = new Element('tr');
|
|
|
|
this.rows.set(id, tr);
|
|
|
|
for (var i = 0; i < row.length; i++) {
|
|
|
|
var td = new Element('td');
|
|
|
|
if (i == 3) {
|
|
|
|
td.adopt(new ProgressBar(row[i].toFloat(), {
|
|
|
|
'id': 'pbf_' + id,
|
|
|
|
'width': 80
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i == 0) {
|
|
|
|
var tree_img = new Element('img', {
|
|
|
|
src: 'images/L.gif',
|
|
|
|
style: 'margin-bottom: -2px'
|
|
|
|
});
|
|
|
|
td.adopt(tree_img, createDownloadedCB(id, row[i]));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i == 4) {
|
|
|
|
td.adopt(createPriorityCombo(id, row[i]));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
td.set('html', row[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
td.injectInside(tr);
|
|
|
|
}
|
|
|
|
tr.injectInside(this.table);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2014-12-11 02:01:04 +03:00
|
|
|
var loadTorrentFilesDataTimer;
|
2014-12-08 23:00:00 +03:00
|
|
|
var loadTorrentFilesData = function() {
|
|
|
|
if ($('prop_files').hasClass('invisible')) {
|
|
|
|
// Tab changed, don't do anything
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var new_hash = myTable.getCurrentTorrentHash();
|
|
|
|
if (new_hash == "") {
|
|
|
|
fTable.removeAllRows();
|
2014-12-11 23:22:23 +03:00
|
|
|
clearTimeout(loadTorrentFilesDataTimer);
|
2014-12-09 00:00:00 +03:00
|
|
|
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000);
|
2014-12-08 23:00:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (new_hash != current_hash) {
|
|
|
|
fTable.removeAllRows();
|
|
|
|
current_hash = new_hash;
|
|
|
|
}
|
2015-01-23 01:37:12 +03:00
|
|
|
var url = 'query/propertiesFiles/' + current_hash;
|
2014-12-11 02:01:04 +03:00
|
|
|
var request = new Request.JSON({
|
|
|
|
url: url,
|
|
|
|
noCache: true,
|
|
|
|
method: 'get',
|
|
|
|
onFailure: function() {
|
2014-12-17 14:58:32 +03:00
|
|
|
$('error_div').set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR');
|
2014-12-11 23:22:23 +03:00
|
|
|
clearTimeout(loadTorrentFilesDataTimer);
|
2014-12-09 00:00:00 +03:00
|
|
|
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(10000);
|
2014-12-11 02:01:04 +03:00
|
|
|
},
|
|
|
|
onSuccess: function(files) {
|
|
|
|
$('error_div').set('html', '');
|
|
|
|
if (files) {
|
|
|
|
// Update Trackers data
|
|
|
|
var i = 0;
|
|
|
|
files.each(function(file) {
|
|
|
|
if (i == 0) {
|
|
|
|
is_seed = file.is_seed;
|
2014-12-08 23:00:00 +03:00
|
|
|
}
|
2014-12-11 02:01:04 +03:00
|
|
|
var row = new Array();
|
|
|
|
row.length = 4;
|
|
|
|
row[0] = file.priority;
|
|
|
|
row[1] = file.name;
|
|
|
|
row[2] = friendlyUnit(file.size, false);
|
|
|
|
row[3] = (file.progress * 100).round(1);
|
|
|
|
if (row[3] == 100.0 && file.progress < 1.0)
|
|
|
|
row[3] = 99.9
|
|
|
|
row[4] = file.priority;
|
|
|
|
fTable.insertRow(i, row);
|
|
|
|
i++;
|
|
|
|
}.bind(this));
|
|
|
|
// Set global CB state
|
|
|
|
if (allCBChecked()) {
|
|
|
|
setCBState("checked");
|
2014-12-08 23:00:00 +03:00
|
|
|
}
|
|
|
|
else {
|
2014-12-11 02:01:04 +03:00
|
|
|
if (allCBUnchecked()) {
|
|
|
|
setCBState("unchecked");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setCBState("partial");
|
|
|
|
}
|
2014-12-08 23:00:00 +03:00
|
|
|
}
|
|
|
|
}
|
2014-12-11 02:01:04 +03:00
|
|
|
else {
|
|
|
|
fTable.removeAllRows();
|
|
|
|
}
|
2014-12-11 23:22:23 +03:00
|
|
|
clearTimeout(loadTorrentFilesDataTimer);
|
2014-12-09 00:00:00 +03:00
|
|
|
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000);
|
2014-12-11 02:01:04 +03:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
2014-12-08 23:00:00 +03:00
|
|
|
|
2014-12-11 02:01:04 +03:00
|
|
|
var updateTorrentFilesData = function() {
|
|
|
|
clearTimeout(loadTorrentFilesDataTimer);
|
|
|
|
loadTorrentFilesData();
|
2014-12-08 23:00:00 +03:00
|
|
|
}
|
2014-12-11 02:01:04 +03:00
|
|
|
|
2014-12-08 23:00:00 +03:00
|
|
|
fTable = new filesDynTable();
|
|
|
|
fTable.setup($('filesTable'));
|