|
|
@ -5,8 +5,9 @@ define(
|
|
|
|
'marionette',
|
|
|
|
'marionette',
|
|
|
|
'AddSeries/Collection',
|
|
|
|
'AddSeries/Collection',
|
|
|
|
'AddSeries/SearchResultCollectionView',
|
|
|
|
'AddSeries/SearchResultCollectionView',
|
|
|
|
'Shared/LoadingView'
|
|
|
|
'AddSeries/NotFoundView',
|
|
|
|
], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, LoadingView) {
|
|
|
|
'Shared/LoadingView',
|
|
|
|
|
|
|
|
], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, NotFoundView, LoadingView) {
|
|
|
|
return Marionette.Layout.extend({
|
|
|
|
return Marionette.Layout.extend({
|
|
|
|
template: 'AddSeries/AddSeriesTemplate',
|
|
|
|
template: 'AddSeries/AddSeriesTemplate',
|
|
|
|
|
|
|
|
|
|
|
@ -44,6 +45,8 @@ define(
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
this.className = 'new-series';
|
|
|
|
this.className = 'new-series';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.listenTo(this.collection, 'sync', this._showResults);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
_onSeriesAdded: function (options) {
|
|
|
|
_onSeriesAdded: function (options) {
|
|
|
@ -78,8 +81,6 @@ define(
|
|
|
|
|
|
|
|
|
|
|
|
search: function (options) {
|
|
|
|
search: function (options) {
|
|
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.abortExistingSearch();
|
|
|
|
this.abortExistingSearch();
|
|
|
|
|
|
|
|
|
|
|
|
this.collection.reset();
|
|
|
|
this.collection.reset();
|
|
|
@ -89,20 +90,29 @@ define(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
this.searchResult.show(new LoadingView());
|
|
|
|
this.searchResult.show(new LoadingView());
|
|
|
|
|
|
|
|
this.collection.term = options.term;
|
|
|
|
this.currentSearchPromise = this.collection.fetch({
|
|
|
|
this.currentSearchPromise = this.collection.fetch({
|
|
|
|
data: { term: options.term }
|
|
|
|
data: { term: options.term }
|
|
|
|
}).done(function () {
|
|
|
|
});
|
|
|
|
if (!self.isClosed) {
|
|
|
|
|
|
|
|
self.searchResult.show(self.resultCollectionView);
|
|
|
|
|
|
|
|
if (!self.showingAll && self.isExisting) {
|
|
|
|
|
|
|
|
self.ui.loadMore.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.currentSearchPromise;
|
|
|
|
return this.currentSearchPromise;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_showResults: function () {
|
|
|
|
|
|
|
|
if (!this.isClosed) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.collection.length === 0) {
|
|
|
|
|
|
|
|
this.searchResult.show(new NotFoundView({term: this.collection.term}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
this.searchResult.show(this.resultCollectionView);
|
|
|
|
|
|
|
|
if (!this.showingAll && this.isExisting) {
|
|
|
|
|
|
|
|
this.ui.loadMore.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
abortExistingSearch: function () {
|
|
|
|
abortExistingSearch: function () {
|
|
|
|
if (this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) {
|
|
|
|
if (this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) {
|
|
|
|
console.log('aborting previous pending search request.');
|
|
|
|
console.log('aborting previous pending search request.');
|
|
|
|