diff --git a/src/webui/www/public/scripts/client.js b/src/webui/www/public/scripts/client.js index 065b562e5..cdacceba6 100644 --- a/src/webui/www/public/scripts/client.js +++ b/src/webui/www/public/scripts/client.js @@ -24,9 +24,6 @@ myTable = new dynamicTable(); ajaxfn = function () {}; -setSortedColumn = function (index) { - myTable.setSortedColumn(index); -}; window.addEvent('load', function () { @@ -135,7 +132,9 @@ window.addEvent('load', function () { var ajaxfn = function () { var queueing_enabled = false; var url = new URI('json/torrents'); - url.setData({'filter': filter}); + url.setData('filter', filter); + url.setData('sort', myTable.table.sortedColumn); + url.setData('reverse', myTable.table.reverseSort); if (!waiting) { waiting = true; var request = new Request.JSON({ @@ -153,6 +152,7 @@ window.addEvent('load', function () { // Add new torrents or update them torrent_hashes = myTable.getRowIds(); events_hashes = new Array(); + pos = 0; events.each(function (event) { events_hashes[events_hashes.length] = event.hash; var row = new Array(); @@ -193,11 +193,13 @@ window.addEvent('load', function () { // New unfinished torrent torrent_hashes[torrent_hashes.length] = event.hash; //alert("Inserting row"); - myTable.insertRow(event.hash, row, data, event.state); + myTable.insertRow(event.hash, row, data, event.state, pos); } else { // Update torrent data - myTable.updateRow(event.hash, row, data, event.state); + myTable.updateRow(event.hash, row, data, event.state, pos); } + + pos++; }); // Remove deleted torrents torrent_hashes.each(function (hash) { @@ -212,6 +214,8 @@ window.addEvent('load', function () { $('queueingButtons').addClass('invisible'); myTable.hidePriority(); } + + myTable.altRow(); } waiting = false; ajaxfn.delay(1500); @@ -219,6 +223,13 @@ window.addEvent('load', function () { }).send(); } }; + + setSortedColumn = function (column) { + myTable.setSortedColumn(column); + // reload torrents + ajaxfn(); + }; + new MochaUI.Panel({ id : 'transferList', title : 'Panel', diff --git a/src/webui/www/public/scripts/dynamicTable.js b/src/webui/www/public/scripts/dynamicTable.js index caa06f433..4ae397fd2 100644 --- a/src/webui/www/public/scripts/dynamicTable.js +++ b/src/webui/www/public/scripts/dynamicTable.js @@ -42,51 +42,18 @@ var dynamicTable = new Class({ this.priority_hidden = false; this.progressIndex = progressIndex; this.context_menu = context_menu; - this.table.sortedIndex = 1; // Default is NAME + this.table.sortedColumn = 'name'; // Default is NAME this.table.reverseSort = false; }, - sortfunction : function (tr1, tr2) { - var i = tr2.getParent().sortedIndex; - var reverseSort = tr2.getParent().reverseSort; - 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; + setSortedColumn : function (column) { + if (column != this.table.sortedColumn) { + this.table.sortedColumn = column; this.table.reverseSort = false; } else { // Toggle sort order this.table.reverseSort = !this.table.reverseSort; } - this.updateSort(); - this.altRow(); }, getCurrentTorrentHash : function () { @@ -130,7 +97,7 @@ var dynamicTable = new Class({ this.priority_hidden = false; }, - insertRow : function (id, row, data, status) { + insertRow : function (id, row, data, status, pos) { if (this.rows.has(id)) { return; } @@ -254,17 +221,12 @@ var dynamicTable = new Class({ // Insert var trs = this.table.getChildren('tr'); - var i = 0; - while (i < trs.length && this.sortfunction(tr, trs[i]) > 0) { - i++; - } - if (i == trs.length) { + if (pos >= trs.length) { tr.inject(this.table); } else { - tr.inject(trs[i], 'before'); + tr.inject(trs[pos], 'before'); } //tr.injectInside(this.table); - this.altRow(); // Update context menu this.context_menu.addTarget(tr); }, @@ -279,10 +241,11 @@ var dynamicTable = new Class({ }, this); }, - updateRow : function (id, row, data, status) { + updateRow : function (id, row, data, status, newpos) { if (!this.rows.has(id)) { return false; } + var tr = this.rows.get(id); var tds = tr.getElements('td'); for (var i = 0; i < row.length; i++) { @@ -300,6 +263,18 @@ var dynamicTable = new Class({ if (typeof data[i] != 'undefined') 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; }, diff --git a/src/webui/www/public/transferlist.html b/src/webui/www/public/transferlist.html index fff6a57fc..8cfa98680 100644 --- a/src/webui/www/public/transferlist.html +++ b/src/webui/www/public/transferlist.html @@ -2,16 +2,16 @@ - _(Name) - # - _(Size) - _(Done) - _(Seeds) - _(Peers) - _(Down Speed) - _(Up Speed) - _(ETA) - _(Ratio) + _(Name) + # + _(Size) + _(Done) + _(Seeds) + _(Peers) + _(Down Speed) + _(Up Speed) + _(ETA) + _(Ratio)