Sonarr/UI/AddSeries/AddSeriesView.js

86 lines
2.8 KiB
JavaScript
Raw Normal View History

2013-06-22 06:24:24 +00:00
'use strict';
2013-06-21 01:43:58 +00:00
define(
[
'marionette',
'AddSeries/Collection',
'AddSeries/SearchResultCollectionView',
'Shared/SpinnerView',
'app',
'AddSeries/RootFolders/Collection',
'AddSeries/SearchResultView',
'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'
2013-06-21 01:43:58 +00:00
},
regions: {
searchResult: '#search-result'
},
initialize: function (options) {
2013-06-21 01:43:58 +00:00
this.collection = new AddSeriesCollection();
this.isExisting = options.isExisting;
2013-06-21 01:43:58 +00:00
},
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
});
2013-06-21 01:43:58 +00:00
},
2013-01-27 02:14:42 +00:00
search: function (options) {
var self = this;
2013-01-27 02:14:42 +00:00
this.abortExistingRequest();
this.collection.reset();
2013-02-01 03:15:19 +00:00
if (!options || options.term === '') {
this.searchResult.close();
2013-06-21 01:43:58 +00:00
}
else {
this.searchResult.show(new SpinnerView());
this.currentSearchRequest = this.collection.fetch({
data: { term: options.term }
}).done(function () {
self.searchResult.show(self.resultView);
2013-01-27 02:14:42 +00:00
if (!self.showingAll && self.isExisting) {
self.ui.loadMore.show();
}
});
2013-06-21 01:43:58 +00:00
}
},
2013-06-21 01:43:58 +00:00
abortExistingRequest: function () {
if (this.currentSearchRequest && this.currentSearchRequest.readyState > 0 && this.currentSearchRequest.readyState < 4) {
console.log('aborting previous pending search request.');
this.currentSearchRequest.abort();
}
}
2013-06-21 01:43:58 +00:00
});
});