@ -5,7 +5,7 @@ var PosterCollectionView = require('./Posters/SeriesPostersCollectionView');
var ListCollectionView = require ( './Overview/SeriesOverviewCollectionView' ) ;
var EmptyView = require ( './EmptyView' ) ;
var MoviesCollection = require ( '../MoviesCollection' ) ;
var FullMovieCollection = require ( '../FullMovieCollection' ) ;
//var FullMovieCollection = require('../FullMovieCollection');
var InCinemasCell = require ( '../../Cells/InCinemasCell' ) ;
var MovieTitleCell = require ( '../../Cells/MovieTitleCell' ) ;
var TemplatedCell = require ( '../../Cells/TemplatedCell' ) ;
@ -21,6 +21,13 @@ var FooterModel = require('./FooterModel');
var ToolbarLayout = require ( '../../Shared/Toolbar/ToolbarLayout' ) ;
require ( '../../Mixins/backbone.signalr.mixin' ) ;
var MoviesCollectionClient = require ( '../MoviesCollectionClient' ) ;
//this variable prevents double fetching the FullMovieCollection on first load
//var shownOnce = false;
//require('../Globals');
window . shownOnce = false ;
module . exports = Marionette . Layout . extend ( {
template : 'Movies/Index/MoviesIndexLayoutTemplate' ,
@ -120,35 +127,61 @@ module.exports = Marionette.Layout.extend({
} ,
initialize : function ( ) {
this . seriesCollection = MoviesCollection . clone ( ) ;
//this variable prevents us from showing the list before seriesCollection has been fetched the first time
this . renderedOnce = false ;
this . seriesCollection = MoviesCollection ; //.clone();
this . seriesCollection . bindSignalR ( ) ;
//this.fullCollection = FullMovieCollection;
//need to add this so the footer gets refreshed
this . listenTo ( FullMovieCollection , 'sync' , function ( model , collection , options ) {
//this._renderView();
this . _showFooter ( ) ;
/ * v a r s e l e c t e d = M o v i e s C o l l e c t i o n C l i e n t . f u l l C o l l e c t i o n . w h e r e ( { s a v e d : t r u e } ) ;
_ . each ( selected , function ( model ) {
model . set ( 'saved' , false ) ;
} ) ; * /
//if (window.shownOnce) {
// FullMovieCollection.fetch({reset : true});
//}
this . listenTo ( MoviesCollectionClient , 'sync' , function ( eventName ) {
this . _showFooter ( ) ;
window . shownOnce = true ;
} ) ;
this . listenTo ( this . seriesCollection , 'sync' , function ( model , collection , options ) {
//this.seriesCollection.fullCollection.resetFiltered();
this . _renderView ( ) ;
//MoviesCollectionClient.fetch();
this . renderedOnce = true ;
} ) ;
this . listenTo ( MoviesCollection , "sync" , function ( eventName ) {
this . seriesCollection = MoviesCollection . clone ( ) ;
//this._showTable();
this . _renderView ( ) ;
} ) ;
this . listenTo ( this . seriesCollection , "change" , function ( model ) {
if ( model . get ( 'saved' ) ) {
model . set ( 'saved' , false ) ;
this . seriesCollection . fetch ( ) ;
//FullMovieCollection.fetch({reset : true });
//this._showFooter();
var m = MoviesCollectionClient . fullCollection . findWhere ( { tmdbId : model . get ( 'tmdbId' ) } ) ;
m . set ( 'monitored' , model . get ( 'monitored' ) ) ;
m . set ( 'minimumAvailability' , model . get ( 'minimumAvailability' ) ) ;
m . set ( { profileId : model . get ( 'profileId' ) } ) ;
this . _showFooter ( ) ;
}
} ) ;
this . listenTo ( this . seriesCollection , 'add' , function ( model , collection , options ) {
//this.seriesCollection.fullCollection.resetFiltered();
//this._renderView();
} ) ;
this . listenTo ( this . seriesCollection , 'remove' , function ( model , collection , options ) {
//this.seriesCollection.fullCollection.resetFiltered();
//this._showTable();
if ( model . get ( 'deleted' ) ) {
this . seriesCollection . fetch ( ) ; //need to do this so that the page shows a full page and the 'total records' number is updated
//FullMovieCollection.fetch({reset : true}); //need to do this to update the footer
MoviesCollectionClient . fullCollection . remove ( model ) ;
this . _showFooter ( ) ;
}
} ) ;
this . sortingOptions = {
@ -264,7 +297,10 @@ module.exports = Marionette.Layout.extend({
onShow : function ( ) {
this . _showToolbar ( ) ;
this . _fetchCollection ( ) ;
//if (window.shownOnce) {
this . _showFooter ( ) ;
//}
//this._fetchCollection();
} ,
_showTable : function ( ) {
@ -274,9 +310,10 @@ module.exports = Marionette.Layout.extend({
className : 'table table-hover'
} ) ;
this . _showPager ( ) ;
this . _renderView ( ) ;
//this._showPager();
if ( this . renderedOnce ) {
this . _renderView ( ) ;
}
} ,
_showList : function ( ) {
@ -309,19 +346,11 @@ module.exports = Marionette.Layout.extend({
} else {
this . seriesRegion . show ( this . currentView ) ;
this . listenTo ( this . currentView . collection , "sync" , function ( eventName ) {
this . _showPager ( ) ;
//debugger;
} ) ;
this . _showToolbar ( ) ;
//this._showFooter();
this . _showPager ( ) ;
}
} ,
_fetchCollection : function ( ) {
this . seriesCollection . fetch ( ) ;
} ,
_setFilter : function ( buttonContext ) {
var mode = buttonContext . model . get ( 'key' ) ;
this . seriesCollection . setFilterMode ( mode ) ;
@ -366,7 +395,7 @@ module.exports = Marionette.Layout.extend({
_showFooter : function ( ) {
var footerModel = new FooterModel ( ) ;
var movies = Full MovieCollection. models . length ;
var movies = MoviesCollectionClient. full Collection. models . length ;
//instead of all the counters could do something like this with different query in the where...
//var releasedMovies = FullMovieCollection.where({ 'released' : this.model.get('released') });
// releasedMovies.length
@ -380,12 +409,13 @@ module.exports = Marionette.Layout.extend({
var downloaded = 0 ;
var missingMonitored = 0 ;
var missingNotMonitored = 0 ;
var missing NotAvailable= 0 ;
var missing Monitored NotAvailable= 0 ;
var missingMonitoredAvailable = 0 ;
var downloadedMonitored = 0 ;
var downloadedNotMonitored = 0 ;
_ . each ( Full MovieCollection. models , function ( model ) {
_ . each ( MoviesCollectionClient. full Collection. models , function ( model ) {
if ( model . get ( 'status' ) . toLowerCase ( ) === 'released' ) {
released ++ ;
@ -398,7 +428,10 @@ module.exports = Marionette.Layout.extend({
}
if ( model . get ( 'monitored' ) ) {
monitored ++ ;
monitored ++ ;
if ( model . get ( 'downloaded' ) ) {
downloadedMonitored ++ ;
}
}
else { //not monitored
if ( model . get ( 'downloaded' ) ) {
@ -414,7 +447,9 @@ module.exports = Marionette.Layout.extend({
}
else { //missing
if ( ! model . get ( 'isAvailable' ) ) {
missingNotAvailable ++ ;
if ( model . get ( 'monitored' ) ) {
missingMonitoredNotAvailable ++ ;
}
}
if ( model . get ( 'monitored' ) ) {
@ -433,10 +468,11 @@ module.exports = Marionette.Layout.extend({
released : released ,
monitored : monitored ,
downloaded : downloaded ,
downloadedMonitored : downloadedMonitored ,
downloadedNotMonitored : downloadedNotMonitored ,
missingMonitored : missingMonitored ,
missingMonitoredAvailable : missingMonitoredAvailable ,
missing NotAvailable : missing NotAvailable,
missing Monitored NotAvailable : missing Monitored NotAvailable,
missingNotMonitored : missingNotMonitored
} ) ;