@ -17,126 +17,168 @@ require('../../Mixins/backbone.signalr.mixin');
module . exports = Marionette . Layout . extend ( {
module . exports = Marionette . Layout . extend ( {
template : 'Wanted/Cutoff/CutoffUnmetLayoutTemplate' ,
template : 'Wanted/Cutoff/CutoffUnmetLayoutTemplate' ,
regions : {
regions : {
cutoff : '#x-cutoff-unmet' ,
cutoff : '#x-cutoff-unmet' ,
toolbar : '#x-toolbar' ,
toolbar : '#x-toolbar' ,
pager : '#x-pager'
pager : '#x-pager'
} ,
} ,
ui : { searchSelectedButton : '.btn i.icon-search' } ,
columns : [ {
ui : {
searchSelectedButton : '.btn i.icon-search'
} ,
columns : [
{
name : '' ,
name : '' ,
cell : 'select-row' ,
cell : 'select-row' ,
headerCell : 'select-all' ,
headerCell : 'select-all' ,
sortable : false
sortable : false
} , {
} ,
{
name : 'series' ,
name : 'series' ,
label : 'Series Title' ,
label : 'Series Title' ,
cell : SeriesTitleCell ,
cell : SeriesTitleCell ,
sortValue : 'series.sortTitle'
sortValue : 'series.sortTitle'
} , {
} ,
{
name : 'this' ,
name : 'this' ,
label : 'Episode' ,
label : 'Episode' ,
cell : EpisodeNumberCell ,
cell : EpisodeNumberCell ,
sortable : false
sortable : false
} , {
} ,
{
name : 'this' ,
name : 'this' ,
label : 'Episode Title' ,
label : 'Episode Title' ,
cell : EpisodeTitleCell ,
cell : EpisodeTitleCell ,
sortable : false
sortable : false
} , {
} ,
{
name : 'airDateUtc' ,
name : 'airDateUtc' ,
label : 'Air Date' ,
label : 'Air Date' ,
cell : RelativeDateCell
cell : RelativeDateCell
} , {
} ,
{
name : 'status' ,
name : 'status' ,
label : 'Status' ,
label : 'Status' ,
cell : EpisodeStatusCell ,
cell : EpisodeStatusCell ,
sortable : false
sortable : false
} ] ,
}
] ,
initialize : function ( ) {
initialize : function ( ) {
this . collection = new CutoffUnmetCollection ( ) . bindSignalR ( { updateOnly : true } ) ;
this . collection = new CutoffUnmetCollection ( ) . bindSignalR ( { updateOnly : true } ) ;
this . listenTo ( this . collection , 'sync' , this . _showTable ) ;
this . listenTo ( this . collection , 'sync' , this . _showTable ) ;
} ,
} ,
onShow : function ( ) {
onShow : function ( ) {
this . cutoff . show ( new LoadingView ( ) ) ;
this . cutoff . show ( new LoadingView ( ) ) ;
this . _showToolbar ( ) ;
this . _showToolbar ( ) ;
this . collection . fetch ( ) ;
this . collection . fetch ( ) ;
} ,
} ,
_showTable : function ( ) {
_showTable : function ( ) {
this . cutoffGrid = new Backgrid . Grid ( {
this . cutoffGrid = new Backgrid . Grid ( {
columns : this . columns ,
columns : this . columns ,
collection : this . collection ,
collection : this . collection ,
className : 'table table-hover'
className : 'table table-hover'
} ) ;
} ) ;
this . cutoff . show ( this . cutoffGrid ) ;
this . cutoff . show ( this . cutoffGrid ) ;
this . pager . show ( new GridPager ( {
this . pager . show ( new GridPager ( {
columns : this . columns ,
columns : this . columns ,
collection : this . collection
collection : this . collection
} ) ) ;
} ) ) ;
} ,
} ,
_showToolbar : function ( ) {
_showToolbar : function ( ) {
var leftSideButtons = {
var leftSideButtons = {
type : 'default' ,
type : 'default' ,
storeState : false ,
storeState : false ,
items : [ {
items : [
{
title : 'Search Selected' ,
title : 'Search Selected' ,
icon : 'icon-search' ,
icon : 'icon-search' ,
callback : this . _searchSelected ,
callback : this . _searchSelected ,
ownerContext : this ,
ownerContext : this ,
className : 'x-search-selected'
className : 'x-search-selected'
} , {
} ,
{
title : 'Season Pass' ,
title : 'Season Pass' ,
icon : 'icon-bookmark' ,
icon : 'icon-bookmark' ,
route : 'seasonpass'
route : 'seasonpass'
} ]
}
]
} ;
} ;
var filterOptions = {
var filterOptions = {
type : 'radio' ,
type : 'radio' ,
storeState : false ,
storeState : false ,
menuKey : 'wanted.filterMode' ,
menuKey : 'wanted.filterMode' ,
defaultAction : 'monitored' ,
defaultAction : 'monitored' ,
items : [ {
items : [
{
key : 'monitored' ,
key : 'monitored' ,
title : '' ,
title : '' ,
tooltip : 'Monitored Only' ,
tooltip : 'Monitored Only' ,
icon : 'icon-nd-monitored' ,
icon : 'icon-nd-monitored' ,
callback : this . _setFilter
callback : this . _setFilter
} , {
} ,
{
key : 'unmonitored' ,
key : 'unmonitored' ,
title : '' ,
title : '' ,
tooltip : 'Unmonitored Only' ,
tooltip : 'Unmonitored Only' ,
icon : 'icon-nd-unmonitored' ,
icon : 'icon-nd-unmonitored' ,
callback : this . _setFilter
callback : this . _setFilter
} ]
}
]
} ;
} ;
this . toolbar . show ( new ToolbarLayout ( {
this . toolbar . show ( new ToolbarLayout ( {
left : [ leftSideButtons ] ,
left : [
right : [ filterOptions ] ,
leftSideButtons
] ,
right : [
filterOptions
] ,
context : this
context : this
} ) ) ;
} ) ) ;
CommandController . bindToCommand ( {
CommandController . bindToCommand ( {
element : this . $ ( '.x-search-selected' ) ,
element : this . $ ( '.x-search-selected' ) ,
command : { name : 'episodeSearch' }
command : {
name : 'episodeSearch'
}
} ) ;
} ) ;
} ,
} ,
_setFilter : function ( buttonContext ) {
_setFilter : function ( buttonContext ) {
var mode = buttonContext . model . get ( 'key' ) ;
var mode = buttonContext . model . get ( 'key' ) ;
this . collection . state . currentPage = 1 ;
this . collection . state . currentPage = 1 ;
var promise = this . collection . setFilterMode ( mode ) ;
var promise = this . collection . setFilterMode ( mode ) ;
if ( buttonContext ) {
if ( buttonContext ) {
buttonContext . ui . icon . spinForPromise ( promise ) ;
buttonContext . ui . icon . spinForPromise ( promise ) ;
}
}
} ,
} ,
_searchSelected : function ( ) {
_searchSelected : function ( ) {
var selected = this . cutoffGrid . getSelectedModels ( ) ;
var selected = this . cutoffGrid . getSelectedModels ( ) ;
if ( selected . length === 0 ) {
if ( selected . length === 0 ) {
Messenger . show ( {
Messenger . show ( {
type : 'error' ,
type : 'error' ,
message : 'No episodes selected'
message : 'No episodes selected'
} ) ;
} ) ;
return ;
return ;
}
}
var ids = _ . pluck ( selected , 'id' ) ;
var ids = _ . pluck ( selected , 'id' ) ;
CommandController . Execute ( 'episodeSearch' , {
CommandController . Execute ( 'episodeSearch' , {
name : 'episodeSearch' ,
name : 'episodeSearch' ,
episodeIds : ids
episodeIds : ids