@ -1,6 +1,5 @@
'use strict' ;
define (
[
define ( [
'underscore' ,
'marionette' ,
'backgrid' ,
@ -16,7 +15,7 @@ define(
'Shared/Messenger' ,
'Commands/CommandController' ,
'backgrid.selectall'
] , function ( _ ,
] , function ( _ ,
Marionette ,
Backgrid ,
MissingCollection ,
@ -31,24 +30,23 @@ define(
Messenger ,
CommandController ) {
return Marionette . Layout . extend ( {
template : 'Wanted/Missing/MissingLayoutTemplate' ,
template : 'Wanted/Missing/MissingLayoutTemplate' ,
regions : {
missing : '#x-missing' ,
toolbar : '#x-toolbar' ,
regions : {
missing : '#x-missing' ,
toolbar : '#x-toolbar' ,
pager : '#x-pager'
} ,
ui : {
searchSelectedButton : '.btn i.icon-search'
ui : {
searchSelectedButton : '.btn i.icon-search'
} ,
columns :
[
columns : [
{
name : '' ,
cell : 'select-row' ,
headerCell : 'select-all' ,
headerCell : 'select-all' ,
sortable : false
} ,
{
@ -78,26 +76,26 @@ define(
name : 'status' ,
label : 'Status' ,
cell : EpisodeStatusCell ,
sortable : false
sortable : false
}
] ,
initialize : function ( ) {
initialize : function ( ) {
this . collection = new MissingCollection ( ) ;
this . listenTo ( this . collection , 'sync' , this . _showTable ) ;
} ,
onShow : function ( ) {
onShow : function ( ) {
this . missing . show ( new LoadingView ( ) ) ;
this . _showToolbar ( ) ;
this . collection . fetch ( ) ;
} ,
_showTable : function ( ) {
_showTable : function ( ) {
this . missingGrid = new Backgrid . Grid ( {
columns : this . columns ,
collection : this . collection ,
collection : this . collection ,
className : 'table table-hover'
} ) ;
@ -105,40 +103,41 @@ define(
this . pager . show ( new GridPager ( {
columns : this . columns ,
collection : this . collection
collection : this . collection
} ) ) ;
} ,
_showToolbar : function ( ) {
_showToolbar : function ( ) {
var leftSideButtons = {
type : 'default' ,
storeState : false ,
collapse : true ,
items :
[
items : [
{
title : 'Search Selected' ,
title : 'Search Selected' ,
icon : 'icon-search' ,
callback : this . _searchSelected ,
ownerContext : this
callback : this . _searchSelected ,
ownerContext : this ,
className : 'x-search-selected'
} ,
{
title : 'Search All Missing' ,
title : 'Search All Missing' ,
icon : 'icon-search' ,
callback : this . _searchMissing ,
ownerContext : this
callback : this . _searchMissing ,
ownerContext : this ,
className : 'x-search-missing'
} ,
{
title : 'Season Pass' ,
title : 'Season Pass' ,
icon : 'icon-bookmark' ,
route : 'seasonpass'
route : 'seasonpass'
} ,
{
title : 'Rescan Drone Factory Folder' ,
title : 'Rescan Drone Factory Folder' ,
icon : 'icon-refresh' ,
command : 'downloadedepisodesscan' ,
properties : {
sendUpdates : true
command : 'downloadedepisodesscan' ,
properties : {
sendUpdates : true
}
}
]
@ -149,8 +148,7 @@ define(
storeState : false ,
menuKey : 'wanted.filterMode' ,
defaultAction : 'monitored' ,
items :
[
items : [
{
key : 'monitored' ,
title : '' ,
@ -169,42 +167,48 @@ define(
} ;
this . toolbar . show ( new ToolbarLayout ( {
left :
[
left : [
leftSideButtons
] ,
right :
[
right : [
filterOptions
] ,
context : this
context : this
} ) ) ;
CommandController . bindToCommand ( {
element : this . $ ( '.x-toolbar-left-1 .btn i.icon-search' ) ,
command : {
name : 'episodeSearch'
element : this . $ ( '.x-search-selected' ) ,
command : {
name : 'episodeSearch'
}
} ) ;
CommandController . bindToCommand ( {
element : this . $ ( '.x-search-missing' ) ,
command : {
name : 'missingEpisodeSearch'
}
} ) ;
} ,
_setFilter : function ( buttonContext ) {
_setFilter : function ( buttonContext ) {
var mode = buttonContext . model . get ( 'key' ) ;
this . collection . state . currentPage = 1 ;
var promise = this . collection . setFilterMode ( mode ) ;
if ( buttonContext )
if ( buttonContext ) {
buttonContext . ui . icon . spinForPromise ( promise ) ;
}
} ,
_searchSelected : function ( ) {
_searchSelected : function ( ) {
var selected = this . missingGrid . getSelectedModels ( ) ;
if ( selected . length === 0 ) {
Messenger . show ( {
type : 'error' ,
message : 'No episodes selected'
type : 'error' ,
message : 'No episodes selected'
} ) ;
return ;
@ -214,18 +218,16 @@ define(
CommandController . Execute ( 'episodeSearch' , {
name : 'episodeSearch' ,
episodeIds : ids
episodeIds : ids
} ) ;
} ,
_searchMissing : function ( ) {
if ( window . confirm ( 'Are you sure you want to search for {0} missing episodes? ' . format ( this . collection . state . totalRecords ) +
'One API request to each indexer will be used for each episode. ' +
'This cannot be stopped once started.' ) ) {
_searchMissing : function ( ) {
if ( window . confirm ( 'Are you sure you want to search for {0} missing episodes? ' . format ( this . collection . state . totalRecords ) + 'One API request to each indexer will be used for each episode. ' + 'This cannot be stopped once started.' ) ) {
CommandController . Execute ( 'missingEpisodeSearch' , {
name : 'missingEpisodeSearch'
} ) ;
}
}
} ) ;
} ) ;
} ) ;