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