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