fully working add series

This commit is contained in:
kay.one 2013-06-30 12:57:26 -07:00
commit 96810c489c
21 changed files with 295 additions and 314 deletions

View file

@ -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);
});
}
},

View file

@ -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
};
}
});
});

View file

@ -1,23 +0,0 @@
<div class="unmapped-folder-view">
<div class="text-center">
<h2>
<icon class="icon-folder-open"></icon>
{{folder.path}}
</h2>
</div>
<div class="row x-search-bar" style="display: none;">
<div class="folder-header span11">
<div class="input-prepend">
<i class="add-on icon-search"/>
<input class="x-txt-search input-xlarge" type="text" value="{{folder.name}}" placeholder="{{folder.name}}">
</div>
<div class="btn btn-primary x-btn-search pull-right">
<icon class="icon-search"></icon>
</div>
</div>
</div>
<div class="row">
<div class="x-folder-name-match-results folder-name-matches"/>
</div>
</div>