From 0488ddafa5559c0eb30507462a0be2accf26ee08 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sat, 22 Nov 2014 09:35:56 +0300 Subject: [PATCH] WebUI: Fix indentation. Fix indentation in client.js and dynamicTable.js. --- src/webui/www/public/scripts/client.js | 473 ++++++------ src/webui/www/public/scripts/dynamicTable.js | 715 ++++++++++--------- 2 files changed, 605 insertions(+), 583 deletions(-) diff --git a/src/webui/www/public/scripts/client.js b/src/webui/www/public/scripts/client.js index b69f979e1..f4feac3bc 100644 --- a/src/webui/www/public/scripts/client.js +++ b/src/webui/www/public/scripts/client.js @@ -23,252 +23,269 @@ */ myTable = new dynamicTable(); -ajaxfn = function(){}; -setSortedColumn = function(index){ - myTable.setSortedColumn(index); +ajaxfn = function () {}; +setSortedColumn = function (index) { + myTable.setSortedColumn(index); }; -window.addEvent('load', function(){ +window.addEvent('load', function () { - var saveColumnSizes = function() { - var filters_width = $('Filters').getSize().x; - var properties_height = $('propertiesPanel').getSize().y; - localStorage.setItem('filters_width', filters_width); - localStorage.setItem('properties_height', properties_height); - } + var saveColumnSizes = function () { + var filters_width = $('Filters').getSize().x; + var properties_height = $('propertiesPanel').getSize().y; + localStorage.setItem('filters_width', filters_width); + localStorage.setItem('properties_height', properties_height); + } - /*MochaUI.Desktop = new MochaUI.Desktop(); - MochaUI.Desktop.desktop.setStyles({ - 'background': '#fff', - 'visibility': 'visible' - });*/ - MochaUI.Desktop.initialize(); + /*MochaUI.Desktop = new MochaUI.Desktop(); + MochaUI.Desktop.desktop.setStyles({ + 'background': '#fff', + 'visibility': 'visible' + });*/ + MochaUI.Desktop.initialize(); - var filt_w = localStorage.getItem('filters_width'); - if($defined(filt_w)) - filt_w = filt_w.toInt(); - else - filt_w = 120; - new MochaUI.Column({ - id: 'filtersColumn', - placement: 'left', - onResize: saveColumnSizes, - width: filt_w, - resizeLimit: [100, 300] - }); - new MochaUI.Column({ - id: 'mainColumn', - placement: 'main', - width: null, - resizeLimit: [100, 300] - }); - MochaUI.Desktop.setDesktopSize(); - new MochaUI.Panel({ - id: 'Filters', - title: 'Panel', - header: false, - padding: { top: 0, right: 0, bottom: 0, left: 0 }, - loadMethod: 'xhr', - contentURL: 'filters.html', - column: 'filtersColumn', - height: 300 - }); - initializeWindows(); - var r=0; - var waiting=false; - var waitingTrInfo = false; + var filt_w = localStorage.getItem('filters_width'); + if ($defined(filt_w)) + filt_w = filt_w.toInt(); + else + filt_w = 120; + new MochaUI.Column({ + id : 'filtersColumn', + placement : 'left', + onResize : saveColumnSizes, + width : filt_w, + resizeLimit : [100, 300] + }); + new MochaUI.Column({ + id : 'mainColumn', + placement : 'main', + width : null, + resizeLimit : [100, 300] + }); + MochaUI.Desktop.setDesktopSize(); + new MochaUI.Panel({ + id : 'Filters', + title : 'Panel', + header : false, + padding : { + top : 0, + right : 0, + bottom : 0, + left : 0 + }, + loadMethod : 'xhr', + contentURL : 'filters.html', + column : 'filtersColumn', + height : 300 + }); + initializeWindows(); + var r = 0; + var waiting = false; + var waitingTrInfo = false; - var stateToImg = function(state){ - if(state == "pausedUP" || state == "pausedDL") { - state = "paused"; - } else { - if(state == "queuedUP" || state == "queuedDL") { - state = "queued"; - } else { - if(state == "checkingUP" || state == "checkingDL") { - state = "checking"; + var stateToImg = function (state) { + if (state == "pausedUP" || state == "pausedDL") { + state = "paused"; + } else { + if (state == "queuedUP" || state == "queuedDL") { + state = "queued"; + } else { + if (state == "checkingUP" || state == "checkingDL") { + state = "checking"; + } + } } - } - } - return 'images/skin/'+state+'.png'; - }; - var loadTransferInfo = function() { - var url = 'json/transferInfo'; - if(!waitingTrInfo) { - waitingTrInfo = true; - var request = new Request.JSON({ - url: url, - noCache: true, - method: 'get', - onFailure: function() { - $('error_div').set('html', '_(qBittorrent client is not reachable)'); - waitingTrInfo=false; - loadTransferInfo.delay(4000); + return 'images/skin/' + state + '.png'; + }; + var loadTransferInfo = function () { + var url = 'json/transferInfo'; + if (!waitingTrInfo) { + waitingTrInfo = true; + var request = new Request.JSON({ + url : url, + noCache : true, + method : 'get', + onFailure : function () { + $('error_div').set('html', '_(qBittorrent client is not reachable)'); + waitingTrInfo = false; + loadTransferInfo.delay(4000); }, - onSuccess: function(info) { - if(info) { - $("DlInfos").set('html', "_(D: %1 - T: %2)".replace("%1", friendlyUnit(info.dl_info_speed, true)) - .replace("%2", friendlyUnit(info.dl_info_data, false))); - $("UpInfos").set('html', "_(U: %1 - T: %2)".replace("%1", friendlyUnit(info.up_info_speed, true)) - .replace("%2", friendlyUnit(info.up_info_data, false))); - if(localStorage.getItem('speed_in_browser_title_bar') == 'true') - document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true)); - else - document.title = "_(qBittorrent web User Interface)"; - waitingTrInfo=false; - loadTransferInfo.delay(3000); - } + onSuccess : function (info) { + if (info) { + $("DlInfos").set('html', "_(D: %1 - T: %2)" + .replace("%1", friendlyUnit(info.dl_info_speed, true)) + .replace("%2", friendlyUnit(info.dl_info_data, false))); + $("UpInfos").set('html', "_(U: %1 - T: %2)" + .replace("%1", friendlyUnit(info.up_info_speed, true)) + .replace("%2", friendlyUnit(info.up_info_data, false))); + if(localStorage.getItem('speed_in_browser_title_bar') == 'true') + document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true)); + else + document.title = "_(qBittorrent web User Interface)"; + waitingTrInfo = false; + loadTransferInfo.delay(3000); + } } - }).send(); - } - }; - $('DlInfos').addEvent('click', globalDownloadLimitFN); - $('UpInfos').addEvent('click', globalUploadLimitFN); + }).send(); + } + }; + $('DlInfos').addEvent('click', globalDownloadLimitFN); + $('UpInfos').addEvent('click', globalUploadLimitFN); - var ajaxfn = function(){ - var queueing_enabled = false; - var url = 'json/torrents'; - if (!waiting){ - waiting=true; - var request = new Request.JSON({ - url: url, - noCache: true, - method: 'get', - onFailure: function() { - $('error_div').set('html', '_(qBittorrent client is not reachable)'); - waiting=false; - ajaxfn.delay(2000); - }, - onSuccess: function(events) { - $('error_div').set('html', ''); - if(events){ - // Add new torrents or update them - torrent_hashes = myTable.getRowIds(); - events_hashes = new Array(); - events.each(function(event){ - events_hashes[events_hashes.length] = event.hash; - var row = new Array(); - var data = new Array(); - row.length = 10; - row[0] = stateToImg(event.state); - row[1] = event.name; - row[2] = event.priority > -1 ? event.priority : null; - data[2] = event.priority; - row[3] = friendlyUnit(event.size, false); - data[3] = event.size; - row[4] = (event.progress*100).round(1); - if(row[4] == 100.0 && event.progress != 1.0) - row[4] = 99.9; - data[4] = event.progress; - row[5] = event.num_seeds; - if (event.num_complete != -1) - row[5] += " (" + event.num_complete + ")"; - data[5] = event.num_seeds; - row[6] = event.num_leechs; - if (event.num_incomplete != -1) - row[6] += " (" + event.num_incomplete + ")"; - data[6] = event.num_leechs; - row[7] = friendlyUnit(event.dlspeed, true); - data[7] = event.dlspeed; - row[8] = friendlyUnit(event.upspeed, true); - data[8] = event.upspeed; - row[9] = friendlyDuration(event.eta); - data[9] = event.eta - if(event.ratio == -1) - row[10] = "∞"; - else - row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up - data[10] = event.ratio; - if(row[2] != null) - queueing_enabled = true; - if(!torrent_hashes.contains(event.hash)) { - // New unfinished torrent - torrent_hashes[torrent_hashes.length] = event.hash; - //alert("Inserting row"); - myTable.insertRow(event.hash, row, data, event.state); - } else { - // Update torrent data - myTable.updateRow(event.hash, row, data, event.state); - } - }); - // Remove deleted torrents - torrent_hashes.each(function(hash){ - if(!events_hashes.contains(hash)) { - myTable.removeRow(hash); - } - }); - if(queueing_enabled) { - $('queueingButtons').removeClass('invisible'); - myTable.showPriority(); - } else { - $('queueingButtons').addClass('invisible'); - myTable.hidePriority(); - } - } - waiting=false; - ajaxfn.delay(1500); - } - }).send(); - } - }; - new MochaUI.Panel({ - id: 'transferList', - title: 'Panel', - header: false, - padding: { top: 0, right: 0, bottom: 0, left: 0 }, - loadMethod: 'xhr', - contentURL: 'transferlist.html', - onContentLoaded: function() { - ajaxfn(); - }, - column: 'mainColumn', - onResize: saveColumnSizes, - height: null - }); + var ajaxfn = function () { + var queueing_enabled = false; + var url = 'json/torrents'; + if (!waiting) { + waiting = true; + var request = new Request.JSON({ + url : url, + noCache : true, + method : 'get', + onFailure : function () { + $('error_div').set('html', '_(qBittorrent client is not reachable)'); + waiting = false; + ajaxfn.delay(2000); + }, + onSuccess : function (events) { + $('error_div').set('html', ''); + if (events) { + // Add new torrents or update them + torrent_hashes = myTable.getRowIds(); + events_hashes = new Array(); + events.each(function (event) { + events_hashes[events_hashes.length] = event.hash; + var row = new Array(); + var data = new Array(); + row.length = 10; + row[0] = stateToImg(event.state); + row[1] = event.name; + row[2] = event.priority > -1 ? event.priority : null; + data[2] = event.priority; + row[3] = friendlyUnit(event.size, false); + data[3] = event.size; + row[4] = (event.progress * 100).round(1); + if (row[4] == 100.0 && event.progress != 1.0) + row[4] = 99.9; + data[4] = event.progress; + row[5] = event.num_seeds; + if (event.num_complete != -1) + row[5] += " (" + event.num_complete + ")"; + data[5] = event.num_seeds; + row[6] = event.num_leechs; + if (event.num_incomplete != -1) + row[6] += " (" + event.num_incomplete + ")"; + data[6] = event.num_leechs; + row[7] = friendlyUnit(event.dlspeed, true); + data[7] = event.dlspeed; + row[8] = friendlyUnit(event.upspeed, true); + data[8] = event.upspeed; + row[9] = friendlyDuration(event.eta); + data[9] = event.eta; + if (event.ratio == -1) + row[10] = "∞"; + else + row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up + data[10] = event.ratio; + if (row[2] != null) + queueing_enabled = true; + if (!torrent_hashes.contains(event.hash)) { + // New unfinished torrent + torrent_hashes[torrent_hashes.length] = event.hash; + //alert("Inserting row"); + myTable.insertRow(event.hash, row, data, event.state); + } else { + // Update torrent data + myTable.updateRow(event.hash, row, data, event.state); + } + }); + // Remove deleted torrents + torrent_hashes.each(function (hash) { + if (!events_hashes.contains(hash)) { + myTable.removeRow(hash); + } + }); + if (queueing_enabled) { + $('queueingButtons').removeClass('invisible'); + myTable.showPriority(); + } else { + $('queueingButtons').addClass('invisible'); + myTable.hidePriority(); + } + } + waiting = false; + ajaxfn.delay(1500); + } + }).send(); + } + }; + new MochaUI.Panel({ + id : 'transferList', + title : 'Panel', + header : false, + padding : { + top : 0, + right : 0, + bottom : 0, + left : 0 + }, + loadMethod : 'xhr', + contentURL : 'transferlist.html', + onContentLoaded : function () { + ajaxfn(); + }, + column : 'mainColumn', + onResize : saveColumnSizes, + height : null + }); var prop_h = localStorage.getItem('properties_height'); - if($defined(prop_h)) - prop_h = prop_h.toInt(); + if ($defined(prop_h)) + prop_h = prop_h.toInt(); else - prop_h = Window.getSize().y / 2.; + prop_h = Window.getSize().y / 2.; new MochaUI.Panel({ - id: 'propertiesPanel', - title: 'Panel', - header: true, - padding: { top: 0, right: 0, bottom: 0, left: 0 }, - contentURL: 'prop-general.html', - require: { - css: ['css/Tabs.css'] - }, - tabsURL: 'properties.html', - column: 'mainColumn', - height: prop_h - }); - //ajaxfn(); - loadTransferInfo(); + id : 'propertiesPanel', + title : 'Panel', + header : true, + padding : { + top : 0, + right : 0, + bottom : 0, + left : 0 + }, + contentURL : 'prop-general.html', + require : { + css : ['css/Tabs.css'] + }, + tabsURL : 'properties.html', + column : 'mainColumn', + height : prop_h + }); + //ajaxfn(); + loadTransferInfo(); - setFilter = function(f) { - // Visually Select the right filter - $("all_filter").removeClass("selectedFilter"); - $("downloading_filter").removeClass("selectedFilter"); - $("completed_filter").removeClass("selectedFilter"); - $("paused_filter").removeClass("selectedFilter"); - $("active_filter").removeClass("selectedFilter"); - $("inactive_filter").removeClass("selectedFilter"); - $(f+"_filter").addClass("selectedFilter"); - myTable.setFilter(f); - ajaxfn(); - localStorage.setItem('selected_filter', f); - } + setFilter = function (f) { + // Visually Select the right filter + $("all_filter").removeClass("selectedFilter"); + $("downloading_filter").removeClass("selectedFilter"); + $("completed_filter").removeClass("selectedFilter"); + $("paused_filter").removeClass("selectedFilter"); + $("active_filter").removeClass("selectedFilter"); + $("inactive_filter").removeClass("selectedFilter"); + $(f + "_filter").addClass("selectedFilter"); + myTable.setFilter(f); + ajaxfn(); + localStorage.setItem('selected_filter', f); + } }); function closeWindows() { - MochaUI.closeAll(); + MochaUI.closeAll(); } -window.addEvent('keydown', function(event){ - if (event.key == 'a' && event.control) { - event.stop(); - myTable.selectAll(); - } +window.addEvent('keydown', function (event) { + if (event.key == 'a' && event.control) { + event.stop(); + myTable.selectAll(); + } }); diff --git a/src/webui/www/public/scripts/dynamicTable.js b/src/webui/www/public/scripts/dynamicTable.js index 7792c9958..32d9a2027 100644 --- a/src/webui/www/public/scripts/dynamicTable.js +++ b/src/webui/www/public/scripts/dynamicTable.js @@ -8,10 +8,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,372 +23,377 @@ /************************************************************** - Script : Dynamic Table - Version : 0.5 - Authors : Ishan Arora & Christophe Dumez - Desc : Programable sortable table - Licence : Open Source MIT Licence + Script : Dynamic Table + Version : 0.5 + Authors : Ishan Arora & Christophe Dumez + Desc : Programable sortable table + Licence : Open Source MIT Licence -**************************************************************/ + **************************************************************/ -var dynamicTable = new Class ({ +var dynamicTable = new Class({ - initialize: function(){ - }, - - setup: function(table, progressIndex, context_menu){ - this.table = $(table); - this.rows = new Hash(); - this.cur = new Array(); - this.priority_hidden = false; - this.progressIndex = progressIndex; - this.filter = localStorage.getItem('selected_filter'); - if(!$defined(this.filter)) { - this.filter = 'all'; - } - this.context_menu = context_menu; - this.table.sortedIndex = 1; // 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; - this.table.reverseSort = false; - } else { - // Toggle sort order - this.table.reverseSort = !this.table.reverseSort; - } - this.updateSort(); - this.altRow(); - }, - - getCurrentTorrentHash: function() { - if(this.cur.length > 0) - return this.cur[0]; - return ''; - }, + initialize : function () {}, - altRow: function() - { - var trs = this.table.getElements('tr'); - trs.each(function(el,i){ - if(i % 2){ - el.addClass('alt'); - }else{ - el.removeClass('alt'); - } - }.bind(this)); - }, + setup : function (table, progressIndex, context_menu) { + this.table = $(table); + this.rows = new Hash(); + this.cur = new Array(); + this.priority_hidden = false; + this.progressIndex = progressIndex; + this.filter = localStorage.getItem('selected_filter'); + if (!$defined(this.filter)) { + this.filter = 'all'; + } + this.context_menu = context_menu; + this.table.sortedIndex = 1; // Default is NAME + this.table.reverseSort = false; + }, - hidePriority: function(){ - if(this.priority_hidden) return; - $('prioHeader').addClass('invisible'); - var trs = this.table.getElements('tr'); - trs.each(function(tr,i){ - var tds = tr.getElements('td'); - tds[2].addClass('invisible'); - }.bind(this)); - this.priority_hidden = true; - }, - - setFilter: function(f) { - this.filter = f; - }, + 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; + this.table.reverseSort = false; + } else { + // Toggle sort order + this.table.reverseSort = !this.table.reverseSort; + } + this.updateSort(); + this.altRow(); + }, + + getCurrentTorrentHash : function () { + if (this.cur.length > 0) + return this.cur[0]; + return ''; + }, + + altRow : function () { + var trs = this.table.getElements('tr'); + trs.each(function (el, i) { + if (i % 2) { + el.addClass('alt'); + } else { + el.removeClass('alt'); + } + }.bind(this)); + }, + + hidePriority : function () { + if (this.priority_hidden) + return; + $('prioHeader').addClass('invisible'); + var trs = this.table.getElements('tr'); + trs.each(function (tr, i) { + var tds = tr.getElements('td'); + tds[2].addClass('invisible'); + }.bind(this)); + this.priority_hidden = true; + }, - showPriority: function(){ - if(!this.priority_hidden) return; - $('prioHeader').removeClass('invisible'); - var trs = this.table.getElements('tr'); - trs.each(function(tr,i){ - var tds = tr.getElements('td'); - tds[2].removeClass('invisible'); + setFilter : function (f) { + this.filter = f; + }, + + showPriority : function () { + if (!this.priority_hidden) + return; + $('prioHeader').removeClass('invisible'); + var trs = this.table.getElements('tr'); + trs.each(function (tr, i) { + var tds = tr.getElements('td'); + tds[2].removeClass('invisible'); + }.bind(this)); + this.priority_hidden = false; + }, + + applyFilterOnRow : function (tr, status) { + switch (this.filter) { + case 'all': + tr.removeClass("invisible"); + break; + case 'downloading': + if (status == "downloading" || status == "stalledDL" || status == "checkingDL" || status == "pausedDL" || status == "queuedDL") { + tr.removeClass("invisible"); + } else { + tr.addClass("invisible"); + } + break; + case 'completed': + if (status == "uploading" || status == "stalledUP" || status == "checkingUP" || status == "pausedUP" || status == "queuedUP") { + tr.removeClass("invisible"); + } else { + tr.addClass("invisible"); + } + break; + case 'paused': + if (status == "pausedDL" || status == "pausedUP") { + tr.removeClass("invisible"); + } else { + tr.addClass("invisible"); + } + break; + case 'active': + if (status == "downloading" || status == "uploading") { + tr.removeClass("invisible"); + } else { + tr.addClass("invisible"); + } + break; + case 'inactive': + if (status != "downloading" && status != "uploading") { + tr.removeClass("invisible"); + } else { + tr.addClass("invisible"); + } + } + return !tr.hasClass('invisible'); + }, + + insertRow : function (id, row, data, status) { + if (this.rows.has(id)) { + return; + } + var tr = new Element('tr'); + tr.addClass("menu-target"); + this.rows.set(id, tr); + for (var i = 0; i < row.length; i++) { + var td = new Element('td'); + if (i == this.progressIndex) { + td.adopt(new ProgressBar(row[i].toFloat(), { + 'id' : 'pb_' + id, + 'width' : 80 + })); + if (typeof data[i] != 'undefined') + td.set('data-raw', data[i]) + } else { + if (i == 0) { + td.adopt(new Element('img', { + 'src' : row[i], + 'class' : 'statusIcon' + })); + } else { + if (i == 2) { + // Priority + if (this.priority_hidden) + td.addClass('invisible'); + } + td.set('html', row[i]); + if (typeof data[i] != 'undefined') + td.set('data-raw', data[i]) + } + } + td.injectInside(tr); + }; + + tr.addEvent('mouseover', function (e) { + tr.addClass('over'); + }.bind(this)); + tr.addEvent('mouseout', function (e) { + tr.removeClass('over'); + }.bind(this)); + tr.addEvent('contextmenu', function (e) { + if (!this.cur.contains(id)) { + // Remove selected style from previous ones + for (i = 0; i < this.cur.length; i++) { + if (this.rows.has(this.cur[i])) { + var temptr = this.rows.get(this.cur[i]); + temptr.removeClass('selected'); + } + } + this.cur.empty(); + this.cur[this.cur.length] = id; + temptr = this.rows.get(id); + temptr.addClass("selected"); + } + return true; + }.bind(this)); + tr.addEvent('click', function (e) { + e.stop(); + if (e.control) { + // CTRL key was pressed + if (this.cur.contains(id)) { + // remove it + this.cur.erase(id); + // Remove selected style + if (this.rows.has(id)) { + temptr = this.rows.get(id); + temptr.removeClass('selected'); + } + } else { + this.cur[this.cur.length] = id; + // Add selected style + if (this.rows.has(id)) { + temptr = this.rows.get(id); + temptr.addClass('selected'); + } + } + } else { + if (e.shift && this.cur.length == 1) { + // Shift key was pressed + var first_id = this.cur[0]; + var first_tr = this.rows.get(first_id); + var last_id = id; + var last_tr = this.rows.get(last_id); + var all_trs = this.table.getChildren('tr'); + var index_first_tr = all_trs.indexOf(first_tr); + var index_last_tr = all_trs.indexOf(last_tr); + var trs_to_select = all_trs.filter(function (item, index) { + if (index_first_tr < index_last_tr) + return (index > index_first_tr) && (index <= index_last_tr); + else + return (index < index_first_tr) && (index >= index_last_tr); + }); + trs_to_select.each(function (item, index) { + // Add to selection + this.cur[this.cur.length] = this.getRowId(item); + // Select it visually + item.addClass('selected'); }.bind(this)); - this.priority_hidden = false; + } else { + // Simple selection + // Remove selected style from previous ones + for (i = 0; i < this.cur.length; i++) { + if (this.rows.has(this.cur[i])) { + var temptr = this.rows.get(this.cur[i]); + temptr.removeClass('selected'); + } + } + this.cur.empty(); + // Add selected style to new one + if (this.rows.has(id)) { + temptr = this.rows.get(id); + temptr.addClass('selected'); + } + this.cur[0] = id; + // TODO: Warn Properties panel + } + } + return false; + }.bind(this)); + // Apply filter + this.applyFilterOnRow(tr, status); + // 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) { + tr.inject(this.table); + } else { + tr.inject(trs[i], 'before'); + } + //tr.injectInside(this.table); + this.altRow(); + // Update context menu + this.context_menu.addTarget(tr); }, - - applyFilterOnRow: function(tr, status) { - switch(this.filter) { - case 'all': - tr.removeClass("invisible"); - break; - case 'downloading': - if(status == "downloading" || status == "stalledDL" || status == "checkingDL" || status == "pausedDL" || status == "queuedDL") { - tr.removeClass("invisible"); - } else { - tr.addClass("invisible"); - } - break; - case 'completed': - if(status == "uploading" || status == "stalledUP" || status == "checkingUP" || status == "pausedUP" || status == "queuedUP") { - tr.removeClass("invisible"); - } else { - tr.addClass("invisible"); - } - break; - case 'paused': - if(status == "pausedDL" || status == "pausedUP") { - tr.removeClass("invisible"); - } else { - tr.addClass("invisible"); - } - break; - case 'active': - if(status == "downloading" || status == "uploading") { - tr.removeClass("invisible"); - } else { - tr.addClass("invisible"); - } - break; - case 'inactive': - if(status != "downloading" && status != "uploading") { - tr.removeClass("invisible"); - } else { - tr.addClass("invisible"); - } - } - return !tr.hasClass('invisible'); - }, - insertRow: function(id, row, data, status){ - if(this.rows.has(id)) { - return; - } - var tr = new Element('tr'); - tr.addClass("menu-target"); - this.rows.set(id, tr); - for(var i=0; i index_first_tr) && (index <= index_last_tr); - else - return (index < index_first_tr) && (index >= index_last_tr); - }); - trs_to_select.each(function(item, index){ - // Add to selection - this.cur[this.cur.length] = this.getRowId(item); - // Select it visually - item.addClass('selected'); - }.bind(this)); - } else { - // Simple selection - // Remove selected style from previous ones - for(i=0; i 0) { - i++; - } - if(i==trs.length) { - tr.inject(this.table); - } else { - tr.inject(trs[i], 'before'); - } - //tr.injectInside(this.table); - this.altRow(); - // Update context menu - this.context_menu.addTarget(tr); - }, - - selectAll: function() { - this.cur.empty(); - this.rows.each(function(tr, id){ - this.cur[this.cur.length] = id; - if(!tr.hasClass('selected')) { - tr.addClass('selected'); - } - }, this); - }, + removeRow : function (id) { + if (this.cur.contains(id)) { + this.cur.erase(id); + } + if (this.rows.has(id)) { + var tr = this.rows.get(id); + tr.dispose(); + this.altRow(); + this.rows.erase(id); + return true; + } + return false; + }, - updateRow: function(id, row, data, status){ - if(!this.rows.has(id)) { - return false; - } - var tr = this.rows.get(id); - // Apply filter - if(this.applyFilterOnRow(tr, status)) { - var tds = tr.getElements('td'); - for(var i=0; i