@ -1,51 +1,26 @@
var is _seed = true ;
var is _seed = true ;
var current _hash = "" ;
var current _hash = "" ;
if ( ! ( Browser . name == "ie" && Browser . version < 9 ) ) {
$ ( "all_files_cb" ) . removeClass ( "tristate" ) ;
$ ( "all_files_cb" ) . removeClass ( "partial" ) ;
$ ( "all_files_cb" ) . removeClass ( "checked" ) ;
$ ( "tristate_cb" ) . style . display = "inline" ;
}
var setCBState = function ( state ) {
var setCBState = function ( state ) {
if ( Browser . name == "ie" && Browser . version < 9 ) {
$ ( "tristate_cb" ) . state = state ;
if ( state == "partial" ) {
if ( state === "partial" ) {
if ( ! $ ( "all_files_cb" ) . hasClass ( "partial" ) ) {
$ ( "tristate_cb" ) . indeterminate = true ;
$ ( "all_files_cb" ) . removeClass ( "checked" ) ;
$ ( "all_files_cb" ) . addClass ( "partial" ) ;
}
return ;
}
if ( state == "checked" ) {
if ( ! $ ( "all_files_cb" ) . hasClass ( "checked" ) ) {
$ ( "all_files_cb" ) . removeClass ( "partial" ) ;
$ ( "all_files_cb" ) . addClass ( "checked" ) ;
}
return ;
}
$ ( "all_files_cb" ) . removeClass ( "partial" ) ;
$ ( "all_files_cb" ) . removeClass ( "checked" ) ;
}
}
else {
else if ( state === "checked" ) {
if ( state == "partial" ) {
$ ( "tristate_cb" ) . indeterminate = false ;
$ ( "tristate_cb" ) . indeterminate = true ;
$ ( "tristate_cb" ) . checked = true ;
}
}
else if ( state == "checked" ) {
else if ( state === "unchecked" ) {
$ ( "tristate_cb" ) . indeterminate = false ;
$ ( "tristate_cb" ) . indeterminate = false ;
$ ( "tristate_cb" ) . checked = true ;
$ ( "tristate_cb" ) . checked = false ;
}
else {
$ ( "tristate_cb" ) . indeterminate = false ;
$ ( "tristate_cb" ) . checked = false ;
}
}
}
} ;
} ;
var switchCBState = function ( ) {
var switchCBState = function ( ) {
// Uncheck
// Uncheck
if ( $ ( "all_files_cb" ) . hasClass ( "partial" ) ) {
if ( ( $ ( "tristate_cb" ) . state === "partial" ) || ( $ ( "tristate_cb" ) . state === "checked" ) ) {
$ ( "all_files_cb" ) . removeClass ( "partial" ) ;
$ ( "tristate_cb" ) . state = "unchecked" ;
$ ( "tristate_cb" ) . checked = false ;
// Uncheck all checkboxes
// Uncheck all checkboxes
var indexes = [ ] ;
var indexes = [ ] ;
$$ ( 'input.DownloadedCB' ) . each ( function ( item , index ) {
$$ ( 'input.DownloadedCB' ) . each ( function ( item , index ) {
@ -53,28 +28,19 @@ var switchCBState = function() {
indexes . push ( index ) ;
indexes . push ( index ) ;
} ) ;
} ) ;
setFilePriority ( indexes , 0 ) ;
setFilePriority ( indexes , 0 ) ;
return ;
}
}
if ( $ ( "all_files_cb" ) . hasClass ( "checked" ) ) {
else if ( $ ( "tristate_cb" ) . state === "unchecked" ) {
$ ( "all_files_cb" ) . removeClass ( "checked" ) ;
// Check
// Uncheck all checkboxes
$ ( "tristate_cb" ) . state = "checked" ;
$ ( "tristate_cb" ) . checked = true ;
// Check all checkboxes
var indexes = [ ] ;
var indexes = [ ] ;
$$ ( 'input.DownloadedCB' ) . each ( function ( item , index ) {
$$ ( 'input.DownloadedCB' ) . each ( function ( item , index ) {
item . erase ( "checked" ) ;
item . set ( "checked" , "checked" ) ;
indexes . push ( index ) ;
indexes . push ( index ) ;
} ) ;
} ) ;
setFilePriority ( indexes , 0 ) ;
setFilePriority ( indexes , FilePriority . Normal ) ;
return ;
}
}
// Check
$ ( "all_files_cb" ) . addClass ( "checked" ) ;
// Check all checkboxes
var indexes = [ ] ;
$$ ( 'input.DownloadedCB' ) . each ( function ( item , index ) {
item . set ( "checked" , "checked" ) ;
indexes . push ( index ) ;
} ) ;
setFilePriority ( indexes , 1 ) ;
} ;
} ;
var allCBChecked = function ( ) {
var allCBChecked = function ( ) {
@ -97,10 +63,32 @@ var allCBUnchecked = function() {
return true ;
return true ;
} ;
} ;
var FilePriority = {
"Ignored" : 0 ,
"Normal" : 1 ,
"High" : 6 ,
"Maximum" : 7 ,
"Mixed" : - 1
} ;
var normalizePriority = function ( priority ) {
switch ( priority ) {
case FilePriority . Ignored :
case FilePriority . Normal :
case FilePriority . High :
case FilePriority . Maximum :
case FilePriority . Mixed :
return priority ;
default :
return FilePriority . Normal ;
}
} ;
var setFilePriority = function ( id , priority ) {
var setFilePriority = function ( id , priority ) {
if ( current _hash === "" ) return ;
if ( current _hash === "" ) return ;
var ids = Array . isArray ( id ) ? id : [ id ] ;
var ids = Array . isArray ( id ) ? id : [ id ] ;
clearTimeout ( loadTorrentFilesDataTimer ) ;
new Request ( {
new Request ( {
url : 'api/v2/torrents/filePrio' ,
url : 'api/v2/torrents/filePrio' ,
method : 'post' ,
method : 'post' ,
@ -108,6 +96,9 @@ var setFilePriority = function(id, priority) {
'hash' : current _hash ,
'hash' : current _hash ,
'id' : ids . join ( '|' ) ,
'id' : ids . join ( '|' ) ,
'priority' : priority
'priority' : priority
} ,
onComplete : function ( ) {
loadTorrentFilesDataTimer = loadTorrentFilesData . delay ( 1000 ) ;
}
}
} ) . send ( ) ;
} ) . send ( ) ;
// Display or add combobox
// Display or add combobox
@ -142,13 +133,11 @@ var createDownloadedCB = function(id, downloaded) {
if ( allCBChecked ( ) ) {
if ( allCBChecked ( ) ) {
setCBState ( "checked" ) ;
setCBState ( "checked" ) ;
}
}
else if ( allCBUnchecked ( ) ) {
setCBState ( "unchecked" ) ;
}
else {
else {
if ( allCBUnchecked ( ) ) {
setCBState ( "partial" ) ;
setCBState ( "unchecked" ) ;
}
else {
setCBState ( "partial" ) ;
}
}
}
} ) ;
} ) ;
return CB ;
return CB ;
@ -166,23 +155,16 @@ var createPriorityCombo = function(id, selected_prio) {
var elem = new Element ( "option" ) ;
var elem = new Element ( "option" ) ;
elem . set ( 'value' , priority . toString ( ) ) ;
elem . set ( 'value' , priority . toString ( ) ) ;
elem . set ( 'html' , html ) ;
elem . set ( 'html' , html ) ;
if ( selected _ prio == priority )
if ( priority == selected _ prio)
elem . setAttribute ( 'selected' , 'true ' ) ;
elem . setAttribute ( 'selected' , '' ) ;
return elem ;
return elem ;
}
}
var normal = createOptionElement ( 1 , "QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]" ) ;
createOptionElement ( FilePriority . Normal , "QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]" ) . injectInside ( select ) ;
if ( selected _prio <= 0 )
createOptionElement ( FilePriority . High , "QBT_TR(High)QBT_TR[CONTEXT=PropListDelegate]" ) . injectInside ( select ) ;
normal . setAttribute ( 'selected' , '' ) ;
createOptionElement ( FilePriority . Maximum , "QBT_TR(Maximum)QBT_TR[CONTEXT=PropListDelegate]" ) . injectInside ( select ) ;
normal . injectInside ( select ) ;
var high = createOptionElement ( 6 , "QBT_TR(High)QBT_TR[CONTEXT=PropListDelegate]" ) ;
high . injectInside ( select ) ;
var maximum = createOptionElement ( 7 , "QBT_TR(Maximum)QBT_TR[CONTEXT=PropListDelegate]" ) ;
maximum . injectInside ( select ) ;
if ( is _seed || selected _prio < 1 ) {
if ( is _seed || ( selected _prio === FilePriority . Ignored ) || ( selected _prio === FilePriority . Mixed ) ) {
select . addClass ( "invisible" ) ;
select . addClass ( "invisible" ) ;
}
}
else {
else {
@ -231,8 +213,9 @@ var filesDynTable = new Class({
$ ( 'pbf_' + id ) . setValue ( row [ i ] . toFloat ( ) ) ;
$ ( 'pbf_' + id ) . setValue ( row [ i ] . toFloat ( ) ) ;
break ;
break ;
case 4 : // download priority
case 4 : // download priority
if ( ! is _seed && row [ i ] > 0 ) {
var priority = normalizePriority ( row [ i ] ) ;
tds [ i ] . getChildren ( 'select' ) . set ( 'value' , row [ i ] ) ;
if ( ! is _seed && ( priority > 0 ) ) {
tds [ i ] . getChildren ( 'select' ) . set ( 'value' , priority ) ;
if ( $ ( 'comboPrio' + id ) . hasClass ( "invisible" ) )
if ( $ ( 'comboPrio' + id ) . hasClass ( "invisible" ) )
$ ( 'comboPrio' + id ) . removeClass ( "invisible" ) ;
$ ( 'comboPrio' + id ) . removeClass ( "invisible" ) ;
}
}
@ -278,7 +261,7 @@ var filesDynTable = new Class({
} ) ) ;
} ) ) ;
break ;
break ;
case 4 :
case 4 :
td . adopt ( createPriorityCombo ( id , row [ i ] ) ) ;
td . adopt ( createPriorityCombo ( id , normalizePriority ( row [ i ] ) ) ) ;
break ;
break ;
default :
default :
td . set ( 'html' , row [ i ] ) ;
td . set ( 'html' , row [ i ] ) ;
@ -346,13 +329,11 @@ var loadTorrentFilesData = function() {
if ( allCBChecked ( ) ) {
if ( allCBChecked ( ) ) {
setCBState ( "checked" ) ;
setCBState ( "checked" ) ;
}
}
else if ( allCBUnchecked ( ) ) {
setCBState ( "unchecked" ) ;
}
else {
else {
if ( allCBUnchecked ( ) ) {
setCBState ( "partial" ) ;
setCBState ( "unchecked" ) ;
}
else {
setCBState ( "partial" ) ;
}
}
}
}
}
else {
else {