2014-03-10 05:18:05 +00:00
$ ( document ) . ready ( function ( ) {
2015-03-18 22:22:54 +00:00
function make _row ( indexer _id , season , episode , name , checked , airdate _never ) {
2015-02-25 23:19:52 +00:00
var checkedbox = ( checked ? ' checked' : '' ) ,
2015-03-18 22:22:54 +00:00
row _class = $ ( '#row_class' ) . val ( ) ,
ep _id = season + 'x' + episode ;
2014-12-13 15:47:58 +00:00
2015-03-18 22:22:54 +00:00
return ' <tr id="ep-' + indexer _id + '-' + ep _id + '" class="' + ( airdate _never ? 'airdate-never' : row _class ) + '">'
2015-02-25 23:19:52 +00:00
+ ' <td class="tableleft" align="center">'
+ '<input type="checkbox"'
+ ' class="' + indexer _id + '-epcheck"'
2015-03-18 22:22:54 +00:00
+ ' name="' + indexer _id + '-' + ep _id + '"'
2015-02-25 23:19:52 +00:00
+ checkedbox + '></td>'
2015-03-18 22:22:54 +00:00
+ ' <td>' + ep _id + '</td>'
+ ' <td class="tableright" style="width: 100%">' + name + ( airdate _never ? ' (<strong><em>airdate is never, this should change in time</em></strong>)' : '' ) + '</td>'
2015-02-25 23:19:52 +00:00
+ ' </tr>' ;
}
2014-03-10 05:18:05 +00:00
2015-02-25 23:19:52 +00:00
$ ( '.go' ) . click ( function ( ) {
2015-02-28 03:05:20 +00:00
if ( $ ( 'input[class*="-epcheck"]:checked' ) . length === 0 && $ ( 'input[id*="allCheck-"]:checked' ) . length === 0 ) {
alert ( 'Please select at least one Show or Episode' ) ;
return false
}
2015-02-25 23:19:52 +00:00
} ) ;
2014-12-13 15:47:58 +00:00
2015-02-25 23:19:52 +00:00
$ ( '.allCheck' ) . click ( function ( ) {
var indexer _id = $ ( this ) . attr ( 'id' ) . split ( '-' ) [ 1 ] ;
$ ( '.' + indexer _id + '-epcheck' ) . prop ( 'checked' , $ ( this ) . prop ( 'checked' ) ) ;
} ) ;
2014-03-10 05:18:05 +00:00
2015-03-18 22:22:54 +00:00
$ ( '.get_more_eps' ) . show ( ) ;
function show _episodes ( btn _element ) {
var match = btn _element . attr ( 'id' ) . match ( /(.*)[-](.*)/ ) ;
if ( null == match )
return false ;
2014-03-10 05:18:05 +00:00
2015-03-18 22:22:54 +00:00
var cur _indexer _id = match [ 1 ] , action = match [ 2 ] , checked = $ ( '#allCheck-' + cur _indexer _id ) . prop ( 'checked' ) ,
show _header = $ ( 'tr#' + cur _indexer _id ) , episode _rows = $ ( 'tr[id*="ep-' + cur _indexer _id + '"]' ) ,
void _var = 'more' == action && episode _rows . show ( ) || episode _rows . hide ( ) ;
$ ( 'input#' + match [ 0 ] ) . val ( 'more' == action ? 'Expanding...' : 'Collapsing...' ) ;
2014-03-10 05:18:05 +00:00
2015-03-18 22:22:54 +00:00
if ( 0 == episode _rows . length ) {
2015-02-25 23:19:52 +00:00
$ . getJSON ( sbRoot + '/manage/showEpisodeStatuses' ,
{
indexer _id : cur _indexer _id ,
whichStatus : $ ( '#oldStatus' ) . val ( )
} ,
function ( data ) {
2015-03-18 22:22:54 +00:00
$ . each ( data , function ( season , eps ) {
$ . each ( eps , function ( episode , meta ) {
show _header . after ( make _row ( cur _indexer _id , season , episode , meta . name , checked , meta . airdate _never ) ) ;
2015-02-25 23:19:52 +00:00
} ) ;
} ) ;
2015-03-18 22:22:54 +00:00
$ ( 'input#' + match [ 0 ] ) . val ( 'more' == action ? 'Expand' : 'Collapse' ) ;
btn _element . hide ( ) ;
$ ( 'input[id="' + cur _indexer _id + '-' + ( 'more' == action ? 'less' : 'more' ) + '"]' ) . show ( ) ;
2015-02-25 23:19:52 +00:00
} ) ;
2015-03-18 22:22:54 +00:00
} else {
$ ( 'input#' + match [ 0 ] ) . val ( 'more' == action ? 'Expand' : 'Collapse' ) ;
btn _element . hide ( ) ;
$ ( 'input[id="' + cur _indexer _id + '-' + ( 'more' == action ? 'less' : 'more' ) + '"]' ) . show ( ) ;
}
}
$ ( '.get_more_eps,.get_less_eps' ) . click ( function ( ) {
show _episodes ( $ ( this ) ) ;
( $ ( '.get_more_eps:visible' ) . length == 0 ? $ ( '.expandAll' ) . hide ( ) : '' ) ;
} ) ;
$ ( '.expandAll' ) . click ( function ( ) {
2015-02-25 23:19:52 +00:00
$ ( this ) . hide ( ) ;
2015-03-18 22:22:54 +00:00
$ ( '.get_more_eps' ) . each ( function ( ) {
show _episodes ( $ ( this ) ) ;
} ) ;
2015-02-25 23:19:52 +00:00
} ) ;
// selects all visible episode checkboxes.
$ ( '.selectAllShows' ) . click ( function ( ) {
$ ( '.sickbeardTable input' ) . each ( function ( ) {
this . checked = true ;
} ) ;
} ) ;
// clears all visible episode checkboxes and the season selectors
$ ( '.unselectAllShows' ) . click ( function ( ) {
$ ( '.sickbeardTable input' ) . each ( function ( ) {
this . checked = false ;
} ) ;
} ) ;
2014-03-10 05:18:05 +00:00
} ) ;