1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/UI/AddSeries/Existing/ImportSeriesView.js

143 lines
4.4 KiB
JavaScript
Raw Normal View History

2013-02-01 01:40:51 +03:00
'use strict';
define([
2013-05-13 07:24:04 +03:00
'app', 'AddSeries/RootFolders/RootFolderCollection',
'Quality/QualityProfileCollection',
'AddSeries/Existing/UnmappedFolderModel',
'AddSeries/Collection',
'AddSeries/SearchResultView',
'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection) {
2013-03-29 22:17:03 +03:00
NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.CompositeView.extend({
2013-03-30 22:30:00 +03:00
template : 'AddSeries/Existing/UnmappedFolderCompositeViewTemplate',
2013-03-29 22:17:03 +03:00
itemViewContainer: '.x-folder-name-match-results',
itemView : NzbDrone.AddSeries.SearchResultView,
2013-03-29 22:17:03 +03:00
events: {
'click .x-btn-search' : 'search',
'click .x-load-more' : '_loadMore',
'keydown .x-txt-search': 'keyDown'
2013-03-29 22:17:03 +03:00
},
2013-03-29 22:17:03 +03:00
ui: {
searchButton: '.x-btn-search',
searchText : '.x-txt-search',
profileList : '.x-lst-quality-profile',
searchBar : '.x-search-bar',
loadMore : '.x-load-more'
2013-03-29 22:17:03 +03:00
},
2013-03-29 22:17:03 +03:00
initialize: function () {
2013-05-13 07:24:04 +03:00
this.collection = new NzbDrone.AddSeries.Collection();
this.collection.bind('reset', this.collectionReset, this);
2013-04-12 18:08:09 +03:00
this.on("itemview:seriesAdded", function () {
2013-04-12 18:08:09 +03:00
this.close();
});
2013-03-29 22:17:03 +03:00
},
onRender: function () {
this.ui.loadMore.show();
},
2013-02-01 01:40:51 +03:00
search: function () {
2013-03-29 22:17:03 +03:00
var icon = this.ui.searchButton.find('icon');
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
2013-02-01 01:40:51 +03:00
var self = this;
var deferred = $.Deferred();
this.collection.reset();
2013-02-01 01:40:51 +03:00
this.searchCollection = new NzbDrone.AddSeries.Collection();
this.searchCollection.fetch({
2013-03-29 22:17:03 +03:00
data : { term: this.ui.searchText.val() },
success: function (collection) {
2013-03-29 22:17:03 +03:00
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.resolve();
self.collection.add(self.searchCollection.shift());
if (self.showall) {
self._showAll();
}
2013-03-29 22:17:03 +03:00
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.reject();
2013-03-29 22:17:03 +03:00
}
});
return deferred.promise();
2013-03-29 22:17:03 +03:00
},
2013-02-01 01:40:51 +03:00
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);
});
},
2013-03-29 22:17:03 +03:00
itemViewOptions: function () {
return {
qualityProfile: this.ui.profileList,
rootFolder : this.model.get('rootFolder'),
folder : this.model.get('folder'),
isExisting : true
2013-03-29 22:17:03 +03:00
};
}
});
2013-05-27 05:53:56 +03:00
NzbDrone.AddSeries.Existing.ListView = Backbone.Marionette.CollectionView.extend({
2013-05-27 05:53:56 +03:00
itemView: NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView,
2013-02-01 01:40:51 +03:00
2013-03-29 22:17:03 +03:00
initialize: function () {
this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection();
this.refreshItems();
},
2013-03-29 22:17:03 +03:00
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);
});
}
2013-03-29 22:17:03 +03:00
}
});
2013-05-27 05:53:56 +03:00
});