1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-29 03:15:19 +00:00
Radarr/NzbDrone.Backbone/AddSeries/Existing/ImportSeriesView.js

136 lines
4.5 KiB
JavaScript
Raw Normal View History

2013-01-31 22:40:51 +00:00
'use strict';
define([
'app', 'AddSeries/RootFolders/RootFolderCollection', 'Quality/QualityProfileCollection', 'Shared/NotificationCollection', 'AddSeries/Existing/UnmappedFolderModel', 'AddSeries/SearchResultCollection', 'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection, notificationCollection) {
NzbDrone.AddSeries.Existing.FolderMatchResultView = Backbone.Marionette.ItemView.extend({
template:'AddSeries/Existing/FolderMatchResultViewTemplatate',
events:{
'click .x-btn-add':'addSeries'
},
addSeries:function () {
2013-02-15 06:57:01 +00:00
var self = this;
var seriesId = this.model.get('tvDbId');
var title = this.model.get('title');
var quality = this.options.qualityProfile.val();
var path = this.options.folder.path;
var model = new NzbDrone.Series.SeriesModel({
tvDbId: seriesId,
title:title,
qualityProfileId:quality,
path:path
});
var seriesCollection = new NzbDrone.Series.SeriesCollection();
2013-02-15 06:57:01 +00:00
seriesCollection.add(model);
model.save(undefined, {
success:function () {
var notificationModel = new NzbDrone.Shared.NotificationModel({
tvDbId: seriesId,
title:'Added',
message:title,
level:'success'
});
notificationCollection.push(notificationModel);
self.close();
}
});
}
2013-01-31 22:40:51 +00:00
});
NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.CompositeView.extend({
template:'AddSeries/Existing/UnmappedFolderCompositeViewTemplatate',
itemViewContainer:'.x-folder-name-match-results',
itemView:NzbDrone.AddSeries.Existing.FolderMatchResultView,
events:{
'click .x-btn-search':'search'
},
ui:{
searchButton:'.x-btn-search',
searchText:'.x-txt-search',
profileList:'.x-lst-quality-profile'
},
initialize:function () {
this.collection = new NzbDrone.AddSeries.SearchResultCollection();
},
search:function () {
2013-01-31 22:40:51 +00:00
var icon = this.ui.searchButton.find('icon');
2013-01-31 22:40:51 +00:00
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
2013-01-31 22:40:51 +00:00
this.collection.fetch({
2013-02-15 08:18:42 +00:00
data:{ term:this.ui.searchText.val() },
success:function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
2013-01-31 22:40:51 +00:00
},
fail:function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
}
});
},
2013-01-31 22:40:51 +00:00
itemViewOptions:function () {
return {
qualityProfile:this.ui.profileList,
rootFolder: this.model.get('rootFolder'),
folder: this.model.get('folder')
};
}
2013-02-01 03:15:19 +00:00
});
NzbDrone.AddSeries.Existing.RootFolderCompositeView = Backbone.Marionette.CompositeView.extend({
template:"AddSeries/Existing/RootFolderCompositeViewTemplate",
itemViewContainer:".x-existing-folder-container",
itemView:NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView,
2013-01-31 22:40:51 +00:00
initialize:function () {
if (!this.model) {
throw "model is required.";
}
2013-01-31 22:40:51 +00:00
this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection();
this.refreshItems();
this.listenTo(qualityProfileCollection, 'reset', this.refreshItems, this);
},
refreshItems:function () {
2013-02-15 08:18:42 +00:00
this.collection.importItems(this.model);
}
2013-01-31 22:40:51 +00:00
});
NzbDrone.AddSeries.Existing.ImportSeriesView = Backbone.Marionette.CollectionView.extend({
itemView:NzbDrone.AddSeries.Existing.RootFolderCompositeView,
initialize:function () {
this.collection = rootFolders;
}
});
});