@ -27,228 +27,220 @@ require('jquery.dotdotdot');
var SchemaModal = require ( '../../Settings/NetImport/Add/NetImportSchemaModal' ) ;
var SchemaModal = require ( '../../Settings/NetImport/Add/NetImportSchemaModal' ) ;
module . exports = Marionette . Layout . extend ( {
module . exports = Marionette . Layout . extend ( {
template : 'AddMovies/List/AddFromListViewTemplate' ,
template : 'AddMovies/List/AddFromListViewTemplate' ,
regions : {
regions : {
fetchResult : '#fetch-result'
fetchResult : '#fetch-result'
} ,
} ,
ui : {
ui : {
moviesSearch : '.x-movies-search' ,
moviesSearch : '.x-movies-search' ,
listSelection : ".x-list-selection" ,
listSelection : ".x-list-selection" ,
importSelected : ".x-import-selected"
importSelected : ".x-import-selected"
} ,
} ,
columns : [
columns : [ {
{
name : '' ,
name : '' ,
cell : SelectAllCell ,
cell : SelectAllCell ,
headerCell : 'select-all' ,
headerCell : 'select-all' ,
sortable : false
sortable : false
} , {
} ,
name : 'title' ,
{
label : 'Title' ,
name : 'title' ,
cell : MovieTitleCell ,
label : 'Title' ,
cellValue : 'this' ,
cell : MovieTitleCell ,
} , {
cellValue : 'this' ,
name : 'profileId' ,
} ,
label : 'Profile' ,
{
cell : ProfileCell ,
name : 'profileId' ,
sortable : false ,
label : 'Profile' ,
} , {
cell : ProfileCell
name : 'this' ,
} ,
label : 'Links' ,
{
cell : MovieLinksCell ,
name : 'this' ,
className : "movie-links-cell" ,
label : 'Links' ,
sortable : false ,
cell : MovieLinksCell ,
} ] ,
className : "movie-links-cell" ,
sortable : false ,
events : {
}
'click .x-load-more' : '_onLoadMore' ,
] ,
"change .x-list-selection" : "_listSelected" ,
"click .x-fetch-list" : "_fetchList" ,
events : {
"click .x-import-selected" : "_importSelected"
'click .x-load-more' : '_onLoadMore' ,
} ,
"change .x-list-selection" : "_listSelected" ,
"click .x-fetch-list" : "_fetchList" ,
initialize : function ( options ) {
"click .x-import-selected" : "_importSelected"
console . log ( options ) ;
} ,
this . isExisting = options . isExisting ;
initialize : function ( options ) {
//this.collection = new AddFromListCollection();
console . log ( options ) ;
this . templateHelpers = { }
this . isExisting = options . isExisting ;
this . listCollection = new ListCollection ( ) ;
//this.collection = new AddFromListCollection();
this . templateHelpers . lists = this . listCollection . toJSON ( ) ;
this . templateHelpers = { }
this . listenTo ( this . listCollection , 'all' , this . _listsUpdated ) ;
this . listCollection = new ListCollection ( ) ;
this . listCollection . fetch ( ) ;
this . templateHelpers . lists = this . listCollection . toJSON ( ) ;
this . collection = new AddFromListCollection ( ) ;
this . listenTo ( this . listCollection , 'all' , this . _listsUpdated ) ;
this . listCollection . fetch ( ) ;
this . listenTo ( this . collection , 'sync' , this . _showResults ) ;
this . collection = new AddFromListCollection ( ) ;
/ * t h i s . l i s t e n T o ( t h i s . c o l l e c t i o n , ' s y n c ' , t h i s . _ s h o w R e s u l t s ) ;
this . listenTo ( this . collection , 'sync' , this . _showResults ) ;
this . resultCollectionView = new SearchResultCollectionView ( {
collection : this . collection ,
/ * t h i s . l i s t e n T o ( t h i s . c o l l e c t i o n , ' s y n c ' , t h i s . _ s h o w R e s u l t s ) ;
isExisting : this . isExisting
} ) ; * /
this . resultCollectionView = new SearchResultCollectionView ( {
collection : this . collection ,
//this.throttledSearch = _.debounce(this.search, 1000, { trailing : true }).bind(this);
isExisting : this . isExisting
} ,
} ) ; * /
onRender : function ( ) {
//this.throttledSearch = _.debounce(this.search, 1000, { trailing : true }).bind(this);
var self = this ;
} ,
this . ui . importSelected . hide ( ) ;
} ,
onRender : function ( ) {
var self = this ;
onShow : function ( ) {
this . ui . importSelected . hide ( ) ;
this . ui . moviesSearch . focus ( ) ;
} ,
} ,
onShow : function ( ) {
this . ui . moviesSearch . focus ( ) ;
search : function ( options ) {
var self = this ;
} ,
this . collection . reset ( ) ;
search : function ( options ) {
var self = this ;
if ( ! options . term || options . term === this . collection . term ) {
return Marionette . $ . Deferred ( ) . resolve ( ) ;
this . collection . reset ( ) ;
}
if ( ! options . term || options . term === this . collection . term ) {
this . searchResult . show ( new LoadingView ( ) ) ;
return Marionette . $ . Deferred ( ) . resolve ( ) ;
this . collection . term = options . term ;
}
this . currentSearchPromise = this . collection . fetch ( {
data : { term : options . term }
this . searchResult . show ( new LoadingView ( ) ) ;
} ) ;
this . collection . term = options . term ;
this . currentSearchPromise = this . collection . fetch ( {
this . currentSearchPromise . fail ( function ( ) {
data : { term : options . term }
self . _showError ( ) ;
} ) ;
} ) ;
this . currentSearchPromise . fail ( function ( ) {
return this . currentSearchPromise ;
self . _showError ( ) ;
} ,
} ) ;
_onMoviesAdded : function ( options ) {
return this . currentSearchPromise ;
if ( this . isExisting && options . movie . get ( 'path' ) === this . model . get ( 'folder' ) . path ) {
} ,
this . close ( ) ;
} else if ( ! this . isExisting ) {
_onMoviesAdded : function ( options ) {
this . resultCollectionView . setExisting ( options . movie . get ( 'tmdbId' ) ) ;
if ( this . isExisting && options . movie . get ( 'path' ) === this . model . get ( 'folder' ) . path ) {
/ * t h i s . c o l l e c t i o n . t e r m = ' ' ;
this . close ( ) ;
this . collection . reset ( ) ;
}
this . _clearResults ( ) ;
this . ui . moviesSearch . val ( '' ) ;
else if ( ! this . isExisting ) {
this . ui . moviesSearch . focus ( ) ; * / / / TODO : Maybe add option wheter to clear search result .
this . resultCollectionView . setExisting ( options . movie . get ( 'tmdbId' ) ) ;
}
/ * t h i s . c o l l e c t i o n . t e r m = ' ' ;
} ,
this . collection . reset ( ) ;
this . _clearResults ( ) ;
_onLoadMore : function ( ) {
this . ui . moviesSearch . val ( '' ) ;
var showingAll = this . resultCollectionView . showMore ( ) ;
this . ui . moviesSearch . focus ( ) ; * / / / TODO : Maybe add option wheter to clear search result .
this . ui . searchBar . show ( ) ;
}
} ,
if ( showingAll ) {
this . ui . loadMore . hide ( ) ;
_onLoadMore : function ( ) {
}
var showingAll = this . resultCollectionView . showMore ( ) ;
} ,
this . ui . searchBar . show ( ) ;
_listSelected : function ( ) {
if ( showingAll ) {
var rootFolderValue = this . ui . listSelection . val ( ) ;
this . ui . loadMore . hide ( ) ;
if ( rootFolderValue === 'addNew' ) {
}
//var rootFolderLayout = new SchemaModal(this.listCollection);
} ,
//AppLayout.modalRegion.show(rootFolderLayout);
SchemaModal . open ( this . listCollection )
_listSelected : function ( ) {
}
var rootFolderValue = this . ui . listSelection . val ( ) ;
} ,
if ( rootFolderValue === 'addNew' ) {
//var rootFolderLayout = new SchemaModal(this.listCollection);
_fetchList : function ( ) {
//AppLayout.modalRegion.show(rootFolderLayout);
var self = this ;
SchemaModal . open ( this . listCollection )
var listId = this . ui . listSelection . val ( ) ;
}
} ,
this . fetchResult . show ( new LoadingView ( ) ) ;
_fetchList : function ( ) {
this . currentFetchPromise = this . collection . fetch ( { data : { listId : listId } } )
var self = this ;
this . currentFetchPromise . fail ( function ( ) {
var listId = this . ui . listSelection . val ( ) ;
self . _showError ( ) ;
} ) ;
this . fetchResult . show ( new LoadingView ( ) ) ;
} ,
this . currentFetchPromise = this . collection . fetch (
{ data : { listId : listId } }
_listsUpdated : function ( ) {
)
this . templateHelpers . lists = this . listCollection . toJSON ( ) ;
this . currentFetchPromise . fail ( function ( ) {
this . render ( ) ;
self . _showError ( ) ;
} ,
} ) ;
_importSelected : function ( ) {
} ,
var selected = this . importGrid . getSelectedModels ( ) ;
// console.log(selected);
_listsUpdated : function ( ) {
var promise = MoviesCollection . importFromList ( selected ) ;
this . templateHelpers . lists = this . listCollection . toJSON ( ) ;
this . ui . importSelected . spinForPromise ( promise ) ;
this . render ( ) ;
this . ui . importSelected . addClass ( 'disabled' ) ;
} ,
Messenger . show ( {
_importSelected : function ( ) {
message : "Importing {0} movies. Don't close this browser window until it has finished" . format ( selected . length ) ,
var selected = this . importGrid . getSelectedModels ( ) ;
hideOnNavigate : false ,
// console.log(selected);
hideAfter : 30 ,
var promise = MoviesCollection . importFromList ( selected ) ;
type : "error"
this . ui . importSelected . spinForPromise ( promise ) ;
} ) ;
this . ui . importSelected . addClass ( 'disabled' ) ;
promise . done ( function ( ) {
Messenger . show ( {
Messenger . show ( {
message : "Importing {0} movies. Don't close this browser window until it has finished" . format ( selected . length ) ,
message : "Imported movies from list." ,
hideOnNavigate : false ,
hideAfter : 8 ,
hideAfter : 30 ,
hideOnNavigate : true
type : "error"
} ) ;
} ) ;
} ) ;
/ * f o r ( m i n s e l e c t e d ) {
promise . done ( function ( ) {
debugger ;
Messenger . show ( {
m . save ( )
message : "Imported movies from list." ,
MoviesCollection . add ( m ) ;
hideAfter : 8 ,
} * /
hideOnNavigate : true
} ) ;
//MoviesCollection.save();
} ) ;
} ,
/ * f o r ( m i n s e l e c t e d ) {
debugger ;
_clearResults : function ( ) {
m . save ( )
MoviesCollection . add ( m ) ;
if ( ! this . isExisting ) {
} * /
this . searchResult . show ( new EmptyView ( ) ) ;
} else {
//MoviesCollection.save();
this . searchResult . close ( ) ;
} ,
}
} ,
_clearResults : function ( ) {
_showResults : function ( ) {
if ( ! this . isExisting ) {
if ( this . collection . length === 0 ) {
this . searchResult . show ( new EmptyView ( ) ) ;
this . fetchResult . show ( new NotFoundView ( { term : "" } ) ) ;
} else {
} else {
this . searchResult . close ( ) ;
this . importGrid = new Backgrid . Grid ( {
}
collection : this . collection ,
} ,
columns : this . columns ,
className : 'table table-hover'
_showResults : function ( ) {
} ) ;
if ( this . collection . length === 0 ) {
this . fetchResult . show ( this . importGrid ) ;
this . fetchResult . show ( new NotFoundView ( { term : "" } ) ) ;
this . ui . importSelected . show ( ) ;
} else {
}
this . importGrid = new Backgrid . Grid ( {
collection : this . collection ,
} ,
columns : this . columns ,
className : 'table table-hover'
_abortExistingSearch : function ( ) {
} ) ;
if ( this . currentSearchPromise && this . currentSearchPromise . readyState > 0 && this . currentSearchPromise . readyState < 4 ) {
this . fetchResult . show ( this . importGrid ) ;
console . log ( 'aborting previous pending search request.' ) ;
this . ui . importSelected . show ( ) ;
this . currentSearchPromise . abort ( ) ;
}
} else {
this . _clearResults ( ) ;
} ,
}
} ,
_abortExistingSearch : function ( ) {
if ( this . currentSearchPromise && this . currentSearchPromise . readyState > 0 && this . currentSearchPromise . readyState < 4 ) {
_showError : function ( ) {
console . log ( 'aborting previous pending search request.' ) ;
this . fetchResult . show ( new ErrorView ( { term : "" } ) ) ;
this . currentSearchPromise . abort ( ) ;
}
} else {
this . _clearResults ( ) ;
}
} ,
_showError : function ( ) {
this . fetchResult . show ( new ErrorView ( { term : "" } ) ) ;
}
} ) ;
} ) ;