diff --git a/UI/AddSeries/Collection.js b/UI/AddSeries/AddSeriesCollection.js similarity index 100% rename from UI/AddSeries/Collection.js rename to UI/AddSeries/AddSeriesCollection.js diff --git a/UI/AddSeries/AddSeriesLayout.js b/UI/AddSeries/AddSeriesLayout.js index ca577de9b..cc3c88486 100644 --- a/UI/AddSeries/AddSeriesLayout.js +++ b/UI/AddSeries/AddSeriesLayout.js @@ -15,8 +15,7 @@ define( ExistingSeriesCollectionView, AddSeriesView, QualityProfileCollection, - RootFolderCollection, - SeriesCollection) { + RootFolderCollection) { return Marionette.Layout.extend({ template: 'AddSeries/AddSeriesLayoutTemplate', @@ -35,8 +34,6 @@ define( }, initialize: function () { - - SeriesCollection.fetch(); QualityProfileCollection.fetch(); RootFolderCollection.promise = RootFolderCollection.fetch(); }, diff --git a/UI/AddSeries/addSeriesLayoutTemplate.html b/UI/AddSeries/AddSeriesLayoutTemplate.html similarity index 100% rename from UI/AddSeries/addSeriesLayoutTemplate.html rename to UI/AddSeries/AddSeriesLayoutTemplate.html diff --git a/UI/AddSeries/AddSeriesView.js b/UI/AddSeries/AddSeriesView.js index e66b1e891..957b2cabc 100644 --- a/UI/AddSeries/AddSeriesView.js +++ b/UI/AddSeries/AddSeriesView.js @@ -3,14 +3,14 @@ define( [ 'app', 'marionette', - 'AddSeries/Collection', + 'AddSeries/AddSeriesCollection', 'AddSeries/SearchResultCollectionView', 'AddSeries/NotFoundView', 'Shared/LoadingView', 'underscore' ], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, NotFoundView, LoadingView, _) { return Marionette.Layout.extend({ - template: 'AddSeries/AddSeriesTemplate', + template: 'AddSeries/AddSeriesViewTemplate', regions: { searchResult: '#search-result' @@ -36,12 +36,12 @@ define( if (this.isExisting) { this.className = 'existing-series'; - this.listenTo(App.vent, App.Events.SeriesAdded, this._onSeriesAdded); } else { this.className = 'new-series'; } + this.listenTo(App.vent, App.Events.SeriesAdded, this._onSeriesAdded); this.listenTo(this.collection, 'sync', this._showResults); this.resultCollectionView = new SearchResultCollectionView({ @@ -52,21 +52,6 @@ define( this.throttledSearch = _.debounce(this.search, 1000, {trailing: true}).bind(this); }, - _onSeriesAdded: function (options) { - if (this.isExisting && options.series.get('path') === this.model.get('folder').path) { - this.close(); - } - }, - - _onLoadMore: function () { - var showingAll = this.resultCollectionView.showMore(); - this.ui.searchBar.show(); - - if (showingAll) { - this.ui.loadMore.hide(); - } - }, - onRender: function () { var self = this; @@ -77,7 +62,7 @@ define( self._abortExistingSearch(); self.throttledSearch({ term: self.ui.seriesSearch.val() - }) + }); }); if (this.isExisting) { @@ -87,6 +72,7 @@ define( onShow: function () { this.searchResult.show(this.resultCollectionView); + this.ui.seriesSearch.focus(); }, search: function (options) { @@ -106,6 +92,28 @@ define( return this.currentSearchPromise; }, + _onSeriesAdded: function (options) { + if (this.isExisting && options.series.get('path') === this.model.get('folder').path) { + this.close(); + } + + else if (!this.isExisting) { + this.collection.reset(); + this.searchResult.show(this.resultCollectionView); + this.ui.seriesSearch.val(''); + this.ui.seriesSearch.focus(); + } + }, + + _onLoadMore: function () { + var showingAll = this.resultCollectionView.showMore(); + this.ui.searchBar.show(); + + if (showingAll) { + this.ui.loadMore.hide(); + } + }, + _showResults: function () { if (!this.isClosed) { diff --git a/UI/AddSeries/AddSeriesTemplate.html b/UI/AddSeries/AddSeriesViewTemplate.html similarity index 100% rename from UI/AddSeries/AddSeriesTemplate.html rename to UI/AddSeries/AddSeriesViewTemplate.html diff --git a/UI/AddSeries/Existing/CollectionView.js b/UI/AddSeries/Existing/CollectionView.js index 74108d33d..849d19fd5 100644 --- a/UI/AddSeries/Existing/CollectionView.js +++ b/UI/AddSeries/Existing/CollectionView.js @@ -29,9 +29,9 @@ define( this.addItemView(model, this.getItemView(), index); this.children.findByModel(model) .search({term: folderName}) - .always((function () { + .always(function () { self._showAndSearch(currentIndex + 1); - })); + }); } }, diff --git a/UI/AddSeries/SearchResultCollectionView.js b/UI/AddSeries/SearchResultCollectionView.js index e1d912f01..53d0a8936 100644 --- a/UI/AddSeries/SearchResultCollectionView.js +++ b/UI/AddSeries/SearchResultCollectionView.js @@ -2,8 +2,7 @@ define( [ 'marionette', - 'AddSeries/SearchResultView', - + 'AddSeries/SearchResultView' ], function (Marionette, SearchResultView) { return Marionette.CollectionView.extend({ diff --git a/UI/AddSeries/SearchResultView.js b/UI/AddSeries/SearchResultView.js index 3f8c6ec33..218bf0ff0 100644 --- a/UI/AddSeries/SearchResultView.js +++ b/UI/AddSeries/SearchResultView.js @@ -38,6 +38,9 @@ define( throw 'model is required'; } + this.templateHelpers = {}; + this._configureTemplateHelpers(); + this.listenTo(App.vent, Config.Events.ConfigUpdatedEvent, this._onConfigUpdated); this.listenTo(this.model, 'change', this.render); this.listenTo(RootFolders, 'all', this.render); @@ -72,22 +75,18 @@ define( }); }, - serializeData: function () { - var data = this.model.toJSON(); - + _configureTemplateHelpers: function () { var existingSeries = SeriesCollection.where({tvdbId: this.model.get('tvdbId')}); if (existingSeries.length > 0) { - data.existing = existingSeries[0].toJSON(); + this.templateHelpers.existing = existingSeries[0].toJSON(); } - data.qualityProfiles = QualityProfiles.toJSON(); + this.templateHelpers.qualityProfiles = QualityProfiles.toJSON(); - if (!data.isExisting) { - data.rootFolders = RootFolders.toJSON(); + if (!this.model.get('isExisting')) { + this.templateHelpers.rootFolders = RootFolders.toJSON(); } - - return data; }, _onConfigUpdated: function (options) { @@ -135,17 +134,23 @@ define( SeriesCollection.add(this.model); - this.model.save().done(function () { + + var promise = this.model.save(); + + promise.done(function () { self.close(); icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); + Messenger.show({ message: 'Added: ' + self.model.get('title') }); App.vent.trigger(App.Events.SeriesAdded, { series: self.model }); - }).fail(function () { - icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); - }); + }); + + promise.fail(function () { + icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); + }); } });