@ -1,5 +1,3 @@
var waiting = false ;
var clearData = function ( ) {
var clearData = function ( ) {
$ ( 'torrent_hash' ) . set ( 'html' , '' ) ;
$ ( 'torrent_hash' ) . set ( 'html' , '' ) ;
$ ( 'save_path' ) . set ( 'html' , '' ) ;
$ ( 'save_path' ) . set ( 'html' , '' ) ;
@ -16,7 +14,8 @@ var clearData = function() {
$ ( 'share_ratio' ) . set ( 'html' , '' ) ;
$ ( 'share_ratio' ) . set ( 'html' , '' ) ;
}
}
var loadData = function ( ) {
var loadTorrentDataTimer ;
var loadTorrentData = function ( ) {
if ( $ ( 'prop_general' ) . hasClass ( 'invisible' ) ) {
if ( $ ( 'prop_general' ) . hasClass ( 'invisible' ) ) {
// Tab changed, don't do anything
// Tab changed, don't do anything
return ;
return ;
@ -24,61 +23,61 @@ var loadData = function() {
var current _hash = myTable . getCurrentTorrentHash ( ) ;
var current _hash = myTable . getCurrentTorrentHash ( ) ;
if ( current _hash == "" ) {
if ( current _hash == "" ) {
clearData ( ) ;
clearData ( ) ;
loadData . delay ( 1500 ) ;
loadTorrentDataTimer = loadTorrent Data . delay ( 1500 ) ;
return ;
return ;
}
}
// Display hash
// Display hash
$ ( 'torrent_hash' ) . set ( 'html' , current _hash ) ;
$ ( 'torrent_hash' ) . set ( 'html' , current _hash ) ;
var url = 'json/propertiesGeneral/' + current _hash ;
var url = 'json/propertiesGeneral/' + current _hash ;
if ( ! waiting ) {
var request = new Request . JSON ( {
waiting = 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 ( ) {
loadTorrentDataTimer = loadTorrentData . delay ( 2000 ) ;
$ ( 'error_div' ) . set ( 'html' , '_(qBittorrent client is not reachable)' ) ;
} ,
waiting = false ;
onSuccess : function ( data ) {
loadData . delay ( 2000 ) ;
$ ( 'error_div' ) . set ( 'html' , '' ) ;
} ,
if ( data ) {
onSuccess : function ( data ) {
var temp ;
$ ( 'error_div' ) . set ( 'html' , '' ) ;
// Update Torrent data
if ( data ) {
$ ( 'save_path' ) . set ( 'html' , data . save _path ) ;
var temp ;
temp = data . creation _date ;
// Update Torrent data
var timestamp = "_(Unknown)" ;
$ ( 'save_path' ) . set ( 'html' , data . save _path ) ;
if ( temp != - 1 )
temp = data . creation _date ;
timestamp = new Date ( data . creation _date * 1000 ) . toISOString ( ) ;
var timestamp = "_(Unknown)" ;
$ ( 'creation_date' ) . set ( 'html' , timestamp ) ;
if ( temp != - 1 )
$ ( 'piece_size' ) . set ( 'html' , friendlyUnit ( data . piece _size ) ) ;
timestamp = new Date ( data . creation _date * 1000 ) . toISOString ( ) ;
$ ( 'comment' ) . set ( 'html' , data . comment ) ;
$ ( 'creation_date' ) . set ( 'html' , timestamp ) ;
$ ( 'total_uploaded' ) . set ( 'html' , friendlyUnit ( data . total _uploaded ) +
$ ( 'piece_size' ) . set ( 'html' , friendlyUnit ( data . piece _size ) ) ;
" (" + friendlyUnit ( data . total _uploaded _session ) +
$ ( 'comment' ) . set ( 'html' , data . comment ) ;
" (" + "_(this session)" + ")" ) ;
$ ( 'total_uploaded' ) . set ( 'html' , friendlyUnit ( data . total _uploaded ) +
$ ( 'total_downloaded' ) . set ( 'html' , friendlyUnit ( data . total _downloaded ) +
" (" + friendlyUnit ( data . total _uploaded _session ) +
" (" + friendlyUnit ( data . total _downloaded _session ) +
" (" + "_(this session)" + ")" ) ;
" (" + "_(this session)" + ")" ) ;
$ ( 'total_downloaded' ) . set ( 'html' , friendlyUnit ( data . total _downloaded ) +
$ ( 'total_wasted' ) . set ( 'html' , data . total _wasted ) ;
" (" + friendlyUnit ( data . total _downloaded _session ) +
temp = data . up _limit ;
" (" + "_(this session)" + ")" ) ;
$ ( 'up_limit' ) . set ( 'html' , temp == - 1 ? "∞" : temp ) ;
$ ( 'total_wasted' ) . set ( 'html' , data . total _wasted ) ;
temp = data . dl _limit ;
temp = data . up _limit ;
$ ( 'dl_limit' ) . set ( 'html' , temp == - 1 ? "∞" : temp ) ;
$ ( 'up_limit' ) . set ( 'html' , temp == - 1 ? "∞" : temp ) ;
temp = friendlyDuration ( status . active _time ) ;
temp = data . dl _limit ;
if ( status . is _seed )
$ ( 'dl_limit' ) . set ( 'html' , temp == - 1 ? "∞" : temp ) ;
temp += " (" + "_(Seeded for %1)" . replace ( "%1" , status . seeding _time ) + ")" ;
temp = friendlyDuration ( status . active _time ) ;
$ ( 'time_elapsed' ) . set ( 'html' , temp ) ;
if ( status . is _seed )
temp = data . nb _connections + " (" + "_(%1 max)" . replace ( "%1" , status . nb _connections _limit ) + ")" ;
temp += " (" + "_(Seeded for %1)" . replace ( "%1" , status . seeding _time ) + ")" ;
$ ( 'nb_connections' ) . set ( 'html' , temp ) ;
$ ( 'time_elapsed' ) . set ( 'html' , temp ) ;
$ ( 'share_ratio' ) . set ( 'html' , data . share _ratio . toFixed ( 2 ) ) ;
temp = data . nb _connections + " (" + "_(%1 max)" . replace ( "%1" , status . nb _connections _limit ) + ")" ;
$ ( 'nb_connections' ) . set ( 'html' , temp ) ;
$ ( 'share_ratio' ) . set ( 'html' , data . share _ratio . toFixed ( 2 ) ) ;
}
else {
clearData ( ) ;
}
waiting = false ;
loadData . delay ( 1500 ) ;
}
}
} ) . send ( ) ;
else {
}
clearData ( ) ;
}
loadTorrentDataTimer = loadTorrentData . delay ( 1500 ) ;
}
} ) . send ( ) ;
}
var updateTorrentData = function ( ) {
clearTimeout ( loadTorrentDataTimer ) ;
loadTorrentData ( ) ;
}
}