mirror of https://github.com/Radarr/Radarr
Fix only one movie showing. Fix more button not showing up.
This commit is contained in:
parent
c5ca2babf7
commit
4263808360
|
@ -9,178 +9,178 @@ var ErrorView = require('./ErrorView');
|
|||
var LoadingView = require('../Shared/LoadingView');
|
||||
|
||||
module.exports = Marionette.Layout.extend({
|
||||
template : 'AddMovies/AddMoviesViewTemplate',
|
||||
template : 'AddMovies/AddMoviesViewTemplate',
|
||||
|
||||
regions : {
|
||||
searchResult : '#search-result'
|
||||
},
|
||||
regions : {
|
||||
searchResult : '#search-result'
|
||||
},
|
||||
|
||||
ui : {
|
||||
moviesSearch : '.x-movies-search',
|
||||
searchBar : '.x-search-bar',
|
||||
loadMore : '.x-load-more'
|
||||
},
|
||||
ui : {
|
||||
moviesSearch : '.x-movies-search',
|
||||
searchBar : '.x-search-bar',
|
||||
loadMore : '.x-load-more'
|
||||
},
|
||||
|
||||
events : {
|
||||
'click .x-load-more' : '_onLoadMore'
|
||||
},
|
||||
events : {
|
||||
'click .x-load-more' : '_onLoadMore'
|
||||
},
|
||||
|
||||
initialize : function(options) {
|
||||
console.log(options);
|
||||
|
||||
this.isExisting = options.isExisting;
|
||||
this.collection = new AddMoviesCollection();
|
||||
initialize : function(options) {
|
||||
console.log(options);
|
||||
|
||||
if (this.isExisting) {
|
||||
this.collection.unmappedFolderModel = this.model;
|
||||
}
|
||||
this.isExisting = options.isExisting;
|
||||
this.collection = new AddMoviesCollection();
|
||||
|
||||
if (this.isExisting) {
|
||||
this.className = 'existing-movies';
|
||||
} else {
|
||||
this.className = 'new-movies';
|
||||
}
|
||||
if (this.isExisting) {
|
||||
this.collection.unmappedFolderModel = this.model;
|
||||
}
|
||||
|
||||
this.listenTo(vent, vent.Events.MoviesAdded, this._onMoviesAdded);
|
||||
this.listenTo(this.collection, 'sync', this._showResults);
|
||||
if (this.isExisting) {
|
||||
this.className = 'existing-movies';
|
||||
} else {
|
||||
this.className = 'new-movies';
|
||||
}
|
||||
|
||||
this.resultCollectionView = new SearchResultCollectionView({
|
||||
collection : this.collection,
|
||||
isExisting : this.isExisting
|
||||
});
|
||||
this.listenTo(vent, vent.Events.MoviesAdded, this._onMoviesAdded);
|
||||
this.listenTo(this.collection, 'sync', this._showResults);
|
||||
|
||||
this.throttledSearch = _.debounce(this.search, 1000, { trailing : true }).bind(this);
|
||||
},
|
||||
this.resultCollectionView = new SearchResultCollectionView({
|
||||
collection : this.collection,
|
||||
isExisting : this.isExisting
|
||||
});
|
||||
|
||||
onRender : function() {
|
||||
var self = this;
|
||||
this.throttledSearch = _.debounce(this.search, 1000, { trailing : true }).bind(this);
|
||||
},
|
||||
|
||||
this.$el.addClass(this.className);
|
||||
onRender : function() {
|
||||
var self = this;
|
||||
|
||||
this.ui.moviesSearch.keyup(function(e) {
|
||||
this.$el.addClass(this.className);
|
||||
|
||||
if (_.contains([
|
||||
9,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
33,
|
||||
34,
|
||||
35,
|
||||
36,
|
||||
37,
|
||||
38,
|
||||
39,
|
||||
40,
|
||||
91,
|
||||
92,
|
||||
93
|
||||
], e.keyCode)) {
|
||||
return;
|
||||
}
|
||||
this.ui.moviesSearch.keyup(function(e) {
|
||||
|
||||
self._abortExistingSearch();
|
||||
self.throttledSearch({
|
||||
term : self.ui.moviesSearch.val()
|
||||
});
|
||||
});
|
||||
if (_.contains([
|
||||
9,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
33,
|
||||
34,
|
||||
35,
|
||||
36,
|
||||
37,
|
||||
38,
|
||||
39,
|
||||
40,
|
||||
91,
|
||||
92,
|
||||
93
|
||||
], e.keyCode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._clearResults();
|
||||
self._abortExistingSearch();
|
||||
self.throttledSearch({
|
||||
term : self.ui.moviesSearch.val()
|
||||
});
|
||||
});
|
||||
|
||||
if (this.isExisting) {
|
||||
this.ui.searchBar.hide();
|
||||
}
|
||||
},
|
||||
this._clearResults();
|
||||
|
||||
onShow : function() {
|
||||
this.ui.moviesSearch.focus();
|
||||
},
|
||||
if (this.isExisting) {
|
||||
this.ui.searchBar.hide();
|
||||
}
|
||||
},
|
||||
|
||||
search : function(options) {
|
||||
var self = this;
|
||||
onShow : function() {
|
||||
this.ui.moviesSearch.focus();
|
||||
},
|
||||
|
||||
this.collection.reset();
|
||||
search : function(options) {
|
||||
var self = this;
|
||||
|
||||
if (!options.term || options.term === this.collection.term) {
|
||||
return Marionette.$.Deferred().resolve();
|
||||
}
|
||||
this.collection.reset();
|
||||
|
||||
this.searchResult.show(new LoadingView());
|
||||
this.collection.term = options.term;
|
||||
this.currentSearchPromise = this.collection.fetch({
|
||||
data : { term : options.term }
|
||||
});
|
||||
if (!options.term || options.term === this.collection.term) {
|
||||
return Marionette.$.Deferred().resolve();
|
||||
}
|
||||
|
||||
this.currentSearchPromise.fail(function() {
|
||||
self._showError();
|
||||
});
|
||||
this.searchResult.show(new LoadingView());
|
||||
this.collection.term = options.term;
|
||||
this.currentSearchPromise = this.collection.fetch({
|
||||
data : { term : options.term }
|
||||
});
|
||||
|
||||
return this.currentSearchPromise;
|
||||
},
|
||||
this.currentSearchPromise.fail(function() {
|
||||
self._showError();
|
||||
});
|
||||
|
||||
_onMoviesAdded : function(options) {
|
||||
if (this.isExisting && options.movie.get('path') === this.model.get('folder').path) {
|
||||
this.close();
|
||||
}
|
||||
return this.currentSearchPromise;
|
||||
},
|
||||
|
||||
else if (!this.isExisting) {
|
||||
this.resultCollectionView.setExisting(options.movie.get('tmdbId'));
|
||||
/*this.collection.term = '';
|
||||
this.collection.reset();
|
||||
this._clearResults();
|
||||
this.ui.moviesSearch.val('');
|
||||
this.ui.moviesSearch.focus();*/ //TODO: Maybe add option wheter to clear search result.
|
||||
}
|
||||
},
|
||||
_onMoviesAdded : function(options) {
|
||||
if (this.isExisting && options.movie.get('path') === this.model.get('folder').path) {
|
||||
this.close();
|
||||
}
|
||||
|
||||
_onLoadMore : function() {
|
||||
var showingAll = this.resultCollectionView.showMore();
|
||||
this.ui.searchBar.show();
|
||||
else if (!this.isExisting) {
|
||||
this.resultCollectionView.setExisting(options.movie.get('tmdbId'));
|
||||
/*this.collection.term = '';
|
||||
this.collection.reset();
|
||||
this._clearResults();
|
||||
this.ui.moviesSearch.val('');
|
||||
this.ui.moviesSearch.focus();*/ //TODO: Maybe add option wheter to clear search result.
|
||||
}
|
||||
},
|
||||
|
||||
if (showingAll) {
|
||||
this.ui.loadMore.hide();
|
||||
}
|
||||
},
|
||||
_onLoadMore : function() {
|
||||
var showingAll = this.resultCollectionView.showMore();
|
||||
this.ui.searchBar.show();
|
||||
|
||||
_clearResults : function() {
|
||||
if (showingAll) {
|
||||
this.ui.loadMore.hide();
|
||||
}
|
||||
},
|
||||
|
||||
if (!this.isExisting) {
|
||||
this.searchResult.show(new EmptyView());
|
||||
} else {
|
||||
this.searchResult.close();
|
||||
}
|
||||
},
|
||||
_clearResults : function() {
|
||||
|
||||
_showResults : function() {
|
||||
if (!this.isClosed) {
|
||||
if (this.collection.length === 0) {
|
||||
this.ui.searchBar.show();
|
||||
this.searchResult.show(new NotFoundView({ term : this.collection.term }));
|
||||
} else {
|
||||
this.searchResult.show(this.resultCollectionView);
|
||||
if (!this.showingAll && this.isExisting) {
|
||||
this.ui.loadMore.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
if (!this.isExisting) {
|
||||
this.searchResult.show(new EmptyView());
|
||||
} else {
|
||||
this.searchResult.close();
|
||||
}
|
||||
},
|
||||
|
||||
_abortExistingSearch : function() {
|
||||
if (this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) {
|
||||
console.log('aborting previous pending search request.');
|
||||
this.currentSearchPromise.abort();
|
||||
} else {
|
||||
this._clearResults();
|
||||
}
|
||||
},
|
||||
_showResults : function() {
|
||||
if (!this.isClosed) {
|
||||
if (this.collection.length === 0) {
|
||||
this.ui.searchBar.show();
|
||||
this.searchResult.show(new NotFoundView({ term : this.collection.term }));
|
||||
} else {
|
||||
this.searchResult.show(this.resultCollectionView);
|
||||
if (!this.showingAll) {
|
||||
this.ui.loadMore.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_showError : function() {
|
||||
if (!this.isClosed) {
|
||||
this.ui.searchBar.show();
|
||||
this.searchResult.show(new ErrorView({ term : this.collection.term }));
|
||||
this.collection.term = '';
|
||||
}
|
||||
}
|
||||
_abortExistingSearch : function() {
|
||||
if (this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) {
|
||||
console.log('aborting previous pending search request.');
|
||||
this.currentSearchPromise.abort();
|
||||
} else {
|
||||
this._clearResults();
|
||||
}
|
||||
},
|
||||
|
||||
_showError : function() {
|
||||
if (!this.isClosed) {
|
||||
this.ui.searchBar.show();
|
||||
this.searchResult.show(new ErrorView({ term : this.collection.term }));
|
||||
this.collection.term = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,59 +4,62 @@ var MoviesCollection = require('../Movies/MoviesCollection');
|
|||
var vent = require('vent');
|
||||
|
||||
module.exports = Marionette.CollectionView.extend({
|
||||
itemView : SearchResultView,
|
||||
itemView : SearchResultView,
|
||||
|
||||
initialize : function(options) {
|
||||
this.showExisting = true;
|
||||
this.isExisting = options.isExisting;
|
||||
this.showing = 1;
|
||||
vent.on(vent.Commands.ShowExistingCommand, this._onExistingToggle.bind(this));
|
||||
},
|
||||
initialize : function(options) {
|
||||
this.showExisting = true;
|
||||
this.isExisting = options.isExisting;
|
||||
this.showing = 5;
|
||||
if (this.isExisting) {
|
||||
this.showing = 1;
|
||||
}
|
||||
vent.on(vent.Commands.ShowExistingCommand, this._onExistingToggle.bind(this));
|
||||
},
|
||||
|
||||
_onExistingToggle : function(data) {
|
||||
this.showExisting = data.showExisting;
|
||||
_onExistingToggle : function(data) {
|
||||
this.showExisting = data.showExisting;
|
||||
|
||||
this.render();
|
||||
},
|
||||
this.render();
|
||||
},
|
||||
|
||||
showAll : function() {
|
||||
this.showingAll = true;
|
||||
this.render();
|
||||
},
|
||||
showAll : function() {
|
||||
this.showingAll = true;
|
||||
this.render();
|
||||
},
|
||||
|
||||
showMore : function() {
|
||||
this.showing += 5;
|
||||
this.render();
|
||||
showMore : function() {
|
||||
this.showing += 5;
|
||||
this.render();
|
||||
|
||||
return this.showing >= this.collection.length;
|
||||
},
|
||||
return this.showing >= this.collection.length;
|
||||
},
|
||||
|
||||
setExisting : function(tmdbid) {
|
||||
var movies = this.collection.where({ tmdbId : tmdbid });
|
||||
console.warn(movies);
|
||||
//debugger;
|
||||
if (movies.length > 0) {
|
||||
this.children.findByModel(movies[0])._configureTemplateHelpers();
|
||||
//this.children.findByModel(movies[0])._configureTemplateHelpers();
|
||||
this.children.findByModel(movies[0]).render();
|
||||
//this.templateHelpers.existing = existingMovies[0].toJSON();
|
||||
}
|
||||
},
|
||||
setExisting : function(tmdbid) {
|
||||
var movies = this.collection.where({ tmdbId : tmdbid });
|
||||
console.warn(movies);
|
||||
//debugger;
|
||||
if (movies.length > 0) {
|
||||
this.children.findByModel(movies[0])._configureTemplateHelpers();
|
||||
//this.children.findByModel(movies[0])._configureTemplateHelpers();
|
||||
this.children.findByModel(movies[0]).render();
|
||||
//this.templateHelpers.existing = existingMovies[0].toJSON();
|
||||
}
|
||||
},
|
||||
|
||||
appendHtml : function(collectionView, itemView, index) {
|
||||
var tmdbId = itemView.model.get('tmdbId');
|
||||
var existingMovies = MoviesCollection.where({ tmdbId: tmdbId });
|
||||
if(existingMovies.length > 0) {
|
||||
if(this.showExisting) {
|
||||
if (index < this.showing || index === 0) {
|
||||
collectionView.$el.append(itemView.el);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (index < this.showing || index === 0) {
|
||||
collectionView.$el.append(itemView.el);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
appendHtml : function(collectionView, itemView, index) {
|
||||
var tmdbId = itemView.model.get('tmdbId');
|
||||
var existingMovies = MoviesCollection.where({ tmdbId: tmdbId });
|
||||
if(existingMovies.length > 0) {
|
||||
if(this.showExisting) {
|
||||
if (index < this.showing || index === 0) {
|
||||
collectionView.$el.append(itemView.el);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (index < this.showing || index === 0) {
|
||||
collectionView.$el.append(itemView.el);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue