add series cleanup

pull/6/head
kay.one 11 years ago
parent 07b68b17ee
commit 927dbba945

@ -7,7 +7,8 @@ define(
'AddSeries/SearchResultCollectionView',
'AddSeries/NotFoundView',
'Shared/LoadingView',
], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, NotFoundView, LoadingView) {
'underscore'
], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, NotFoundView, LoadingView, _) {
return Marionette.Layout.extend({
template: 'AddSeries/AddSeriesTemplate',
@ -25,18 +26,13 @@ define(
'click .x-load-more': '_onLoadMore'
},
_onLoadMore: function () {
var showingAll = this.resultCollectionView.showMore();
if (showingAll) {
this.ui.loadMore.hide();
this.ui.searchBar.show();
}
},
initialize: function (options) {
this.collection = new AddSeriesCollection({unmappedFolderModel: this.model});
this.isExisting = options.isExisting;
this.collection = new AddSeriesCollection();
if (this.isExisting) {
this.collection.unmappedFolderModel = this.model;
}
if (this.isExisting) {
this.className = 'existing-series';
@ -47,55 +43,65 @@ define(
}
this.listenTo(this.collection, 'sync', this._showResults);
this.resultCollectionView = new SearchResultCollectionView({
collection: this.collection,
isExisting: this.isExisting
});
this.throttledSearch = _.throttle(this.search, 1000, {trailing: true}).bind(this);
},
_onSeriesAdded: function (options) {
if (options.series.get('path') === this.model.get('folder').path) {
if (this.isExisting && options.series.get('path') === this.model.get('folder').path) {
this.close();
}
},
_onLoadMore: function () {
var showingAll = this.resultCollectionView.showMore();
if (showingAll) {
this.ui.loadMore.hide();
this.ui.searchBar.show();
}
},
onRender: function () {
var self = this;
this.$el.addClass(this.className);
this.ui.seriesSearch.data('timeout', null).keyup(function () {
window.clearTimeout(self.$el.data('timeout'));
self.$el.data('timeout', window.setTimeout(function () {
self.search.call(self, {
this.ui.seriesSearch.keyup(function () {
self.searchResult.close();
self._abortExistingSearch();
self.throttledSearch({
term: self.ui.seriesSearch.val()
});
}, 500));
})
});
if (this.isExisting) {
this.ui.searchBar.hide();
}
},
this.resultCollectionView = new SearchResultCollectionView({
collection: this.collection,
isExisting: this.isExisting
});
onShow: function () {
this.searchResult.show(this.resultCollectionView);
},
search: function (options) {
this.abortExistingSearch();
this.collection.reset();
if (!options || options.term === '') {
this.searchResult.close();
if (!options.term || options.term === this.collection.term) {
return;
}
else {
this.searchResult.show(new LoadingView());
this.collection.term = options.term;
this.currentSearchPromise = this.collection.fetch({
data: { term: options.term }
});
}
return this.currentSearchPromise;
},
_showResults: function () {
@ -113,7 +119,7 @@ define(
}
},
abortExistingSearch: function () {
_abortExistingSearch: function () {
if (this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) {
console.log('aborting previous pending search request.');
this.currentSearchPromise.abort();

@ -8,11 +8,6 @@ define(
url : window.NzbDrone.ApiRoot + '/series/lookup',
model: SeriesModel,
initialize: function (options) {
this.unmappedFolderModel = options.unmappedFolderModel;
},
parse: function (response) {
var self = this;

Loading…
Cancel
Save