-
{{debug}}
diff --git a/UI/AddSeries/AddSeriesView.js b/UI/AddSeries/AddSeriesView.js
index c21602aed..933e964eb 100644
--- a/UI/AddSeries/AddSeriesView.js
+++ b/UI/AddSeries/AddSeriesView.js
@@ -1,32 +1,62 @@
'use strict';
define(
[
+ 'app',
'marionette',
'AddSeries/Collection',
'AddSeries/SearchResultCollectionView',
'Shared/SpinnerView'
- ], function (Marionette, AddSeriesCollection, SearchResultCollectionView, SpinnerView) {
+ ], function (App, Marionette, AddSeriesCollection, SearchResultCollectionView, SpinnerView) {
return Marionette.Layout.extend({
template: 'AddSeries/AddSeriesTemplate',
+ regions: {
+ searchResult: '#search-result'
+ },
+
ui: {
seriesSearch: '.x-series-search',
searchBar : '.x-search-bar',
loadMore : '.x-load-more'
},
- regions: {
- searchResult: '#search-result'
+ events: {
+ 'click .x-load-more': '_onLoadMore'
},
+ _onLoadMore: function () {
+ this.ui.loadMore.hide();
+ this.ui.searchBar.show();
+ this.resultCollectionView.showAll();
+ },
+
+
initialize: function (options) {
- this.collection = new AddSeriesCollection();
+ 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();
+ }
},
onRender: function () {
var self = this;
+
+ this.$el.addClass(this.className);
+
this.ui.seriesSearch.data('timeout', null).keyup(function () {
window.clearTimeout(self.$el.data('timeout'));
self.$el.data('timeout', window.setTimeout(function () {
@@ -40,8 +70,8 @@ define(
this.ui.searchBar.hide();
}
- this.resultView = new SearchResultCollectionView({
- fullResult: this.collection,
+ this.resultCollectionView = new SearchResultCollectionView({
+ collection: this.collection,
isExisting: this.isExisting
});
},
@@ -50,7 +80,7 @@ define(
var self = this;
- this.abortExistingRequest();
+ this.abortExistingSearch();
this.collection.reset();
@@ -59,22 +89,24 @@ define(
}
else {
this.searchResult.show(new SpinnerView());
- this.currentSearchRequest = this.collection.fetch({
+ this.currentSearchPromise = this.collection.fetch({
data: { term: options.term }
}).done(function () {
- self.searchResult.show(self.resultView);
-
- if (!self.showingAll && self.isExisting) {
- self.ui.loadMore.show();
+ if (!self.isClosed) {
+ self.searchResult.show(self.resultCollectionView);
+ if (!self.showingAll && self.isExisting) {
+ self.ui.loadMore.show();
+ }
}
});
}
+ return this.currentSearchPromise;
},
- abortExistingRequest: function () {
- if (this.currentSearchRequest && this.currentSearchRequest.readyState > 0 && this.currentSearchRequest.readyState < 4) {
+ abortExistingSearch: function () {
+ if (this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) {
console.log('aborting previous pending search request.');
- this.currentSearchRequest.abort();
+ this.currentSearchPromise.abort();
}
}
});
diff --git a/UI/AddSeries/Collection.js b/UI/AddSeries/Collection.js
index 36e71b397..04101920b 100644
--- a/UI/AddSeries/Collection.js
+++ b/UI/AddSeries/Collection.js
@@ -1,4 +1,4 @@
-'use strict';
+'use strict';
define(
[
'backbone',
@@ -8,10 +8,21 @@ define(
url : window.ApiRoot + '/series/lookup',
model: SeriesModel,
+ initialize: function (options) {
+ this.unmappedFolderModel = options.unmappedFolderModel;
+ },
+
+
parse: function (response) {
+ var self = this;
+
_.each(response, function (model) {
model.id = undefined;
+
+ if (self.unmappedFolderModel) {
+ model.path = self.unmappedFolderModel.get('folder').path;
+ }
});
return response;
diff --git a/UI/AddSeries/Existing/CollectionView.js b/UI/AddSeries/Existing/CollectionView.js
index a933fe8f8..e5added59 100644
--- a/UI/AddSeries/Existing/CollectionView.js
+++ b/UI/AddSeries/Existing/CollectionView.js
@@ -12,10 +12,6 @@ define(
initialize: function () {
this.collection = new UnmappedFolderCollection();
- this.refreshItems();
- },
-
- refreshItems: function () {
this.collection.importItems(this.model);
},
@@ -28,12 +24,12 @@ define(
var model = this.collection.at(index);
if (model) {
- var that = this;
+ var self = this;
var currentIndex = index;
var folderName = model.get('folder').name;
this.addItemView(model, this.getItemView(), index);
$.when(this.children.findByModel(model).search({term: folderName})).then(function () {
- that._showAndSearch(currentIndex + 1);
+ self._showAndSearch(currentIndex + 1);
});
}
},
diff --git a/UI/AddSeries/Existing/CompositeView.js b/UI/AddSeries/Existing/CompositeView.js
deleted file mode 100644
index 600e5f21d..000000000
--- a/UI/AddSeries/Existing/CompositeView.js
+++ /dev/null
@@ -1,104 +0,0 @@
-'use strict';
-define(
- [
- 'marionette',
- 'AddSeries/Collection',
- 'AddSeries/SearchResultView'
- ], function (Marionette, AddSeriesCollection, SearchResultView) {
-
- return Marionette.CompositeView.extend({
-
- template : 'AddSeries/Existing/UnmappedFolderCompositeViewTemplate',
- itemViewContainer: '.x-folder-name-match-results',
- itemView : SearchResultView,
-
- events: {
- 'click .x-btn-search' : 'search',
- 'click .x-load-more' : '_loadMore',
- 'keydown .x-txt-search': 'keyDown'
- },
-
- ui: {
- searchButton: '.x-btn-search',
- searchText : '.x-txt-search',
- searchBar : '.x-search-bar',
- loadMore : '.x-load-more'
- },
-
- initialize: function () {
- this.collection = new AddSeriesCollection();
-
- this.on('item:removed', function () {
- this.close();
- }, this);
- },
-
- onRender: function () {
- this.ui.loadMore.show();
- },
-
- search: function () {
- var icon = this.ui.searchButton.find('icon');
- icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
-
- var self = this;
- var deferred = $.Deferred();
-
- this.collection.reset();
-
- this.searchCollection = new AddSeriesCollection();
-
- this.searchCollection.fetch({
- data: { term: this.ui.searchText.val() }
- }).done(function () {
- icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
- deferred.resolve();
- self.collection.add(self.searchCollection.shift());
-
- if (self.showall) {
- self._showAll();
- }
-
- }).fail(function () {
- icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
- deferred.reject();
- });
-
- return deferred.promise();
- },
-
-
- keyDown: function (e) {
- //Check for enter being pressed
- var code = (e.keyCode ? e.keyCode :e.which);
- if (code === 13) {
- this.search();
- }
- },
-
- _loadMore: function () {
- this.showall = true;
-
- this.ui.searchBar.fadeIn();
- this.ui.loadMore.fadeOut();
-
- this._showAll();
- },
-
- _showAll: function () {
- var self = this;
- this.searchCollection.each(function (searchResult) {
- self.collection.add(searchResult);
- });
- },
-
- itemViewOptions: function () {
- return {
- rootFolder: this.model.get('rootFolder'),
- folder : this.model.get('folder').path,
- isExisting: true
- };
- }
- });
-
- });
diff --git a/UI/AddSeries/Existing/UnmappedFolderCompositeViewTemplate.html b/UI/AddSeries/Existing/UnmappedFolderCompositeViewTemplate.html
deleted file mode 100644
index ba6d0432d..000000000
--- a/UI/AddSeries/Existing/UnmappedFolderCompositeViewTemplate.html
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
- {{folder.path}}
-
-
-
-
-
-
-
diff --git a/UI/AddSeries/RootFolders/LayoutTemplate.html b/UI/AddSeries/RootFolders/LayoutTemplate.html
index fc387d9df..a60ef9142 100644
--- a/UI/AddSeries/RootFolders/LayoutTemplate.html
+++ b/UI/AddSeries/RootFolders/LayoutTemplate.html
@@ -8,7 +8,7 @@
-