From 329786365dd8fa37e471b4fc38ecf0abdae9bc92 Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Tue, 3 Jan 2017 12:52:09 +0100 Subject: [PATCH] Fixed adding multiple movies. --- src/UI/AddMovies/AddMoviesView.js | 8 +++++--- src/UI/AddMovies/SearchResultCollectionView.js | 14 +++++++++++++- src/UI/AddMovies/SearchResultViewTemplate.hbs | 6 +++++- src/UI/Handlebars/Helpers/Series.js | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/UI/AddMovies/AddMoviesView.js b/src/UI/AddMovies/AddMoviesView.js index 1694a9ffc..e83aad42f 100644 --- a/src/UI/AddMovies/AddMoviesView.js +++ b/src/UI/AddMovies/AddMoviesView.js @@ -120,16 +120,17 @@ module.exports = Marionette.Layout.extend({ }, _onMoviesAdded : function(options) { - if (this.isExisting && options.movies.get('path') === this.model.get('folder').path) { + if (this.isExisting && options.movie.get('path') === this.model.get('folder').path) { this.close(); } else if (!this.isExisting) { - this.collection.term = ''; + this.resultCollectionView.setExisting(options.movie.get('imdbId')) + /*this.collection.term = ''; this.collection.reset(); this._clearResults(); this.ui.moviesSearch.val(''); - this.ui.moviesSearch.focus(); + this.ui.moviesSearch.focus();*/ //TODO: Maybe add option wheter to clear search result. } }, @@ -143,6 +144,7 @@ module.exports = Marionette.Layout.extend({ }, _clearResults : function() { + if (!this.isExisting) { this.searchResult.show(new EmptyView()); } else { diff --git a/src/UI/AddMovies/SearchResultCollectionView.js b/src/UI/AddMovies/SearchResultCollectionView.js index e533085ac..ac1257697 100644 --- a/src/UI/AddMovies/SearchResultCollectionView.js +++ b/src/UI/AddMovies/SearchResultCollectionView.js @@ -21,9 +21,21 @@ module.exports = Marionette.CollectionView.extend({ return this.showing >= this.collection.length; }, + setExisting : function(imdbid) { + var movies = this.collection.where({ imdbId : imdbid }); + 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) { if (!this.isExisting || index < this.showing || index === 0) { collectionView.$el.append(itemView.el); } } -}); \ No newline at end of file +}); diff --git a/src/UI/AddMovies/SearchResultViewTemplate.hbs b/src/UI/AddMovies/SearchResultViewTemplate.hbs index 41845cdee..87e1167da 100644 --- a/src/UI/AddMovies/SearchResultViewTemplate.hbs +++ b/src/UI/AddMovies/SearchResultViewTemplate.hbs @@ -2,7 +2,11 @@
@@ -74,7 +78,7 @@ -
diff --git a/src/UI/Handlebars/Helpers/Series.js b/src/UI/Handlebars/Helpers/Series.js index fc96495a0..016279e6e 100644 --- a/src/UI/Handlebars/Helpers/Series.js +++ b/src/UI/Handlebars/Helpers/Series.js @@ -19,6 +19,22 @@ Handlebars.registerHelper('poster', function() { return new Handlebars.SafeString(''.format(placeholder)); }); +Handlebars.registerHelper('remotePoster', function() { + var placeholder = StatusModel.get('urlBase') + '/Content/Images/poster-dark.png'; + var poster = this.remotePoster; + + if (poster) { + if (!poster.match(/^https?:\/\//)) { + return new Handlebars.SafeString(''.format(Handlebars.helpers.defaultImg.call(null, poster, 250))); + } else { + var url = poster.replace(/^https?\:/, 'https://'); //IMDb posters need https to work, k? + return new Handlebars.SafeString(''.format(Handlebars.helpers.defaultImg.call(null, url))); + } + } + + return new Handlebars.SafeString(''.format(placeholder)); +}) + Handlebars.registerHelper('traktUrl', function() { return 'http://trakt.tv/search/tvdb/' + this.tvdbId + '?id_type=show'; });