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

151 lines
5.2 KiB
JavaScript
Raw Normal View History

2013-02-01 01:40:51 +03:00
'use strict';
define([
'app', 'AddSeries/RootFolders/RootFolderCollection', 'Quality/QualityProfileCollection', 'Shared/NotificationCollection', 'AddSeries/Existing/UnmappedFolderModel', 'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection, notificationCollection) {
2013-03-29 22:17:03 +03:00
NzbDrone.AddSeries.Existing.FolderMatchResultView = Backbone.Marionette.ItemView.extend({
template: 'AddSeries/SearchResultTemplate',
2013-03-29 22:17:03 +03:00
events: {
'click .x-add': 'addSeries'
2013-03-29 22:17:03 +03:00
},
initialize: function () {
this.model.set('isExisting', true);
},
2013-03-29 22:17:03 +03:00
addSeries: function () {
2013-03-29 22:17:03 +03:00
var self = this;
2013-02-15 09:57:01 +03:00
2013-03-29 22:17:03 +03:00
var quality = this.options.qualityProfile.val();
var rootFolderId = this.options.rootFolder.id;
var folder = this.options.folder.name;
this.model.set('qualityProfileId', quality);
this.model.set('rootFolderId', rootFolderId);
this.model.set('folder', folder);
2013-03-29 22:17:03 +03:00
var seriesCollection = new NzbDrone.Series.SeriesCollection();
seriesCollection.add(this.model);
this.model.save(undefined, {
2013-03-29 22:17:03 +03:00
success: function () {
var notificationModel = new NzbDrone.Shared.NotificationModel({
tvDbId : self.model.get('tvDbId'),
2013-03-29 22:17:03 +03:00
title : 'Added',
message: self.model.get('title'),
2013-03-29 22:17:03 +03:00
level : 'success'
});
2013-03-29 22:17:03 +03:00
notificationCollection.push(notificationModel);
2013-04-12 18:08:09 +03:00
NzbDrone.vent.trigger(NzbDrone.Events.SeriesAdded, { existing: true, series: self.model });
self.trigger('seriesAdded');
2013-03-29 22:17:03 +03:00
self.close();
}
});
}
});
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.Existing.FolderMatchResultView,
2013-03-29 22:17:03 +03:00
events: {
'click .x-btn-search': 'search',
'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'
},
2013-03-29 22:17:03 +03:00
initialize: function () {
this.collection = new NzbDrone.Series.SeriesCollection();
this.collection.bind('reset', this.collectionReset, this);
2013-04-12 18:08:09 +03:00
this.on("itemview:seriesAdded", function(){
this.close();
});
2013-03-29 22:17:03 +03:00
},
onRender: function () {
this.collection.url = NzbDrone.Constants.ApiRoot + '/series/lookup';
this.resultView = new NzbDrone.AddSeries.SearchResultView({ collection: this.collection });
},
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');
2013-02-01 01:40:51 +03:00
this.collection.reset();
2013-03-29 22:17:03 +03:00
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
2013-02-01 01:40:51 +03:00
2013-03-29 22:17:03 +03:00
this.collection.fetch({
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');
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
}
});
},
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();
}
},
collectionReset: function () {
_.each(this.collection.models, function (model){
model.set('isExisting', true);
});
},
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')
};
}
});
2013-03-29 22:17:03 +03:00
NzbDrone.AddSeries.Existing.RootFolderCompositeView = Backbone.Marionette.CompositeView.extend({
2013-03-29 22:17:03 +03:00
template : "AddSeries/Existing/RootFolderCompositeViewTemplate",
itemViewContainer: ".x-existing-folder-container",
itemView : NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView,
2013-02-01 01:40:51 +03:00
2013-03-29 22:17:03 +03:00
initialize: function () {
2013-03-29 22:17:03 +03:00
if (!this.model) {
throw "model is required.";
}
2013-02-01 01:40:51 +03:00
2013-03-29 22:17:03 +03:00
this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection();
this.refreshItems();
this.listenTo(qualityProfileCollection, 'reset', this.refreshItems, this);
},
2013-03-29 22:17:03 +03:00
refreshItems: function () {
this.collection.importItems(this.model);
}
});
2013-03-29 22:17:03 +03:00
NzbDrone.AddSeries.Existing.ImportSeriesView = Backbone.Marionette.CollectionView.extend({
2013-03-29 22:17:03 +03:00
itemView: NzbDrone.AddSeries.Existing.RootFolderCompositeView,
2013-03-29 22:17:03 +03:00
initialize: function () {
this.collection = rootFolders;
}
});
2013-03-29 22:17:03 +03:00
});