@ -27,53 +27,49 @@ 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"
} ,
initialize : function ( options ) {
console . log ( options ) ;
console . log ( options ) ;
this . isExisting = options . isExisting ;
this . isExisting = options . isExisting ;
@ -100,17 +96,17 @@ module.exports = Marionette.Layout.extend({
//this.throttledSearch = _.debounce(this.search, 1000, { trailing : true }).bind(this);
//this.throttledSearch = _.debounce(this.search, 1000, { trailing : true }).bind(this);
} ,
} ,
onRender : function ( ) {
onRender : function ( ) {
var self = this ;
var self = this ;
this . ui . importSelected . hide ( ) ;
this . ui . importSelected . hide ( ) ;
} ,
} ,
onShow : function ( ) {
onShow : function ( ) {
this . ui . moviesSearch . focus ( ) ;
this . ui . moviesSearch . focus ( ) ;
} ,
} ,
search : function ( options ) {
search : function ( options ) {
var self = this ;
var self = this ;
this . collection . reset ( ) ;
this . collection . reset ( ) ;
@ -122,7 +118,7 @@ module.exports = Marionette.Layout.extend({
this . searchResult . show ( new LoadingView ( ) ) ;
this . searchResult . show ( new LoadingView ( ) ) ;
this . collection . term = options . term ;
this . collection . term = options . term ;
this . currentSearchPromise = this . collection . fetch ( {
this . currentSearchPromise = this . collection . fetch ( {
data : { term : options . term }
data : { term : options . term }
} ) ;
} ) ;
this . currentSearchPromise . fail ( function ( ) {
this . currentSearchPromise . fail ( function ( ) {
@ -132,12 +128,10 @@ module.exports = Marionette.Layout.extend({
return this . currentSearchPromise ;
return this . currentSearchPromise ;
} ,
} ,
_onMoviesAdded : function ( options ) {
_onMoviesAdded : function ( options ) {
if ( this . isExisting && options . movie . get ( 'path' ) === this . model . get ( 'folder' ) . path ) {
if ( this . isExisting && options . movie . get ( 'path' ) === this . model . get ( 'folder' ) . path ) {
this . close ( ) ;
this . close ( ) ;
}
} else if ( ! this . isExisting ) {
else if ( ! this . isExisting ) {
this . resultCollectionView . setExisting ( options . movie . get ( 'tmdbId' ) ) ;
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 = ' ' ;
/ * t h i s . c o l l e c t i o n . t e r m = ' ' ;
this . collection . reset ( ) ;
this . collection . reset ( ) ;
@ -147,7 +141,7 @@ module.exports = Marionette.Layout.extend({
}
}
} ,
} ,
_onLoadMore : function ( ) {
_onLoadMore : function ( ) {
var showingAll = this . resultCollectionView . showMore ( ) ;
var showingAll = this . resultCollectionView . showMore ( ) ;
this . ui . searchBar . show ( ) ;
this . ui . searchBar . show ( ) ;
@ -156,7 +150,7 @@ module.exports = Marionette.Layout.extend({
}
}
} ,
} ,
_listSelected : function ( ) {
_listSelected : function ( ) {
var rootFolderValue = this . ui . listSelection . val ( ) ;
var rootFolderValue = this . ui . listSelection . val ( ) ;
if ( rootFolderValue === 'addNew' ) {
if ( rootFolderValue === 'addNew' ) {
//var rootFolderLayout = new SchemaModal(this.listCollection);
//var rootFolderLayout = new SchemaModal(this.listCollection);
@ -165,27 +159,25 @@ module.exports = Marionette.Layout.extend({
}
}
} ,
} ,
_fetchList : function ( ) {
_fetchList : function ( ) {
var self = this ;
var self = this ;
var listId = this . ui . listSelection . val ( ) ;
var listId = this . ui . listSelection . val ( ) ;
this . fetchResult . show ( new LoadingView ( ) ) ;
this . fetchResult . show ( new LoadingView ( ) ) ;
this . currentFetchPromise = this . collection . fetch (
this . currentFetchPromise = this . collection . fetch ( { data : { listId : listId } } )
{ data : { listId : listId } }
)
this . currentFetchPromise . fail ( function ( ) {
this . currentFetchPromise . fail ( function ( ) {
self . _showError ( ) ;
self . _showError ( ) ;
} ) ;
} ) ;
} ,
} ,
_listsUpdated : function ( ) {
_listsUpdated : function ( ) {
this . templateHelpers . lists = this . listCollection . toJSON ( ) ;
this . templateHelpers . lists = this . listCollection . toJSON ( ) ;
this . render ( ) ;
this . render ( ) ;
} ,
} ,
_importSelected : function ( ) {
_importSelected : function ( ) {
var selected = this . importGrid . getSelectedModels ( ) ;
var selected = this . importGrid . getSelectedModels ( ) ;
// console.log(selected);
// console.log(selected);
var promise = MoviesCollection . importFromList ( selected ) ;
var promise = MoviesCollection . importFromList ( selected ) ;
@ -193,17 +185,17 @@ module.exports = Marionette.Layout.extend({
this . ui . importSelected . addClass ( 'disabled' ) ;
this . ui . importSelected . addClass ( 'disabled' ) ;
Messenger . show ( {
Messenger . show ( {
message : "Importing {0} movies. Don't close this browser window until it has finished" . format ( selected . length ) ,
message : "Importing {0} movies. Don't close this browser window until it has finished" . format ( selected . length ) ,
hideOnNavigate : false ,
hideOnNavigate : false ,
hideAfter : 30 ,
hideAfter : 30 ,
type : "error"
type : "error"
} ) ;
} ) ;
promise . done ( function ( ) {
promise . done ( function ( ) {
Messenger . show ( {
Messenger . show ( {
message : "Imported movies from list." ,
message : "Imported movies from list." ,
hideAfter : 8 ,
hideAfter : 8 ,
hideOnNavigate : true
hideOnNavigate : true
} ) ;
} ) ;
} ) ;
} ) ;
/ * f o r ( m i n s e l e c t e d ) {
/ * f o r ( m i n s e l e c t e d ) {
@ -215,7 +207,7 @@ module.exports = Marionette.Layout.extend({
//MoviesCollection.save();
//MoviesCollection.save();
} ,
} ,
_clearResults : function ( ) {
_clearResults : function ( ) {
if ( ! this . isExisting ) {
if ( ! this . isExisting ) {
this . searchResult . show ( new EmptyView ( ) ) ;
this . searchResult . show ( new EmptyView ( ) ) ;
@ -224,14 +216,14 @@ module.exports = Marionette.Layout.extend({
}
}
} ,
} ,
_showResults : function ( ) {
_showResults : function ( ) {
if ( this . collection . length === 0 ) {
if ( this . collection . length === 0 ) {
this . fetchResult . show ( new NotFoundView ( { term : "" } ) ) ;
this . fetchResult . show ( new NotFoundView ( { term : "" } ) ) ;
} else {
} else {
this . importGrid = new Backgrid . Grid ( {
this . importGrid = new Backgrid . Grid ( {
collection : this . collection ,
collection : this . collection ,
columns : this . columns ,
columns : this . columns ,
className : 'table table-hover'
className : 'table table-hover'
} ) ;
} ) ;
this . fetchResult . show ( this . importGrid ) ;
this . fetchResult . show ( this . importGrid ) ;
this . ui . importSelected . show ( ) ;
this . ui . importSelected . show ( ) ;
@ -239,7 +231,7 @@ module.exports = Marionette.Layout.extend({
} ,
} ,
_abortExistingSearch : function ( ) {
_abortExistingSearch : function ( ) {
if ( this . currentSearchPromise && this . currentSearchPromise . readyState > 0 && this . currentSearchPromise . readyState < 4 ) {
if ( this . currentSearchPromise && this . currentSearchPromise . readyState > 0 && this . currentSearchPromise . readyState < 4 ) {
console . log ( 'aborting previous pending search request.' ) ;
console . log ( 'aborting previous pending search request.' ) ;
this . currentSearchPromise . abort ( ) ;
this . currentSearchPromise . abort ( ) ;
@ -248,7 +240,7 @@ module.exports = Marionette.Layout.extend({
}
}
} ,
} ,
_showError : function ( ) {
_showError : function ( ) {
this . fetchResult . show ( new ErrorView ( { term : "" } ) ) ;
this . fetchResult . show ( new ErrorView ( { term : "" } ) ) ;
}
}
} ) ;
} ) ;