Browse Source

WebUI: Fix indentation.

Fix indentation in client.js and dynamicTable.js.
adaptive-webui-19844
Vladimir Golovnev (Glassez) 10 years ago
parent
commit
0488ddafa5
  1. 473
      src/webui/www/public/scripts/client.js
  2. 715
      src/webui/www/public/scripts/dynamicTable.js

473
src/webui/www/public/scripts/client.js

@ -23,252 +23,269 @@
*/ */
myTable = new dynamicTable(); myTable = new dynamicTable();
ajaxfn = function(){}; ajaxfn = function () {};
setSortedColumn = function(index){ setSortedColumn = function (index) {
myTable.setSortedColumn(index); myTable.setSortedColumn(index);
}; };
window.addEvent('load', function(){ window.addEvent('load', function () {
var saveColumnSizes = function() { var saveColumnSizes = function () {
var filters_width = $('Filters').getSize().x; var filters_width = $('Filters').getSize().x;
var properties_height = $('propertiesPanel').getSize().y; var properties_height = $('propertiesPanel').getSize().y;
localStorage.setItem('filters_width', filters_width); localStorage.setItem('filters_width', filters_width);
localStorage.setItem('properties_height', properties_height); localStorage.setItem('properties_height', properties_height);
} }
/*MochaUI.Desktop = new MochaUI.Desktop(); /*MochaUI.Desktop = new MochaUI.Desktop();
MochaUI.Desktop.desktop.setStyles({ MochaUI.Desktop.desktop.setStyles({
'background': '#fff', 'background': '#fff',
'visibility': 'visible' 'visibility': 'visible'
});*/ });*/
MochaUI.Desktop.initialize(); MochaUI.Desktop.initialize();
var filt_w = localStorage.getItem('filters_width'); var filt_w = localStorage.getItem('filters_width');
if($defined(filt_w)) if ($defined(filt_w))
filt_w = filt_w.toInt(); filt_w = filt_w.toInt();
else else
filt_w = 120; filt_w = 120;
new MochaUI.Column({ new MochaUI.Column({
id: 'filtersColumn', id : 'filtersColumn',
placement: 'left', placement : 'left',
onResize: saveColumnSizes, onResize : saveColumnSizes,
width: filt_w, width : filt_w,
resizeLimit: [100, 300] resizeLimit : [100, 300]
}); });
new MochaUI.Column({ new MochaUI.Column({
id: 'mainColumn', id : 'mainColumn',
placement: 'main', placement : 'main',
width: null, width : null,
resizeLimit: [100, 300] resizeLimit : [100, 300]
}); });
MochaUI.Desktop.setDesktopSize(); MochaUI.Desktop.setDesktopSize();
new MochaUI.Panel({ new MochaUI.Panel({
id: 'Filters', id : 'Filters',
title: 'Panel', title : 'Panel',
header: false, header : false,
padding: { top: 0, right: 0, bottom: 0, left: 0 }, padding : {
loadMethod: 'xhr', top : 0,
contentURL: 'filters.html', right : 0,
column: 'filtersColumn', bottom : 0,
height: 300 left : 0
}); },
initializeWindows(); loadMethod : 'xhr',
var r=0; contentURL : 'filters.html',
var waiting=false; column : 'filtersColumn',
var waitingTrInfo = false; height : 300
});
initializeWindows();
var r = 0;
var waiting = false;
var waitingTrInfo = false;
var stateToImg = function(state){ var stateToImg = function (state) {
if(state == "pausedUP" || state == "pausedDL") { if (state == "pausedUP" || state == "pausedDL") {
state = "paused"; state = "paused";
} else { } else {
if(state == "queuedUP" || state == "queuedDL") { if (state == "queuedUP" || state == "queuedDL") {
state = "queued"; state = "queued";
} else { } else {
if(state == "checkingUP" || state == "checkingDL") { if (state == "checkingUP" || state == "checkingDL") {
state = "checking"; state = "checking";
}
}
} }
} return 'images/skin/' + state + '.png';
} };
return 'images/skin/'+state+'.png'; var loadTransferInfo = function () {
}; var url = 'json/transferInfo';
var loadTransferInfo = function() { if (!waitingTrInfo) {
var url = 'json/transferInfo'; waitingTrInfo = true;
if(!waitingTrInfo) { var request = new Request.JSON({
waitingTrInfo = true; url : url,
var request = new Request.JSON({ noCache : true,
url: url, method : 'get',
noCache: true, onFailure : function () {
method: 'get', $('error_div').set('html', '_(qBittorrent client is not reachable)');
onFailure: function() { waitingTrInfo = false;
$('error_div').set('html', '_(qBittorrent client is not reachable)'); loadTransferInfo.delay(4000);
waitingTrInfo=false;
loadTransferInfo.delay(4000);
}, },
onSuccess: function(info) { onSuccess : function (info) {
if(info) { if (info) {
$("DlInfos").set('html', "_(D: %1 - T: %2)".replace("%1", friendlyUnit(info.dl_info_speed, true)) $("DlInfos").set('html', "_(D: %1 - T: %2)"
.replace("%2", friendlyUnit(info.dl_info_data, false))); .replace("%1", friendlyUnit(info.dl_info_speed, true))
$("UpInfos").set('html', "_(U: %1 - T: %2)".replace("%1", friendlyUnit(info.up_info_speed, true)) .replace("%2", friendlyUnit(info.dl_info_data, false)));
.replace("%2", friendlyUnit(info.up_info_data, false))); $("UpInfos").set('html', "_(U: %1 - T: %2)"
if(localStorage.getItem('speed_in_browser_title_bar') == 'true') .replace("%1", friendlyUnit(info.up_info_speed, true))
document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true)); .replace("%2", friendlyUnit(info.up_info_data, false)));
else if(localStorage.getItem('speed_in_browser_title_bar') == 'true')
document.title = "_(qBittorrent web User Interface)"; document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true));
waitingTrInfo=false; else
loadTransferInfo.delay(3000); document.title = "_(qBittorrent web User Interface)";
} waitingTrInfo = false;
loadTransferInfo.delay(3000);
}
} }
}).send(); }).send();
} }
}; };
$('DlInfos').addEvent('click', globalDownloadLimitFN); $('DlInfos').addEvent('click', globalDownloadLimitFN);
$('UpInfos').addEvent('click', globalUploadLimitFN); $('UpInfos').addEvent('click', globalUploadLimitFN);
var ajaxfn = function(){ var ajaxfn = function () {
var queueing_enabled = false; var queueing_enabled = false;
var url = 'json/torrents'; var url = 'json/torrents';
if (!waiting){ if (!waiting) {
waiting=true; waiting = true;
var request = new Request.JSON({ var request = new Request.JSON({
url: url, url : url,
noCache: true, noCache : true,
method: 'get', method : 'get',
onFailure: function() { onFailure : function () {
$('error_div').set('html', '_(qBittorrent client is not reachable)'); $('error_div').set('html', '_(qBittorrent client is not reachable)');
waiting=false; waiting = false;
ajaxfn.delay(2000); ajaxfn.delay(2000);
}, },
onSuccess: function(events) { onSuccess : function (events) {
$('error_div').set('html', ''); $('error_div').set('html', '');
if(events){ if (events) {
// Add new torrents or update them // Add new torrents or update them
torrent_hashes = myTable.getRowIds(); torrent_hashes = myTable.getRowIds();
events_hashes = new Array(); events_hashes = new Array();
events.each(function(event){ events.each(function (event) {
events_hashes[events_hashes.length] = event.hash; events_hashes[events_hashes.length] = event.hash;
var row = new Array(); var row = new Array();
var data = new Array(); var data = new Array();
row.length = 10; row.length = 10;
row[0] = stateToImg(event.state); row[0] = stateToImg(event.state);
row[1] = event.name; row[1] = event.name;
row[2] = event.priority > -1 ? event.priority : null; row[2] = event.priority > -1 ? event.priority : null;
data[2] = event.priority; data[2] = event.priority;
row[3] = friendlyUnit(event.size, false); row[3] = friendlyUnit(event.size, false);
data[3] = event.size; data[3] = event.size;
row[4] = (event.progress*100).round(1); row[4] = (event.progress * 100).round(1);
if(row[4] == 100.0 && event.progress != 1.0) if (row[4] == 100.0 && event.progress != 1.0)
row[4] = 99.9; row[4] = 99.9;
data[4] = event.progress; data[4] = event.progress;
row[5] = event.num_seeds; row[5] = event.num_seeds;
if (event.num_complete != -1) if (event.num_complete != -1)
row[5] += " (" + event.num_complete + ")"; row[5] += " (" + event.num_complete + ")";
data[5] = event.num_seeds; data[5] = event.num_seeds;
row[6] = event.num_leechs; row[6] = event.num_leechs;
if (event.num_incomplete != -1) if (event.num_incomplete != -1)
row[6] += " (" + event.num_incomplete + ")"; row[6] += " (" + event.num_incomplete + ")";
data[6] = event.num_leechs; data[6] = event.num_leechs;
row[7] = friendlyUnit(event.dlspeed, true); row[7] = friendlyUnit(event.dlspeed, true);
data[7] = event.dlspeed; data[7] = event.dlspeed;
row[8] = friendlyUnit(event.upspeed, true); row[8] = friendlyUnit(event.upspeed, true);
data[8] = event.upspeed; data[8] = event.upspeed;
row[9] = friendlyDuration(event.eta); row[9] = friendlyDuration(event.eta);
data[9] = event.eta data[9] = event.eta;
if(event.ratio == -1) if (event.ratio == -1)
row[10] = "∞"; row[10] = "∞";
else else
row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up row[10] = (Math.floor(100 * event.ratio) / 100).toFixed(2); //Don't round up
data[10] = event.ratio; data[10] = event.ratio;
if(row[2] != null) if (row[2] != null)
queueing_enabled = true; queueing_enabled = true;
if(!torrent_hashes.contains(event.hash)) { if (!torrent_hashes.contains(event.hash)) {
// New unfinished torrent // New unfinished torrent
torrent_hashes[torrent_hashes.length] = event.hash; torrent_hashes[torrent_hashes.length] = event.hash;
//alert("Inserting row"); //alert("Inserting row");
myTable.insertRow(event.hash, row, data, event.state); myTable.insertRow(event.hash, row, data, event.state);
} else { } else {
// Update torrent data // Update torrent data
myTable.updateRow(event.hash, row, data, event.state); myTable.updateRow(event.hash, row, data, event.state);
} }
}); });
// Remove deleted torrents // Remove deleted torrents
torrent_hashes.each(function(hash){ torrent_hashes.each(function (hash) {
if(!events_hashes.contains(hash)) { if (!events_hashes.contains(hash)) {
myTable.removeRow(hash); myTable.removeRow(hash);
} }
}); });
if(queueing_enabled) { if (queueing_enabled) {
$('queueingButtons').removeClass('invisible'); $('queueingButtons').removeClass('invisible');
myTable.showPriority(); myTable.showPriority();
} else { } else {
$('queueingButtons').addClass('invisible'); $('queueingButtons').addClass('invisible');
myTable.hidePriority(); myTable.hidePriority();
} }
} }
waiting=false; waiting = false;
ajaxfn.delay(1500); ajaxfn.delay(1500);
} }
}).send(); }).send();
} }
}; };
new MochaUI.Panel({ new MochaUI.Panel({
id: 'transferList', id : 'transferList',
title: 'Panel', title : 'Panel',
header: false, header : false,
padding: { top: 0, right: 0, bottom: 0, left: 0 }, padding : {
loadMethod: 'xhr', top : 0,
contentURL: 'transferlist.html', right : 0,
onContentLoaded: function() { bottom : 0,
ajaxfn(); left : 0
}, },
column: 'mainColumn', loadMethod : 'xhr',
onResize: saveColumnSizes, contentURL : 'transferlist.html',
height: null onContentLoaded : function () {
}); ajaxfn();
},
column : 'mainColumn',
onResize : saveColumnSizes,
height : null
});
var prop_h = localStorage.getItem('properties_height'); var prop_h = localStorage.getItem('properties_height');
if($defined(prop_h)) if ($defined(prop_h))
prop_h = prop_h.toInt(); prop_h = prop_h.toInt();
else else
prop_h = Window.getSize().y / 2.; prop_h = Window.getSize().y / 2.;
new MochaUI.Panel({ new MochaUI.Panel({
id: 'propertiesPanel', id : 'propertiesPanel',
title: 'Panel', title : 'Panel',
header: true, header : true,
padding: { top: 0, right: 0, bottom: 0, left: 0 }, padding : {
contentURL: 'prop-general.html', top : 0,
require: { right : 0,
css: ['css/Tabs.css'] bottom : 0,
}, left : 0
tabsURL: 'properties.html', },
column: 'mainColumn', contentURL : 'prop-general.html',
height: prop_h require : {
}); css : ['css/Tabs.css']
//ajaxfn(); },
loadTransferInfo(); tabsURL : 'properties.html',
column : 'mainColumn',
height : prop_h
});
//ajaxfn();
loadTransferInfo();
setFilter = function(f) { setFilter = function (f) {
// Visually Select the right filter // Visually Select the right filter
$("all_filter").removeClass("selectedFilter"); $("all_filter").removeClass("selectedFilter");
$("downloading_filter").removeClass("selectedFilter"); $("downloading_filter").removeClass("selectedFilter");
$("completed_filter").removeClass("selectedFilter"); $("completed_filter").removeClass("selectedFilter");
$("paused_filter").removeClass("selectedFilter"); $("paused_filter").removeClass("selectedFilter");
$("active_filter").removeClass("selectedFilter"); $("active_filter").removeClass("selectedFilter");
$("inactive_filter").removeClass("selectedFilter"); $("inactive_filter").removeClass("selectedFilter");
$(f+"_filter").addClass("selectedFilter"); $(f + "_filter").addClass("selectedFilter");
myTable.setFilter(f); myTable.setFilter(f);
ajaxfn(); ajaxfn();
localStorage.setItem('selected_filter', f); localStorage.setItem('selected_filter', f);
} }
}); });
function closeWindows() { function closeWindows() {
MochaUI.closeAll(); MochaUI.closeAll();
} }
window.addEvent('keydown', function(event){ window.addEvent('keydown', function (event) {
if (event.key == 'a' && event.control) { if (event.key == 'a' && event.control) {
event.stop(); event.stop();
myTable.selectAll(); myTable.selectAll();
} }
}); });

