|
|
@ -42,51 +42,18 @@ var dynamicTable = new Class({ |
|
|
|
this.priority_hidden = false; |
|
|
|
this.priority_hidden = false; |
|
|
|
this.progressIndex = progressIndex; |
|
|
|
this.progressIndex = progressIndex; |
|
|
|
this.context_menu = context_menu; |
|
|
|
this.context_menu = context_menu; |
|
|
|
this.table.sortedIndex = 1; // Default is NAME
|
|
|
|
this.table.sortedColumn = 'name'; // Default is NAME
|
|
|
|
this.table.reverseSort = false; |
|
|
|
this.table.reverseSort = false; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
sortfunction : function (tr1, tr2) { |
|
|
|
setSortedColumn : function (column) { |
|
|
|
var i = tr2.getParent().sortedIndex; |
|
|
|
if (column != this.table.sortedColumn) { |
|
|
|
var reverseSort = tr2.getParent().reverseSort; |
|
|
|
this.table.sortedColumn = column; |
|
|
|
switch (i) { |
|
|
|
|
|
|
|
case 1: // Name
|
|
|
|
|
|
|
|
if (!reverseSort) |
|
|
|
|
|
|
|
return tr1.getElements('td')[i].get('html').localeCompare(tr2.getElements('td')[i].get('html')); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return tr2.getElements('td')[i].get('html').localeCompare(tr1.getElements('td')[i].get('html')); |
|
|
|
|
|
|
|
case 2: // Prio
|
|
|
|
|
|
|
|
case 3: // Size
|
|
|
|
|
|
|
|
case 4: // Progress
|
|
|
|
|
|
|
|
case 5: // Seeds
|
|
|
|
|
|
|
|
case 6: // Peers
|
|
|
|
|
|
|
|
case 7: // Up Speed
|
|
|
|
|
|
|
|
case 8: // Down Speed
|
|
|
|
|
|
|
|
case 9: // ETA
|
|
|
|
|
|
|
|
default: // Ratio
|
|
|
|
|
|
|
|
if (!reverseSort) |
|
|
|
|
|
|
|
return (tr1.getElements('td')[i].get('data-raw') - tr2.getElements('td')[i].get('data-raw')); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return (tr2.getElements('td')[i].get('data-raw') - tr1.getElements('td')[i].get('data-raw')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateSort : function () { |
|
|
|
|
|
|
|
var trs = this.table.getChildren('tr'); |
|
|
|
|
|
|
|
trs.sort(this.sortfunction); |
|
|
|
|
|
|
|
this.table.adopt(trs); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setSortedColumn : function (index) { |
|
|
|
|
|
|
|
if (index != this.table.sortedIndex) { |
|
|
|
|
|
|
|
this.table.sortedIndex = index; |
|
|
|
|
|
|
|
this.table.reverseSort = false; |
|
|
|
this.table.reverseSort = false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Toggle sort order
|
|
|
|
// Toggle sort order
|
|
|
|
this.table.reverseSort = !this.table.reverseSort; |
|
|
|
this.table.reverseSort = !this.table.reverseSort; |
|
|
|
} |
|
|
|
} |
|
|
|
this.updateSort(); |
|
|
|
|
|
|
|
this.altRow(); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getCurrentTorrentHash : function () { |
|
|
|
getCurrentTorrentHash : function () { |
|
|
@ -130,7 +97,7 @@ var dynamicTable = new Class({ |
|
|
|
this.priority_hidden = false; |
|
|
|
this.priority_hidden = false; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
insertRow : function (id, row, data, status) { |
|
|
|
insertRow : function (id, row, data, status, pos) { |
|
|
|
if (this.rows.has(id)) { |
|
|
|
if (this.rows.has(id)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -254,17 +221,12 @@ var dynamicTable = new Class({ |
|
|
|
|
|
|
|
|
|
|
|
// Insert
|
|
|
|
// Insert
|
|
|
|
var trs = this.table.getChildren('tr'); |
|
|
|
var trs = this.table.getChildren('tr'); |
|
|
|
var i = 0; |
|
|
|
if (pos >= trs.length) { |
|
|
|
while (i < trs.length && this.sortfunction(tr, trs[i]) > 0) { |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (i == trs.length) { |
|
|
|
|
|
|
|
tr.inject(this.table); |
|
|
|
tr.inject(this.table); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
tr.inject(trs[i], 'before'); |
|
|
|
tr.inject(trs[pos], 'before'); |
|
|
|
} |
|
|
|
} |
|
|
|
//tr.injectInside(this.table);
|
|
|
|
//tr.injectInside(this.table);
|
|
|
|
this.altRow(); |
|
|
|
|
|
|
|
// Update context menu
|
|
|
|
// Update context menu
|
|
|
|
this.context_menu.addTarget(tr); |
|
|
|
this.context_menu.addTarget(tr); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -279,10 +241,11 @@ var dynamicTable = new Class({ |
|
|
|
}, this); |
|
|
|
}, this); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
updateRow : function (id, row, data, status) { |
|
|
|
updateRow : function (id, row, data, status, newpos) { |
|
|
|
if (!this.rows.has(id)) { |
|
|
|
if (!this.rows.has(id)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var tr = this.rows.get(id); |
|
|
|
var tr = this.rows.get(id); |
|
|
|
var tds = tr.getElements('td'); |
|
|
|
var tds = tr.getElements('td'); |
|
|
|
for (var i = 0; i < row.length; i++) { |
|
|
|
for (var i = 0; i < row.length; i++) { |
|
|
@ -300,6 +263,18 @@ var dynamicTable = new Class({ |
|
|
|
if (typeof data[i] != 'undefined') |
|
|
|
if (typeof data[i] != 'undefined') |
|
|
|
tds[i].set('data-raw', data[i]) |
|
|
|
tds[i].set('data-raw', data[i]) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Prevent freezing of the backlight.
|
|
|
|
|
|
|
|
tr.removeClass('over'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Move to 'newpos'
|
|
|
|
|
|
|
|
var trs = this.table.getChildren('tr'); |
|
|
|
|
|
|
|
if (newpos >= trs.length) { |
|
|
|
|
|
|
|
tr.inject(this.table); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
tr.inject(trs[newpos], 'before'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|