You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/UI/AddSeries/Existing/ImportSeriesView.js

152 lines
4.7 KiB

'use strict';
define([
'app', 'AddSeries/RootFolders/RootFolderCollection',
'Quality/QualityProfileCollection',
'AddSeries/Existing/UnmappedFolderModel',
'AddSeries/Collection',
'AddSeries/SearchResultView',
'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection) {
12 years ago
NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.CompositeView.extend({
template : 'AddSeries/Existing/UnmappedFolderCompositeViewTemplate',
12 years ago
itemViewContainer: '.x-folder-name-match-results',
itemView : NzbDrone.AddSeries.SearchResultView,
12 years ago
events: {
'click .x-btn-search' : 'search',
'click .x-load-more' : '_loadMore',
'keydown .x-txt-search': 'keyDown'
12 years ago
},
12 years ago
ui: {
searchButton: '.x-btn-search',
searchText : '.x-txt-search',
profileList : '.x-lst-quality-profile',
searchBar : '.x-search-bar',
loadMore : '.x-load-more'
12 years ago
},
12 years ago
initialize: function () {
this.collection = new NzbDrone.AddSeries.Collection();
this.collection.bind('reset', this.collectionReset, this);
this.on("itemview:seriesAdded", function () {
this.close();
});
12 years ago
},
onRender: function () {
this.ui.loadMore.show();
},
search: function () {
12 years ago
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 NzbDrone.AddSeries.Collection();
this.searchCollection.fetch({
12 years ago
data : { term: this.ui.searchText.val() },
success: function (collection) {
12 years ago
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.resolve();
self.collection.add(self.searchCollection.shift());
if (self.showall) {
self._showAll();
}
12 years ago
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.reject();
12 years ago
}
});
return deferred.promise();
12 years ago
},
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);
});
},
12 years ago
itemViewOptions: function () {
return {
qualityProfile: this.ui.profileList,
rootFolder : this.model.get('rootFolder'),
folder : this.model.get('folder'),
isExisting : true
12 years ago
};
}
});
12 years ago
NzbDrone.AddSeries.Existing.RootFolderCompositeView = Backbone.Marionette.CompositeView.extend({
12 years ago
template : "AddSeries/Existing/RootFolderCompositeViewTemplate",
itemViewContainer: ".x-existing-folder-container",
itemView : NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView,
12 years ago
initialize: function () {
12 years ago
if (!this.model) {
throw "model is required.";
}
12 years ago
this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection();
this.refreshItems();
this.listenTo(qualityProfileCollection, 'reset', this.refreshItems, this);
},
12 years ago
refreshItems: function () {
this.collection.importItems(this.model);
},
showCollection: function () {
this.showAndSearch(0);
},
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);
});
}
12 years ago
}
});
})
;