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 @@ @@ -23,14 +23,14 @@
*/
myTable = new dynamicTable();
ajaxfn = function(){};
setSortedColumn = function(index){
ajaxfn = function () {};
setSortedColumn = function (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 properties_height = $('propertiesPanel').getSize().y;
localStorage.setItem('filters_width', filters_width);
@ -45,77 +45,84 @@ window.addEvent('load', function(){ @@ -45,77 +45,84 @@ window.addEvent('load', function(){
MochaUI.Desktop.initialize();
var filt_w = localStorage.getItem('filters_width');
if($defined(filt_w))
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]
id : 'filtersColumn',
placement : 'left',
onResize : saveColumnSizes,
width : filt_w,
resizeLimit : [100, 300]
});
new MochaUI.Column({
id: 'mainColumn',
placement: 'main',
width: null,
resizeLimit: [100, 300]
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
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 r = 0;
var waiting = false;
var waitingTrInfo = false;
var stateToImg = function(state){
if(state == "pausedUP" || state == "pausedDL") {
var stateToImg = function (state) {
if (state == "pausedUP" || state == "pausedDL") {
state = "paused";
} else {
if(state == "queuedUP" || state == "queuedDL") {
if (state == "queuedUP" || state == "queuedDL") {
state = "queued";
} else {
if(state == "checkingUP" || state == "checkingDL") {
if (state == "checkingUP" || state == "checkingDL") {
state = "checking";
}
}
}
return 'images/skin/'+state+'.png';
return 'images/skin/' + state + '.png';
};
var loadTransferInfo = function() {
var loadTransferInfo = function () {
var url = 'json/transferInfo';
if(!waitingTrInfo) {
if (!waitingTrInfo) {
waitingTrInfo = true;
var request = new Request.JSON({
url: url,
noCache: true,
method: 'get',
onFailure: function() {
url : url,
noCache : true,
method : 'get',
onFailure : function () {
$('error_div').set('html', '_(qBittorrent client is not reachable)');
waitingTrInfo=false;
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))
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))
$("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;
waitingTrInfo = false;
loadTransferInfo.delay(3000);
}
}
@ -125,27 +132,27 @@ window.addEvent('load', function(){ @@ -125,27 +132,27 @@ window.addEvent('load', function(){
$('DlInfos').addEvent('click', globalDownloadLimitFN);
$('UpInfos').addEvent('click', globalUploadLimitFN);
var ajaxfn = function(){
var ajaxfn = function () {
var queueing_enabled = false;
var url = 'json/torrents';
if (!waiting){
waiting=true;
if (!waiting) {
waiting = true;
var request = new Request.JSON({
url: url,
noCache: true,
method: 'get',
onFailure: function() {
url : url,
noCache : true,
method : 'get',
onFailure : function () {
$('error_div').set('html', '_(qBittorrent client is not reachable)');
waiting=false;
waiting = false;
ajaxfn.delay(2000);
},
onSuccess: function(events) {
onSuccess : function (events) {
$('error_div').set('html', '');
if(events){
if (events) {
// Add new torrents or update them
torrent_hashes = myTable.getRowIds();
events_hashes = new Array();
events.each(function(event){
events.each(function (event) {
events_hashes[events_hashes.length] = event.hash;
var row = new Array();
var data = new Array();
@ -156,8 +163,8 @@ window.addEvent('load', function(){ @@ -156,8 +163,8 @@ window.addEvent('load', function(){
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] = (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;
@ -173,15 +180,15 @@ window.addEvent('load', function(){ @@ -173,15 +180,15 @@ window.addEvent('load', function(){
row[8] = friendlyUnit(event.upspeed, true);
data[8] = event.upspeed;
row[9] = friendlyDuration(event.eta);
data[9] = event.eta
if(event.ratio == -1)
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)
if (row[2] != null)
queueing_enabled = true;
if(!torrent_hashes.contains(event.hash)) {
if (!torrent_hashes.contains(event.hash)) {
// New unfinished torrent
torrent_hashes[torrent_hashes.length] = event.hash;
//alert("Inserting row");
@ -192,12 +199,12 @@ window.addEvent('load', function(){ @@ -192,12 +199,12 @@ window.addEvent('load', function(){
}
});
// Remove deleted torrents
torrent_hashes.each(function(hash){
if(!events_hashes.contains(hash)) {
torrent_hashes.each(function (hash) {
if (!events_hashes.contains(hash)) {
myTable.removeRow(hash);
}
});
if(queueing_enabled) {
if (queueing_enabled) {
$('queueingButtons').removeClass('invisible');
myTable.showPriority();
} else {
@ -205,48 +212,58 @@ window.addEvent('load', function(){ @@ -205,48 +212,58 @@ window.addEvent('load', function(){
myTable.hidePriority();
}
}
waiting=false;
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() {
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
column : 'mainColumn',
onResize : saveColumnSizes,
height : null
});
var prop_h = localStorage.getItem('properties_height');
if($defined(prop_h))
if ($defined(prop_h))
prop_h = prop_h.toInt();
else
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']
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
tabsURL : 'properties.html',
column : 'mainColumn',
height : prop_h
});
//ajaxfn();
loadTransferInfo();
setFilter = function(f) {
setFilter = function (f) {
// Visually Select the right filter
$("all_filter").removeClass("selectedFilter");
$("downloading_filter").removeClass("selectedFilter");
@ -254,7 +271,7 @@ window.addEvent('load', function(){ @@ -254,7 +271,7 @@ window.addEvent('load', function(){
$("paused_filter").removeClass("selectedFilter");
$("active_filter").removeClass("selectedFilter");
$("inactive_filter").removeClass("selectedFilter");
$(f+"_filter").addClass("selectedFilter");
$(f + "_filter").addClass("selectedFilter");
myTable.setFilter(f);
ajaxfn();
localStorage.setItem('selected_filter', f);
@ -266,7 +283,7 @@ function closeWindows() { @@ -266,7 +283,7 @@ function closeWindows() {
MochaUI.closeAll();
}
window.addEvent('keydown', function(event){
window.addEvent('keydown', function (event) {
if (event.key == 'a' && event.control) {
event.stop();
myTable.selectAll();

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

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

Loading…
Cancel
Save