You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/UI/AddSeries/AddSeriesView.js

112 lines
3.7 KiB

'use strict';
12 years ago
define(
[
'app',
12 years ago
'marionette',
'AddSeries/Collection',
'AddSeries/SearchResultCollectionView',
'Shared/SpinnerView'
], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, SpinnerView) {
12 years ago
return Marionette.Layout.extend({
template: 'AddSeries/AddSeriesTemplate',
regions: {
searchResult: '#search-result'
},
12 years ago
ui: {
seriesSearch: '.x-series-search',
searchBar : '.x-search-bar',
loadMore : '.x-load-more'
12 years ago
},
events: {
'click .x-load-more': '_onLoadMore'
12 years ago
},
_onLoadMore: function () {
this.ui.loadMore.hide();
this.ui.searchBar.show();
this.resultCollectionView.showAll();
},
initialize: function (options) {
this.collection = new AddSeriesCollection({unmappedFolderModel: this.model});
this.isExisting = options.isExisting;
if (this.isExisting) {
this.className = 'existing-series';
this.listenTo(App.vent, App.Events.SeriesAdded, this._onSeriesAdded);
}
else {
this.className = 'new-series';
}
},
_onSeriesAdded: function (options) {
if (options.series.get('path') === this.model.get('folder').path) {
this.close();
}
12 years ago
},
onRender: function () {
var self = this;
this.$el.addClass(this.className);
12 years ago
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, {
term: self.ui.seriesSearch.val()
});
}, 500));
});
if (this.isExisting) {
this.ui.searchBar.hide();
}
this.resultCollectionView = new SearchResultCollectionView({
collection: this.collection,
isExisting: this.isExisting
});
12 years ago
},
search: function (options) {
var self = this;
this.abortExistingSearch();
this.collection.reset();
if (!options || options.term === '') {
this.searchResult.close();
12 years ago
}
else {
this.searchResult.show(new SpinnerView());
this.currentSearchPromise = this.collection.fetch({
data: { term: options.term }
}).done(function () {
if (!self.isClosed) {
self.searchResult.show(self.resultCollectionView);
if (!self.showingAll && self.isExisting) {
self.ui.loadMore.show();
}
}
});
12 years ago
}
return this.currentSearchPromise;
12 years ago
},
abortExistingSearch: function () {
if (this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) {
12 years ago
console.log('aborting previous pending search request.');
this.currentSearchPromise.abort();
12 years ago
}
}
12 years ago
});
});