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.
Lidarr/UI/AddSeries/Existing/ImportSeriesView.js

158 lines
5.3 KiB

'use strict';
define([
'app', 'AddSeries/RootFolders/RootFolderCollection',
'Quality/QualityProfileCollection',
'AddSeries/Existing/UnmappedFolderModel',
'AddSeries/Collection',
'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection) {
12 years ago
NzbDrone.AddSeries.Existing.FolderMatchResultView = Backbone.Marionette.ItemView.extend({
template: 'AddSeries/SearchResultTemplate',
ui: {
qualityProfile: '.x-quality-profile',
addButton : '.x-add'
},
12 years ago
events: {
'click .x-add': 'addSeries'
12 years ago
},
initialize: function () {
this.model.set('isExisting', true);
},
12 years ago
addSeries: function () {
var icon = this.ui.addButton.find('icon');
icon.removeClass('icon-plus').addClass('icon-spin icon-spinner disabled');
12 years ago
var self = this;
12 years ago
var quality = this.ui.qualityProfile.val();
var rootFolderId = this.options.rootFolder.id;
var folderName = this.options.folder.name;
this.model.set('qualityProfileId', quality);
this.model.set('rootFolderId', rootFolderId);
this.model.set('folderName', folderName);
this.model.save(undefined, {
12 years ago
success: function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
NzbDrone.Shared.Messenger.show({
message: 'Added: ' + self.model.get('title')
12 years ago
});
NzbDrone.vent.trigger(NzbDrone.Events.SeriesAdded, { existing: true, series: self.model });
self.trigger('seriesAdded');
12 years ago
self.close();
},
fail: function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
12 years ago
}
});
}
});
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.Existing.FolderMatchResultView,
12 years ago
events: {
'click .x-btn-search': 'search',
'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'
},
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.resultView = new NzbDrone.AddSeries.SearchResultView({ collection: this.collection });
},
search: function () {
12 years ago
var icon = this.ui.searchButton.find('icon');
this.collection.reset();
12 years ago
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
12 years ago
this.collection.fetch({
data : { term: this.ui.searchText.val() },
success: function (collection) {
12 years ago
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
}
});
},
keyDown: function (e) {
//Check for enter being pressed
var code = (e.keyCode ? e.keyCode : e.which);
if(code === 13) {
this.search();
}
},
collectionReset: function () {
_.each(this.collection.models, function (model){
model.set('isExisting', true);
});
},
12 years ago
itemViewOptions: function () {
return {
qualityProfile: this.ui.profileList,
rootFolder : this.model.get('rootFolder'),
folder : this.model.get('folder')
};
}
});
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);
}
});
12 years ago
NzbDrone.AddSeries.Existing.ImportSeriesView = Backbone.Marionette.CollectionView.extend({
12 years ago
itemView: NzbDrone.AddSeries.Existing.RootFolderCompositeView,
12 years ago
initialize: function () {
this.collection = rootFolders;
}
});
12 years ago
});