2013-01-31 22:40:51 +00:00
|
|
|
|
'use strict';
|
2013-02-15 02:40:29 +00:00
|
|
|
|
define([
|
2013-05-13 04:24:04 +00:00
|
|
|
|
'app', 'AddSeries/RootFolders/RootFolderCollection',
|
|
|
|
|
'Quality/QualityProfileCollection',
|
|
|
|
|
'AddSeries/Existing/UnmappedFolderModel',
|
|
|
|
|
'AddSeries/Collection',
|
2013-05-26 05:54:02 +00:00
|
|
|
|
'AddSeries/SearchResultView',
|
2013-05-23 03:37:43 +00:00
|
|
|
|
'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection) {
|
2013-02-15 02:40:29 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.CompositeView.extend({
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-30 19:30:00 +00:00
|
|
|
|
template : 'AddSeries/Existing/UnmappedFolderCompositeViewTemplate',
|
2013-03-29 19:17:03 +00:00
|
|
|
|
itemViewContainer: '.x-folder-name-match-results',
|
2013-05-26 05:54:02 +00:00
|
|
|
|
itemView : NzbDrone.AddSeries.SearchResultView,
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
events: {
|
2013-05-25 02:08:26 +00:00
|
|
|
|
'click .x-btn-search' : 'search',
|
2013-05-26 05:54:02 +00:00
|
|
|
|
'click .x-load-more' : '_loadMore',
|
2013-04-11 07:52:38 +00:00
|
|
|
|
'keydown .x-txt-search': 'keyDown'
|
2013-03-29 19:17:03 +00:00
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
ui: {
|
|
|
|
|
searchButton: '.x-btn-search',
|
|
|
|
|
searchText : '.x-txt-search',
|
2013-05-26 05:54:02 +00:00
|
|
|
|
profileList : '.x-lst-quality-profile',
|
|
|
|
|
searchBar : '.x-search-bar',
|
|
|
|
|
loadMore : '.x-load-more'
|
2013-03-29 19:17:03 +00:00
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
initialize: function () {
|
2013-05-13 04:24:04 +00:00
|
|
|
|
this.collection = new NzbDrone.AddSeries.Collection();
|
2013-04-05 06:24:23 +00:00
|
|
|
|
this.collection.bind('reset', this.collectionReset, this);
|
2013-04-12 15:08:09 +00:00
|
|
|
|
|
2013-05-25 02:08:26 +00:00
|
|
|
|
this.on("itemview:seriesAdded", function () {
|
2013-04-12 15:08:09 +00:00
|
|
|
|
this.close();
|
|
|
|
|
});
|
2013-03-29 19:17:03 +00:00
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-04-05 06:24:23 +00:00
|
|
|
|
onRender: function () {
|
2013-05-26 05:54:02 +00:00
|
|
|
|
this.ui.loadMore.show();
|
2013-04-05 06:24:23 +00:00
|
|
|
|
},
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-04-05 06:24:23 +00:00
|
|
|
|
search: function () {
|
2013-03-29 19:17:03 +00:00
|
|
|
|
var icon = this.ui.searchButton.find('icon');
|
2013-05-26 05:54:02 +00:00
|
|
|
|
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-05-26 05:54:02 +00:00
|
|
|
|
var self = this;
|
2013-05-25 02:08:26 +00:00
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
|
2013-04-05 06:24:23 +00:00
|
|
|
|
this.collection.reset();
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-05-26 05:54:02 +00:00
|
|
|
|
this.searchCollection = new NzbDrone.AddSeries.Collection();
|
|
|
|
|
|
|
|
|
|
this.searchCollection.fetch({
|
2013-03-29 19:17:03 +00:00
|
|
|
|
data : { term: this.ui.searchText.val() },
|
2013-04-05 06:24:23 +00:00
|
|
|
|
success: function (collection) {
|
2013-03-29 19:17:03 +00:00
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
2013-05-25 02:08:26 +00:00
|
|
|
|
deferred.resolve();
|
2013-05-26 05:54:02 +00:00
|
|
|
|
self.collection.add(self.searchCollection.shift());
|
|
|
|
|
|
|
|
|
|
if (self.showall) {
|
|
|
|
|
self._showAll();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
},
|
|
|
|
|
fail : function () {
|
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
2013-05-25 02:08:26 +00:00
|
|
|
|
deferred.reject();
|
2013-03-29 19:17:03 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2013-05-25 02:08:26 +00:00
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
2013-03-29 19:17:03 +00:00
|
|
|
|
},
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-05-26 05:54:02 +00:00
|
|
|
|
|
2013-04-11 07:52:38 +00:00
|
|
|
|
keyDown: function (e) {
|
|
|
|
|
//Check for enter being pressed
|
2013-05-25 02:08:26 +00:00
|
|
|
|
var code = (e.keyCode ? e.keyCode :e.which);
|
|
|
|
|
if (code === 13) {
|
2013-04-05 06:24:23 +00:00
|
|
|
|
this.search();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-26 05:54:02 +00:00
|
|
|
|
_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);
|
2013-04-05 06:24:23 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
itemViewOptions: function () {
|
|
|
|
|
return {
|
|
|
|
|
qualityProfile: this.ui.profileList,
|
|
|
|
|
rootFolder : this.model.get('rootFolder'),
|
2013-05-26 05:54:02 +00:00
|
|
|
|
folder : this.model.get('folder'),
|
|
|
|
|
isExisting : true
|
2013-03-29 19:17:03 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
NzbDrone.AddSeries.Existing.RootFolderCompositeView = Backbone.Marionette.CompositeView.extend({
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
template : "AddSeries/Existing/RootFolderCompositeViewTemplate",
|
|
|
|
|
itemViewContainer: ".x-existing-folder-container",
|
|
|
|
|
itemView : NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView,
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
initialize: function () {
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
if (!this.model) {
|
|
|
|
|
throw "model is required.";
|
|
|
|
|
}
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection();
|
|
|
|
|
this.refreshItems();
|
|
|
|
|
this.listenTo(qualityProfileCollection, 'reset', this.refreshItems, this);
|
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
refreshItems: function () {
|
|
|
|
|
this.collection.importItems(this.model);
|
2013-05-25 02:08:26 +00:00
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-05-25 02:08:26 +00:00
|
|
|
|
showCollection: function () {
|
|
|
|
|
this.showAndSearch(0);
|
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-05-25 02:08:26 +00:00
|
|
|
|
showAndSearch: function (index) {
|
|
|
|
|
|
|
|
|
|
var model = this.collection.at(index);
|
|
|
|
|
if (model) {
|
|
|
|
|
var that = this;
|
|
|
|
|
var currentIndex = index;
|
|
|
|
|
this.addItemView(model, this.getItemView(), index);
|
|
|
|
|
$.when(this.children.findByModel(model).search())
|
|
|
|
|
.then(function () {
|
|
|
|
|
that.showAndSearch(currentIndex + 1);
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-03-29 19:17:03 +00:00
|
|
|
|
}
|
2013-05-25 02:08:26 +00:00
|
|
|
|
|
2013-02-14 02:28:56 +00:00
|
|
|
|
});
|
2013-05-26 05:54:02 +00:00
|
|
|
|
})
|
|
|
|
|
;
|