1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-29 11:05:44 +00:00
Lidarr/UI/AddSeries/Existing/ImportSeriesView.js

140 lines
4.2 KiB
JavaScript
Raw Normal View History

2013-01-31 22:40:51 +00:00
'use strict';
define([
2013-05-13 04:24:04 +00:00
'app', 'AddSeries/RootFolders/RootFolderCollection',
'AddSeries/Existing/UnmappedFolderModel',
'AddSeries/Collection',
'AddSeries/SearchResultView',
'Series/SeriesModel'], function () {
2013-03-29 19:17:03 +00:00
NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.CompositeView.extend({
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',
itemView : NzbDrone.AddSeries.SearchResultView,
2013-03-29 19:17:03 +00:00
events: {
'click .x-btn-search' : 'search',
'click .x-load-more' : '_loadMore',
'keydown .x-txt-search': 'keyDown'
2013-03-29 19:17:03 +00:00
},
2013-03-29 19:17:03 +00:00
ui: {
searchButton: '.x-btn-search',
searchText : '.x-txt-search',
searchBar : '.x-search-bar',
loadMore : '.x-load-more'
2013-03-29 19:17:03 +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();
this.collection.bind('reset', this.collectionReset, this);
2013-04-12 15:08:09 +00:00
this.on("item:removed", function () {
2013-04-12 15:08:09 +00:00
this.close();
}, this);
2013-03-29 19:17:03 +00:00
},
onRender: function () {
this.ui.loadMore.show();
},
2013-01-31 22:40:51 +00:00
search: function () {
2013-03-29 19:17:03 +00:00
var icon = this.ui.searchButton.find('icon');
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
2013-01-31 22:40:51 +00:00
var self = this;
var deferred = $.Deferred();
this.collection.reset();
2013-01-31 22:40:51 +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() },
success: function () {
2013-03-29 19:17:03 +00: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 19:17:03 +00:00
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.reject();
2013-03-29 19:17:03 +00:00
}
});
return deferred.promise();
2013-03-29 19:17:03 +00:00
},
2013-01-31 22:40:51 +00: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 19:17:03 +00:00
itemViewOptions: function () {
return {
rootFolder : this.model.get('rootFolder'),
folder : this.model.get('folder').path,
isExisting : true
2013-03-29 19:17:03 +00:00
};
}
});
2013-05-27 02:53:56 +00:00
NzbDrone.AddSeries.Existing.ListView = Backbone.Marionette.CollectionView.extend({
2013-05-27 02:53:56 +00:00
itemView: NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView,
2013-01-31 22:40:51 +00:00
2013-03-29 19:17:03 +00:00
initialize: function () {
this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection();
this.refreshItems();
},
2013-03-29 19:17:03 +00: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 19:17:03 +00:00
}
});
2013-05-27 02:53:56 +00:00
});