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. 189
      src/webui/www/public/scripts/client.js
  2. 175
      src/webui/www/public/scripts/dynamicTable.js

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

@ -23,14 +23,14 @@
*/ */
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);
@ -45,77 +45,84 @@ window.addEvent('load', function(){
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
},
loadMethod : 'xhr',
contentURL : 'filters.html',
column : 'filtersColumn',
height : 300
}); });
initializeWindows(); initializeWindows();
var r=0; var r = 0;
var waiting=false; var waiting = false;
var waitingTrInfo = 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 loadTransferInfo = function () {
var url = 'json/transferInfo'; var url = 'json/transferInfo';
if(!waitingTrInfo) { if (!waitingTrInfo) {
waitingTrInfo = true; waitingTrInfo = 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)');
waitingTrInfo=false; waitingTrInfo = false;
loadTransferInfo.delay(4000); 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("%1", friendlyUnit(info.dl_info_speed, true))
.replace("%2", friendlyUnit(info.dl_info_data, false))); .replace("%2", friendlyUnit(info.dl_info_data, false)));
$("UpInfos").set('html', "_(U: %1 - T: %2)".replace("%1", friendlyUnit(info.up_info_speed, true)) $("UpInfos").set('html', "_(U: %1 - T: %2)"
.replace("%1", friendlyUnit(info.up_info_speed, true))
.replace("%2", friendlyUnit(info.up_info_data, false))); .replace("%2", friendlyUnit(info.up_info_data, false)));
if(localStorage.getItem('speed_in_browser_title_bar') == 'true') 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)); document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true));
else else
document.title = "_(qBittorrent web User Interface)"; document.title = "_(qBittorrent web User Interface)";
waitingTrInfo=false; waitingTrInfo = false;
loadTransferInfo.delay(3000); loadTransferInfo.delay(3000);
} }
} }
@ -125,27 +132,27 @@ window.addEvent('load', function(){
$('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();
@ -156,8 +163,8 @@ window.addEvent('load', function(){
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;
@ -173,15 +180,15 @@ window.addEvent('load', function(){
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");
@ -192,12 +199,12 @@ window.addEvent('load', function(){
} }
}); });
// 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 {
@ -205,48 +212,58 @@ window.addEvent('load', function(){
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,
left : 0
},
loadMethod : 'xhr',
contentURL : 'transferlist.html',
onContentLoaded : function () {
ajaxfn(); ajaxfn();
}, },
column: 'mainColumn', column : 'mainColumn',
onResize: saveColumnSizes, onResize : saveColumnSizes,
height: null 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
},
contentURL : 'prop-general.html',
require : {
css : ['css/Tabs.css']
}, },
tabsURL: 'properties.html', tabsURL : 'properties.html',
column: 'mainColumn', column : 'mainColumn',
height: prop_h height : prop_h
}); });
//ajaxfn(); //ajaxfn();
loadTransferInfo(); 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");
@ -254,7 +271,7 @@ window.addEvent('load', function(){
$("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);
@ -266,7 +283,7 @@ 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();

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

@ -29,21 +29,20 @@
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){ setup : function (table, progressIndex, context_menu) {
this.table = $(table); this.table = $(table);
this.rows = new Hash(); this.rows = new Hash();
this.cur = new Array(); this.cur = new Array();
this.priority_hidden = false; this.priority_hidden = false;
this.progressIndex = progressIndex; this.progressIndex = progressIndex;
this.filter = localStorage.getItem('selected_filter'); this.filter = localStorage.getItem('selected_filter');
if(!$defined(this.filter)) { if (!$defined(this.filter)) {
this.filter = 'all'; this.filter = 'all';
} }
this.context_menu = context_menu; this.context_menu = context_menu;
@ -51,12 +50,12 @@ var dynamicTable = new Class ({
this.table.reverseSort = false; this.table.reverseSort = false;
}, },
sortfunction: function(tr1, tr2) { sortfunction : function (tr1, tr2) {
var i = tr2.getParent().sortedIndex; var i = tr2.getParent().sortedIndex;
var reverseSort = tr2.getParent().reverseSort; var reverseSort = tr2.getParent().reverseSort;
switch(i) { switch (i) {
case 1: // Name case 1: // Name
if(!reverseSort) if (!reverseSort)
return tr1.getElements('td')[i].get('html').localeCompare(tr2.getElements('td')[i].get('html')); return tr1.getElements('td')[i].get('html').localeCompare(tr2.getElements('td')[i].get('html'));
else else
return tr2.getElements('td')[i].get('html').localeCompare(tr1.getElements('td')[i].get('html')); return tr2.getElements('td')[i].get('html').localeCompare(tr1.getElements('td')[i].get('html'));
@ -69,21 +68,21 @@ var dynamicTable = new Class ({
case 8: // Down Speed case 8: // Down Speed
case 9: // ETA case 9: // ETA
default: // Ratio default: // Ratio
if(!reverseSort) if (!reverseSort)
return (tr1.getElements('td')[i].get('data-raw') - tr2.getElements('td')[i].get('data-raw')); return (tr1.getElements('td')[i].get('data-raw') - tr2.getElements('td')[i].get('data-raw'));
else else
return (tr2.getElements('td')[i].get('data-raw') - tr1.getElements('td')[i].get('data-raw')); return (tr2.getElements('td')[i].get('data-raw') - tr1.getElements('td')[i].get('data-raw'));
} }
}, },
updateSort: function() { updateSort : function () {
var trs = this.table.getChildren('tr'); var trs = this.table.getChildren('tr');
trs.sort(this.sortfunction); trs.sort(this.sortfunction);
this.table.adopt(trs); this.table.adopt(trs);
}, },
setSortedColumn: function(index) { setSortedColumn : function (index) {
if(index != this.table.sortedIndex) { if (index != this.table.sortedIndex) {
this.table.sortedIndex = index; this.table.sortedIndex = index;
this.table.reverseSort = false; this.table.reverseSort = false;
} else { } else {
@ -94,85 +93,86 @@ var dynamicTable = new Class ({
this.altRow(); this.altRow();
}, },
getCurrentTorrentHash: function() { getCurrentTorrentHash : function () {
if(this.cur.length > 0) if (this.cur.length > 0)
return this.cur[0]; return this.cur[0];
return ''; return '';
}, },
altRow: function() altRow : function () {
{
var trs = this.table.getElements('tr'); var trs = this.table.getElements('tr');
trs.each(function(el,i){ trs.each(function (el, i) {
if(i % 2){ if (i % 2) {
el.addClass('alt'); el.addClass('alt');
}else{ } else {
el.removeClass('alt'); el.removeClass('alt');
} }
}.bind(this)); }.bind(this));
}, },
hidePriority: function(){ hidePriority : function () {
if(this.priority_hidden) return; if (this.priority_hidden)
return;
$('prioHeader').addClass('invisible'); $('prioHeader').addClass('invisible');
var trs = this.table.getElements('tr'); var trs = this.table.getElements('tr');
trs.each(function(tr,i){ trs.each(function (tr, i) {
var tds = tr.getElements('td'); var tds = tr.getElements('td');
tds[2].addClass('invisible'); tds[2].addClass('invisible');
}.bind(this)); }.bind(this));
this.priority_hidden = true; this.priority_hidden = true;
}, },
setFilter: function(f) { setFilter : function (f) {
this.filter = f; this.filter = f;
}, },
showPriority: function(){ showPriority : function () {
if(!this.priority_hidden) return; if (!this.priority_hidden)
return;
$('prioHeader').removeClass('invisible'); $('prioHeader').removeClass('invisible');
var trs = this.table.getElements('tr'); var trs = this.table.getElements('tr');
trs.each(function(tr,i){ trs.each(function (tr, i) {
var tds = tr.getElements('td'); var tds = tr.getElements('td');
tds[2].removeClass('invisible'); tds[2].removeClass('invisible');
}.bind(this)); }.bind(this));
this.priority_hidden = false; this.priority_hidden = false;
}, },
applyFilterOnRow: function(tr, status) { applyFilterOnRow : function (tr, status) {
switch(this.filter) { switch (this.filter) {
case 'all': case 'all':
tr.removeClass("invisible"); tr.removeClass("invisible");
break; break;
case 'downloading': case 'downloading':
if(status == "downloading" || status == "stalledDL" || status == "checkingDL" || status == "pausedDL" || status == "queuedDL") { if (status == "downloading" || status == "stalledDL" || status == "checkingDL" || status == "pausedDL" || status == "queuedDL") {
tr.removeClass("invisible"); tr.removeClass("invisible");
} else { } else {
tr.addClass("invisible"); tr.addClass("invisible");
} }
break; break;
case 'completed': case 'completed':
if(status == "uploading" || status == "stalledUP" || status == "checkingUP" || status == "pausedUP" || status == "queuedUP") { if (status == "uploading" || status == "stalledUP" || status == "checkingUP" || status == "pausedUP" || status == "queuedUP") {
tr.removeClass("invisible"); tr.removeClass("invisible");
} else { } else {
tr.addClass("invisible"); tr.addClass("invisible");
} }
break; break;
case 'paused': case 'paused':
if(status == "pausedDL" || status == "pausedUP") { if (status == "pausedDL" || status == "pausedUP") {
tr.removeClass("invisible"); tr.removeClass("invisible");
} else { } else {
tr.addClass("invisible"); tr.addClass("invisible");
} }
break; break;
case 'active': case 'active':
if(status == "downloading" || status == "uploading") { if (status == "downloading" || status == "uploading") {
tr.removeClass("invisible"); tr.removeClass("invisible");
} else { } else {
tr.addClass("invisible"); tr.addClass("invisible");
} }
break; break;
case 'inactive': case 'inactive':
if(status != "downloading" && status != "uploading") { if (status != "downloading" && status != "uploading") {
tr.removeClass("invisible"); tr.removeClass("invisible");
} else { } else {
tr.addClass("invisible"); tr.addClass("invisible");
@ -181,27 +181,32 @@ var dynamicTable = new Class ({
return !tr.hasClass('invisible'); return !tr.hasClass('invisible');
}, },
insertRow: function(id, row, data, status){ insertRow : function (id, row, data, status) {
if(this.rows.has(id)) { if (this.rows.has(id)) {
return; return;
} }
var tr = new Element('tr'); var tr = new Element('tr');
tr.addClass("menu-target"); tr.addClass("menu-target");
this.rows.set(id, tr); this.rows.set(id, tr);
for(var i=0; i<row.length; i++) for (var i = 0; i < row.length; i++) {
{
var td = new Element('td'); var td = new Element('td');
if(i==this.progressIndex) { if (i == this.progressIndex) {
td.adopt(new ProgressBar(row[i].toFloat(), {'id': 'pb_'+id, 'width':80})); td.adopt(new ProgressBar(row[i].toFloat(), {
'id' : 'pb_' + id,
'width' : 80
}));
if (typeof data[i] != 'undefined') if (typeof data[i] != 'undefined')
td.set('data-raw', data[i]) td.set('data-raw', data[i])
} else { } else {
if(i==0) { if (i == 0) {
td.adopt(new Element('img', {'src':row[i], 'class': 'statusIcon'})); td.adopt(new Element('img', {
'src' : row[i],
'class' : 'statusIcon'
}));
} else { } else {
if(i==2) { if (i == 2) {
// Priority // Priority
if(this.priority_hidden) if (this.priority_hidden)
td.addClass('invisible'); td.addClass('invisible');
} }
td.set('html', row[i]); td.set('html', row[i]);
@ -212,17 +217,17 @@ var dynamicTable = new Class ({
td.injectInside(tr); td.injectInside(tr);
}; };
tr.addEvent('mouseover', function(e){ tr.addEvent('mouseover', function (e) {
tr.addClass('over'); tr.addClass('over');
}.bind(this)); }.bind(this));
tr.addEvent('mouseout', function(e){ tr.addEvent('mouseout', function (e) {
tr.removeClass('over'); tr.removeClass('over');
}.bind(this)); }.bind(this));
tr.addEvent('contextmenu', function(e) { tr.addEvent('contextmenu', function (e) {
if(!this.cur.contains(id)) { if (!this.cur.contains(id)) {
// Remove selected style from previous ones // Remove selected style from previous ones
for(i=0; i<this.cur.length; i++) { for (i = 0; i < this.cur.length; i++) {
if(this.rows.has(this.cur[i])) { if (this.rows.has(this.cur[i])) {
var temptr = this.rows.get(this.cur[i]); var temptr = this.rows.get(this.cur[i]);
temptr.removeClass('selected'); temptr.removeClass('selected');
} }
@ -234,28 +239,28 @@ var dynamicTable = new Class ({
} }
return true; return true;
}.bind(this)); }.bind(this));
tr.addEvent('click', function(e){ tr.addEvent('click', function (e) {
e.stop(); e.stop();
if(e.control) { if (e.control) {
// CTRL key was pressed // CTRL key was pressed
if(this.cur.contains(id)) { if (this.cur.contains(id)) {
// remove it // remove it
this.cur.erase(id); this.cur.erase(id);
// Remove selected style // Remove selected style
if(this.rows.has(id)) { if (this.rows.has(id)) {
temptr = this.rows.get(id); temptr = this.rows.get(id);
temptr.removeClass('selected'); temptr.removeClass('selected');
} }
} else { } else {
this.cur[this.cur.length] = id; this.cur[this.cur.length] = id;
// Add selected style // Add selected style
if(this.rows.has(id)) { if (this.rows.has(id)) {
temptr = this.rows.get(id); temptr = this.rows.get(id);
temptr.addClass('selected'); temptr.addClass('selected');
} }
} }
} else { } else {
if(e.shift && this.cur.length == 1) { if (e.shift && this.cur.length == 1) {
// Shift key was pressed // Shift key was pressed
var first_id = this.cur[0]; var first_id = this.cur[0];
var first_tr = this.rows.get(first_id); var first_tr = this.rows.get(first_id);
@ -264,13 +269,13 @@ var dynamicTable = new Class ({
var all_trs = this.table.getChildren('tr'); var all_trs = this.table.getChildren('tr');
var index_first_tr = all_trs.indexOf(first_tr); var index_first_tr = all_trs.indexOf(first_tr);
var index_last_tr = all_trs.indexOf(last_tr); var index_last_tr = all_trs.indexOf(last_tr);
var trs_to_select = all_trs.filter(function(item, index){ var trs_to_select = all_trs.filter(function (item, index) {
if(index_first_tr < index_last_tr) if (index_first_tr < index_last_tr)
return (index > index_first_tr) && (index <= index_last_tr); return (index > index_first_tr) && (index <= index_last_tr);
else else
return (index < index_first_tr) && (index >= index_last_tr); return (index < index_first_tr) && (index >= index_last_tr);
}); });
trs_to_select.each(function(item, index){ trs_to_select.each(function (item, index) {
// Add to selection // Add to selection
this.cur[this.cur.length] = this.getRowId(item); this.cur[this.cur.length] = this.getRowId(item);
// Select it visually // Select it visually
@ -279,15 +284,15 @@ var dynamicTable = new Class ({
} else { } else {
// Simple selection // Simple selection
// Remove selected style from previous ones // Remove selected style from previous ones
for(i=0; i<this.cur.length; i++) { for (i = 0; i < this.cur.length; i++) {
if(this.rows.has(this.cur[i])) { if (this.rows.has(this.cur[i])) {
var temptr = this.rows.get(this.cur[i]); var temptr = this.rows.get(this.cur[i]);
temptr.removeClass('selected'); temptr.removeClass('selected');
} }
} }
this.cur.empty(); this.cur.empty();
// Add selected style to new one // Add selected style to new one
if(this.rows.has(id)) { if (this.rows.has(id)) {
temptr = this.rows.get(id); temptr = this.rows.get(id);
temptr.addClass('selected'); temptr.addClass('selected');
} }
@ -301,11 +306,11 @@ var dynamicTable = new Class ({
this.applyFilterOnRow(tr, status); this.applyFilterOnRow(tr, status);
// Insert // Insert
var trs = this.table.getChildren('tr'); var trs = this.table.getChildren('tr');
var i=0; var i = 0;
while(i<trs.length && this.sortfunction(tr, trs[i]) > 0) { while (i < trs.length && this.sortfunction(tr, trs[i]) > 0) {
i++; i++;
} }
if(i==trs.length) { if (i == trs.length) {
tr.inject(this.table); tr.inject(this.table);
} else { } else {
tr.inject(trs[i], 'before'); tr.inject(trs[i], 'before');
@ -316,30 +321,31 @@ var dynamicTable = new Class ({
this.context_menu.addTarget(tr); this.context_menu.addTarget(tr);
}, },
selectAll: function() { selectAll : function () {
this.cur.empty(); this.cur.empty();
this.rows.each(function(tr, id){ this.rows.each(function (tr, id) {
this.cur[this.cur.length] = id; this.cur[this.cur.length] = id;
if(!tr.hasClass('selected')) { if (!tr.hasClass('selected')) {
tr.addClass('selected'); tr.addClass('selected');
} }
}, this); }, this);
}, },
updateRow: function(id, row, data, status){ updateRow : function (id, row, data, status) {
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);
// Apply filter // Apply filter
if(this.applyFilterOnRow(tr, status)) { if (this.applyFilterOnRow(tr, status)) {
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++) {
if(i==1) continue; // Do not refresh name if (i == 1)
if(i==this.progressIndex) { continue; // Do not refresh name
$('pb_'+id).setValue(row[i]); if (i == this.progressIndex) {
$('pb_' + id).setValue(row[i]);
} else { } else {
if(i==0) { if (i == 0) {
tds[i].getChildren('img')[0].set('src', row[i]); tds[i].getChildren('img')[0].set('src', row[i]);
} else { } else {
tds[i].set('html', row[i]); tds[i].set('html', row[i]);
@ -351,7 +357,7 @@ var dynamicTable = new Class ({
} else { } else {
// Row was hidden, check if it was selected // Row was hidden, check if it was selected
// and unselect it if it was // and unselect it if it was
if(this.cur.contains(id)) { if (this.cur.contains(id)) {
// Remove from selection // Remove from selection
this.cur.erase(id); this.cur.erase(id);
// Remove selected style // Remove selected style
@ -361,12 +367,11 @@ var dynamicTable = new Class ({
return true; return true;
}, },
removeRow: function(id){ removeRow : function (id) {
if(this.cur.contains(id)) if (this.cur.contains(id)) {
{
this.cur.erase(id); this.cur.erase(id);
} }
if(this.rows.has(id)) { if (this.rows.has(id)) {
var tr = this.rows.get(id); var tr = this.rows.get(id);
tr.dispose(); tr.dispose();
this.altRow(); this.altRow();
@ -376,19 +381,19 @@ var dynamicTable = new Class ({
return false; return false;
}, },
selectedIds: function(){ selectedIds : function () {
return this.cur; return this.cur;
}, },
getRowId: function(tr){ getRowId : function (tr) {
return this.rows.keyOf(tr); return this.rows.keyOf(tr);
}, },
getRowIds: function(){ getRowIds : function () {
return this.rows.getKeys(); return this.rows.getKeys();
} }
}); });
//dynamicTable.implement(new Options); //dynamicTable.implement(new Options);
//dynamicTable.implement(new Events); //dynamicTable.implement(new Events);

Loading…
Cancel
Save