Sonarr/src/UI/AddSeries/Existing/AddExistingSeriesCollection...

60 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-01-30 02:10:16 +00:00
'use strict';
2013-06-21 01:43:58 +00:00
define(
[
'marionette',
'AddSeries/AddSeriesView',
2013-06-21 01:43:58 +00:00
'AddSeries/Existing/UnmappedFolderCollection'
], function (Marionette, AddSeriesView, UnmappedFolderCollection) {
2013-06-21 01:43:58 +00:00
return Marionette.CompositeView.extend({
2013-06-21 01:43:58 +00:00
itemView : AddSeriesView,
itemViewContainer: '.x-loading-folders',
template : 'AddSeries/Existing/AddExistingSeriesCollectionViewTemplate',
ui: {
loadingFolders: '.x-loading-folders'
},
2013-06-21 01:43:58 +00:00
initialize: function () {
this.collection = new UnmappedFolderCollection();
this.collection.importItems(this.model);
},
showCollection: function () {
this._showAndSearch(0);
},
appendHtml: function(collectionView, itemView, index){
collectionView.ui.loadingFolders.before(itemView.el);
},
2013-06-21 01:43:58 +00:00
_showAndSearch: function (index) {
2013-09-18 19:43:37 +00:00
var self = this;
2013-06-21 01:43:58 +00:00
var model = this.collection.at(index);
2013-06-21 01:43:58 +00:00
if (model) {
var currentIndex = index;
var folderName = model.get('folder').name;
2013-06-21 01:43:58 +00:00
this.addItemView(model, this.getItemView(), index);
2013-09-18 19:43:37 +00:00
this.children.findByModel(model)
.search({term: folderName})
.always(function () {
if (!self.isClosed) {
self._showAndSearch(currentIndex + 1);
}
});
2013-06-21 01:43:58 +00:00
}
else {
this.ui.loadingFolders.hide();
}
},
itemViewOptions: {
isExisting: true
2013-06-21 01:43:58 +00:00
}
});
});