2013-06-21 03:43:58 +02:00
|
|
|
|
'use strict';
|
|
|
|
|
define(
|
|
|
|
|
[
|
|
|
|
|
'marionette',
|
2013-06-22 02:48:23 +02:00
|
|
|
|
'AddSeries/AddSeriesView',
|
2013-06-21 03:43:58 +02:00
|
|
|
|
'AddSeries/Existing/UnmappedFolderCollection'
|
2013-06-22 02:48:23 +02:00
|
|
|
|
], function (Marionette, AddSeriesView, UnmappedFolderCollection) {
|
2013-06-21 03:43:58 +02:00
|
|
|
|
|
|
|
|
|
return Marionette.CollectionView.extend({
|
|
|
|
|
|
2013-06-22 02:48:23 +02:00
|
|
|
|
itemView: AddSeriesView,
|
2013-06-21 03:43:58 +02:00
|
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
|
this.collection = new UnmappedFolderCollection();
|
|
|
|
|
this.refreshItems();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
refreshItems: function () {
|
|
|
|
|
this.collection.importItems(this.model);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showCollection: function () {
|
|
|
|
|
this._showAndSearch(0);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_showAndSearch: function (index) {
|
|
|
|
|
|
|
|
|
|
var model = this.collection.at(index);
|
2013-06-22 02:48:23 +02:00
|
|
|
|
|
2013-06-21 03:43:58 +02:00
|
|
|
|
if (model) {
|
|
|
|
|
var that = this;
|
|
|
|
|
var currentIndex = index;
|
2013-06-22 02:48:23 +02:00
|
|
|
|
var folderName = model.get('folder').name;
|
2013-06-21 03:43:58 +02:00
|
|
|
|
this.addItemView(model, this.getItemView(), index);
|
2013-06-22 02:48:23 +02:00
|
|
|
|
$.when(this.children.findByModel(model).search({term: folderName})).then(function () {
|
2013-06-21 03:43:58 +02:00
|
|
|
|
that._showAndSearch(currentIndex + 1);
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-06-22 02:48:23 +02:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
itemViewOptions: {
|
|
|
|
|
isExisting: true
|
2013-06-21 03:43:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|