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.
Readarr/UI/AddSeries/AddSeriesView.js

82 lines
2.7 KiB

'use strict';
11 years ago
define(
[
'marionette',
'AddSeries/Collection',
'AddSeries/SearchResultCollectionView',
'Shared/SpinnerView'
], function (Marionette, AddSeriesCollection, SearchResultCollectionView, SpinnerView) {
return Marionette.Layout.extend({
template: 'AddSeries/AddSeriesTemplate',
ui: {
seriesSearch: '.x-series-search',
searchBar : '.x-search-bar',
loadMore : '.x-load-more'
11 years ago
},
regions: {
searchResult: '#search-result'
},
initialize: function (options) {
11 years ago
this.collection = new AddSeriesCollection();
this.isExisting = options.isExisting;
11 years ago
},
onRender: function () {
var self = this;
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.resultView = new SearchResultCollectionView({
fullResult: this.collection,
isExisting: this.isExisting
});
11 years ago
},
search: function (options) {
var self = this;
this.abortExistingRequest();
this.collection.reset();
if (!options || options.term === '') {
this.searchResult.close();
11 years ago
}
else {
this.searchResult.show(new SpinnerView());
this.currentSearchRequest = this.collection.fetch({
data: { term: options.term }
}).done(function () {
self.searchResult.show(self.resultView);
if (!self.showingAll && self.isExisting) {
self.ui.loadMore.show();
}
});
11 years ago
}
},
11 years ago
abortExistingRequest: function () {
if (this.currentSearchRequest && this.currentSearchRequest.readyState > 0 && this.currentSearchRequest.readyState < 4) {
console.log('aborting previous pending search request.');
this.currentSearchRequest.abort();
}
}
11 years ago
});
});