1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/UI/AddSeries/AddSeriesView.js

82 lines
2.7 KiB
JavaScript
Raw Normal View History

'use strict';
2013-06-21 04:43:58 +03:00
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'
2013-06-21 04:43:58 +03:00
},
regions: {
searchResult: '#search-result'
},
initialize: function (options) {
2013-06-21 04:43:58 +03:00
this.collection = new AddSeriesCollection();
this.isExisting = options.isExisting;
2013-06-21 04:43:58 +03: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 04:43:58 +03:00
},
2013-01-27 05:14:42 +03:00
search: function (options) {
var self = this;
2013-01-27 05:14:42 +03:00
this.abortExistingRequest();
this.collection.reset();
2013-02-01 06:15:19 +03:00
if (!options || options.term === '') {
this.searchResult.close();
2013-06-21 04:43:58 +03: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 05:14:42 +03:00
if (!self.showingAll && self.isExisting) {
self.ui.loadMore.show();
}
});
2013-06-21 04:43:58 +03:00
}
},
2013-06-21 04:43:58 +03: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 04:43:58 +03:00
});
});