Add new series will clear results and re-focus search box

This commit is contained in:
Mark McDowall 2013-09-28 23:29:52 -07:00
parent 0ee82feab7
commit 5d8bc50c77
8 changed files with 49 additions and 40 deletions

View File

@ -15,8 +15,7 @@ define(
ExistingSeriesCollectionView, ExistingSeriesCollectionView,
AddSeriesView, AddSeriesView,
QualityProfileCollection, QualityProfileCollection,
RootFolderCollection, RootFolderCollection) {
SeriesCollection) {
return Marionette.Layout.extend({ return Marionette.Layout.extend({
template: 'AddSeries/AddSeriesLayoutTemplate', template: 'AddSeries/AddSeriesLayoutTemplate',
@ -35,8 +34,6 @@ define(
}, },
initialize: function () { initialize: function () {
SeriesCollection.fetch();
QualityProfileCollection.fetch(); QualityProfileCollection.fetch();
RootFolderCollection.promise = RootFolderCollection.fetch(); RootFolderCollection.promise = RootFolderCollection.fetch();
}, },

View File

@ -3,14 +3,14 @@ define(
[ [
'app', 'app',
'marionette', 'marionette',
'AddSeries/Collection', 'AddSeries/AddSeriesCollection',
'AddSeries/SearchResultCollectionView', 'AddSeries/SearchResultCollectionView',
'AddSeries/NotFoundView', 'AddSeries/NotFoundView',
'Shared/LoadingView', 'Shared/LoadingView',
'underscore' 'underscore'
], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, NotFoundView, LoadingView, _) { ], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, NotFoundView, LoadingView, _) {
return Marionette.Layout.extend({ return Marionette.Layout.extend({
template: 'AddSeries/AddSeriesTemplate', template: 'AddSeries/AddSeriesViewTemplate',
regions: { regions: {
searchResult: '#search-result' searchResult: '#search-result'
@ -36,12 +36,12 @@ define(
if (this.isExisting) { if (this.isExisting) {
this.className = 'existing-series'; this.className = 'existing-series';
this.listenTo(App.vent, App.Events.SeriesAdded, this._onSeriesAdded);
} }
else { else {
this.className = 'new-series'; this.className = 'new-series';
} }
this.listenTo(App.vent, App.Events.SeriesAdded, this._onSeriesAdded);
this.listenTo(this.collection, 'sync', this._showResults); this.listenTo(this.collection, 'sync', this._showResults);
this.resultCollectionView = new SearchResultCollectionView({ this.resultCollectionView = new SearchResultCollectionView({
@ -52,21 +52,6 @@ define(
this.throttledSearch = _.debounce(this.search, 1000, {trailing: true}).bind(this); 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 () { onRender: function () {
var self = this; var self = this;
@ -77,7 +62,7 @@ define(
self._abortExistingSearch(); self._abortExistingSearch();
self.throttledSearch({ self.throttledSearch({
term: self.ui.seriesSearch.val() term: self.ui.seriesSearch.val()
}) });
}); });
if (this.isExisting) { if (this.isExisting) {
@ -87,6 +72,7 @@ define(
onShow: function () { onShow: function () {
this.searchResult.show(this.resultCollectionView); this.searchResult.show(this.resultCollectionView);
this.ui.seriesSearch.focus();
}, },
search: function (options) { search: function (options) {
@ -106,6 +92,28 @@ define(
return this.currentSearchPromise; 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 () { _showResults: function () {
if (!this.isClosed) { if (!this.isClosed) {

View File

@ -29,9 +29,9 @@ define(
this.addItemView(model, this.getItemView(), index); this.addItemView(model, this.getItemView(), index);
this.children.findByModel(model) this.children.findByModel(model)
.search({term: folderName}) .search({term: folderName})
.always((function () { .always(function () {
self._showAndSearch(currentIndex + 1); self._showAndSearch(currentIndex + 1);
})); });
} }
}, },

View File

@ -2,8 +2,7 @@
define( define(
[ [
'marionette', 'marionette',
'AddSeries/SearchResultView', 'AddSeries/SearchResultView'
], function (Marionette, SearchResultView) { ], function (Marionette, SearchResultView) {
return Marionette.CollectionView.extend({ return Marionette.CollectionView.extend({

View File

@ -38,6 +38,9 @@ define(
throw 'model is required'; throw 'model is required';
} }
this.templateHelpers = {};
this._configureTemplateHelpers();
this.listenTo(App.vent, Config.Events.ConfigUpdatedEvent, this._onConfigUpdated); this.listenTo(App.vent, Config.Events.ConfigUpdatedEvent, this._onConfigUpdated);
this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'change', this.render);
this.listenTo(RootFolders, 'all', this.render); this.listenTo(RootFolders, 'all', this.render);
@ -72,22 +75,18 @@ define(
}); });
}, },
serializeData: function () { _configureTemplateHelpers: function () {
var data = this.model.toJSON();
var existingSeries = SeriesCollection.where({tvdbId: this.model.get('tvdbId')}); var existingSeries = SeriesCollection.where({tvdbId: this.model.get('tvdbId')});
if (existingSeries.length > 0) { 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) { if (!this.model.get('isExisting')) {
data.rootFolders = RootFolders.toJSON(); this.templateHelpers.rootFolders = RootFolders.toJSON();
} }
return data;
}, },
_onConfigUpdated: function (options) { _onConfigUpdated: function (options) {
@ -135,17 +134,23 @@ define(
SeriesCollection.add(this.model); SeriesCollection.add(this.model);
this.model.save().done(function () {
var promise = this.model.save();
promise.done(function () {
self.close(); self.close();
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
Messenger.show({ Messenger.show({
message: 'Added: ' + self.model.get('title') message: 'Added: ' + self.model.get('title')
}); });
App.vent.trigger(App.Events.SeriesAdded, { series: self.model }); 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');
});
} }
}); });