715
src/webui/www/public/scripts/dynamicTable.js

@ -8,10 +8,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -23,372 +23,377 @@
/************************************************************** /**************************************************************
Script : Dynamic Table Script : Dynamic Table
Version : 0.5 Version : 0.5
Authors : Ishan Arora & Christophe Dumez Authors : Ishan Arora & Christophe Dumez
Desc : Programable sortable table Desc : Programable sortable table
Licence : Open Source MIT Licence Licence : Open Source MIT Licence
**************************************************************/ **************************************************************/
var dynamicTable = new Class ({ var dynamicTable = new Class({
initialize: function(){ 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 '';
},
altRow: function() setup : function (table, progressIndex, context_menu) {
{ this.table = $(table);
var trs = this.table.getElements('tr'); this.rows = new Hash();
trs.each(function(el,i){ this.cur = new Array();
if(i % 2){ this.priority_hidden = false;
el.addClass('alt'); this.progressIndex = progressIndex;
}else{ this.filter = localStorage.getItem('selected_filter');
el.removeClass('alt'); if (!$defined(this.filter)) {
} this.filter = 'all';
}.bind(this)); }
}, this.context_menu = context_menu;
this.table.sortedIndex = 1; // Default is NAME
this.table.reverseSort = false;
},
hidePriority: function(){ sortfunction : function (tr1, tr2) {
if(this.priority_hidden) return; var i = tr2.getParent().sortedIndex;
$('prioHeader').addClass('invisible'); var reverseSort = tr2.getParent().reverseSort;
var trs = this.table.getElements('tr'); switch (i) {
trs.each(function(tr,i){ case 1: // Name
var tds = tr.getElements('td'); if (!reverseSort)
tds[2].addClass('invisible'); return tr1.getElements('td')[i].get('html').localeCompare(tr2.getElements('td')[i].get('html'));
}.bind(this)); else
this.priority_hidden = true; return tr2.getElements('td')[i].get('html').localeCompare(tr1.getElements('td')[i].get('html'));
}, case 2: // Prio
case 3: // Size
setFilter: function(f) { case 4: // Progress
this.filter = f; 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(){ setFilter : function (f) {
if(!this.priority_hidden) return; this.filter = f;
$('prioHeader').removeClass('invisible'); },
var trs = this.table.getElements('tr');
trs.each(function(tr,i){ showPriority : function () {
var tds = tr.getElements('td'); if (!this.priority_hidden)
tds[2].removeClass('invisible'); 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)); }.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){ selectAll : function () {
if(this.rows.has(id)) { this.cur.empty();
return; this.rows.each(function (tr, id) {
} this.cur[this.cur.length] = id;
var tr = new Element('tr'); if (!tr.hasClass('selected')) {
tr.addClass("menu-target"); tr.addClass('selected');
this.rows.set(id, tr); }
for(var i=0; i<row.length; i++) }, this);
{ },
var td = new Element('td');
if(i==this.progressIndex) { updateRow : function (id, row, data, status) {
td.adopt(new ProgressBar(row[i].toFloat(), {'id': 'pb_'+id, 'width':80})); if (!this.rows.has(id)) {
if (typeof data[i] != 'undefined') return false;
td.set('data-raw', data[i]) }
} else { var tr = this.rows.get(id);
if(i==0) { // Apply filter
td.adopt(new Element('img', {'src':row[i], 'class': 'statusIcon'})); if (this.applyFilterOnRow(tr, status)) {
} else { var tds = tr.getElements('td');
if(i==2) { for (var i = 0; i < row.length; i++) {
// Priority if (i == 1)
if(this.priority_hidden) continue; // Do not refresh name
td.addClass('invisible'); if (i == this.progressIndex) {
} $('pb_' + id).setValue(row[i]);
td.set('html', row[i]); } else {
if (typeof data[i] != 'undefined') if (i == 0) {
td.set('data-raw', data[i]) tds[i].getChildren('img')[0].set('src', row[i]);
} } else {
} tds[i].set('html', row[i]);
td.injectInside(tr); }
}; }
if (typeof data[i] != 'undefined')
tds[i].set('data-raw', data[i])
};
} else {
// Row was hidden, check if it was selected
// and unselect it if it was
if (this.cur.contains(id)) {
// Remove from selection
this.cur.erase(id);
// Remove selected style
tr.removeClass('selected');
}
}
return true;
},
tr.addEvent('mouseover', function(e){ removeRow : function (id) {
tr.addClass('over'); if (this.cur.contains(id)) {
}.bind(this)); this.cur.erase(id);
tr.addEvent('mouseout', function(e){ }
tr.removeClass('over'); if (this.rows.has(id)) {
}.bind(this)); var tr = this.rows.get(id);
tr.addEvent('contextmenu', function(e) { tr.dispose();
if(!this.cur.contains(id)) { this.altRow();
// Remove selected style from previous ones this.rows.erase(id);
for(i=0; i<this.cur.length; i++) { return true;
if(this.rows.has(this.cur[i])) { }
var temptr = this.rows.get(this.cur[i]); return false;
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));
} 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);
},
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);
},
updateRow: function(id, row, data, status){ selectedIds : function () {
if(!this.rows.has(id)) { return this.cur;
return false; },
}
var tr = this.rows.get(id); getRowId : function (tr) {
// Apply filter return this.rows.keyOf(tr);
if(this.applyFilterOnRow(tr, status)) { },
var tds = tr.getElements('td');
for(var i=0; i<row.length; i++) {
if(i==1) continue; // Do not refresh name
if(i==this.progressIndex) {
$('pb_'+id).setValue(row[i]);
} else {
if(i==0) {
tds[i].getChildren('img')[0].set('src', row[i]);
} else {
tds[i].set('html', row[i]);
}
}
if (typeof data[i] != 'undefined')
tds[i].set('data-raw', data[i])
};
} else {
// Row was hidden, check if it was selected
// and unselect it if it was
if(this.cur.contains(id)) {
// Remove from selection
this.cur.erase(id);
// Remove selected style
tr.removeClass('selected');
}
}
return true;
},
removeRow: function(id){ getRowIds : function () {
if(this.cur.contains(id)) return this.rows.getKeys();
{ }
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;
},
selectedIds: function(){ });
return this.cur;
},
getRowId: function(tr){
return this.rows.keyOf(tr);
},
getRowIds: function(){
return this.rows.getKeys();
}
});
//dynamicTable.implement(new Options); //dynamicTable.implement(new Options);
//dynamicTable.implement(new Events); //dynamicTable.implement(new Events);

Loading…
Cancel
Save