2013-01-31 22:40:51 +00:00
|
|
|
|
'use strict';
|
2013-02-15 02:40:29 +00:00
|
|
|
|
define([
|
2013-05-13 04:24:04 +00:00
|
|
|
|
'app', 'AddSeries/RootFolders/RootFolderCollection',
|
|
|
|
|
'Quality/QualityProfileCollection',
|
|
|
|
|
'AddSeries/Existing/UnmappedFolderModel',
|
|
|
|
|
'AddSeries/Collection',
|
2013-05-23 03:37:43 +00:00
|
|
|
|
'Series/SeriesModel'], function (app, rootFolders, qualityProfileCollection) {
|
2013-02-15 02:40:29 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
NzbDrone.AddSeries.Existing.FolderMatchResultView = Backbone.Marionette.ItemView.extend({
|
2013-04-05 06:24:23 +00:00
|
|
|
|
template: 'AddSeries/SearchResultTemplate',
|
2013-02-15 02:40:29 +00:00
|
|
|
|
|
2013-04-24 00:36:08 +00:00
|
|
|
|
ui: {
|
2013-05-23 06:25:58 +00:00
|
|
|
|
qualityProfile: '.x-quality-profile',
|
|
|
|
|
addButton : '.x-add'
|
2013-04-24 00:36:08 +00:00
|
|
|
|
},
|
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
events: {
|
2013-04-07 23:15:04 +00:00
|
|
|
|
'click .x-add': 'addSeries'
|
2013-03-29 19:17:03 +00:00
|
|
|
|
},
|
2013-02-15 02:40:29 +00:00
|
|
|
|
|
2013-04-21 01:29:26 +00:00
|
|
|
|
initialize: function () {
|
|
|
|
|
this.model.set('isExisting', true);
|
|
|
|
|
},
|
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
addSeries: function () {
|
2013-05-23 06:25:58 +00:00
|
|
|
|
var icon = this.ui.addButton.find('icon');
|
|
|
|
|
icon.removeClass('icon-plus').addClass('icon-spin icon-spinner disabled');
|
2013-02-15 02:40:29 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
var self = this;
|
2013-02-15 06:57:01 +00:00
|
|
|
|
|
2013-04-24 00:36:08 +00:00
|
|
|
|
var quality = this.ui.qualityProfile.val();
|
2013-04-11 07:52:38 +00:00
|
|
|
|
var rootFolderId = this.options.rootFolder.id;
|
2013-05-23 05:37:46 +00:00
|
|
|
|
var folderName = this.options.folder.name;
|
2013-02-15 02:40:29 +00:00
|
|
|
|
|
2013-04-11 07:52:38 +00:00
|
|
|
|
this.model.set('qualityProfileId', quality);
|
|
|
|
|
this.model.set('rootFolderId', rootFolderId);
|
2013-05-23 05:37:46 +00:00
|
|
|
|
this.model.set('folderName', folderName);
|
2013-02-15 02:40:29 +00:00
|
|
|
|
|
2013-04-11 07:52:38 +00:00
|
|
|
|
this.model.save(undefined, {
|
2013-03-29 19:17:03 +00:00
|
|
|
|
success: function () {
|
2013-05-23 06:25:58 +00:00
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
2013-05-23 03:37:43 +00:00
|
|
|
|
NzbDrone.Shared.Messenger.show({
|
|
|
|
|
message: 'Added: ' + self.model.get('title')
|
2013-03-29 19:17:03 +00:00
|
|
|
|
});
|
2013-02-15 02:40:29 +00:00
|
|
|
|
|
2013-04-12 15:08:09 +00:00
|
|
|
|
NzbDrone.vent.trigger(NzbDrone.Events.SeriesAdded, { existing: true, series: self.model });
|
|
|
|
|
self.trigger('seriesAdded');
|
2013-03-29 19:17:03 +00:00
|
|
|
|
self.close();
|
2013-05-23 06:25:58 +00:00
|
|
|
|
},
|
|
|
|
|
fail: function () {
|
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
2013-03-29 19:17:03 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.CompositeView.extend({
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
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.Existing.FolderMatchResultView,
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
events: {
|
2013-04-05 06:24:23 +00:00
|
|
|
|
'click .x-btn-search': 'search',
|
2013-04-11 07:52:38 +00:00
|
|
|
|
'keydown .x-txt-search': 'keyDown'
|
2013-03-29 19:17:03 +00:00
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
ui: {
|
|
|
|
|
searchButton: '.x-btn-search',
|
|
|
|
|
searchText : '.x-txt-search',
|
|
|
|
|
profileList : '.x-lst-quality-profile'
|
|
|
|
|
},
|
2013-02-02 03:33:23 +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();
|
2013-04-05 06:24:23 +00:00
|
|
|
|
this.collection.bind('reset', this.collectionReset, this);
|
2013-04-12 15:08:09 +00:00
|
|
|
|
|
|
|
|
|
this.on("itemview:seriesAdded", function(){
|
|
|
|
|
this.close();
|
|
|
|
|
});
|
2013-03-29 19:17:03 +00:00
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-04-05 06:24:23 +00:00
|
|
|
|
onRender: function () {
|
|
|
|
|
this.resultView = new NzbDrone.AddSeries.SearchResultView({ collection: this.collection });
|
|
|
|
|
},
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-04-05 06:24:23 +00:00
|
|
|
|
search: function () {
|
2013-03-29 19:17:03 +00:00
|
|
|
|
var icon = this.ui.searchButton.find('icon');
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-04-05 06:24:23 +00:00
|
|
|
|
this.collection.reset();
|
2013-03-29 19:17:03 +00:00
|
|
|
|
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
this.collection.fetch({
|
|
|
|
|
data : { term: this.ui.searchText.val() },
|
2013-04-05 06:24:23 +00:00
|
|
|
|
success: function (collection) {
|
2013-03-29 19:17:03 +00:00
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
|
|
|
|
},
|
|
|
|
|
fail : function () {
|
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-04-11 07:52:38 +00:00
|
|
|
|
keyDown: function (e) {
|
|
|
|
|
//Check for enter being pressed
|
2013-04-05 06:24:23 +00:00
|
|
|
|
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 19:17:03 +00:00
|
|
|
|
itemViewOptions: function () {
|
|
|
|
|
return {
|
|
|
|
|
qualityProfile: this.ui.profileList,
|
|
|
|
|
rootFolder : this.model.get('rootFolder'),
|
|
|
|
|
folder : this.model.get('folder')
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
NzbDrone.AddSeries.Existing.RootFolderCompositeView = Backbone.Marionette.CompositeView.extend({
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
template : "AddSeries/Existing/RootFolderCompositeViewTemplate",
|
|
|
|
|
itemViewContainer: ".x-existing-folder-container",
|
|
|
|
|
itemView : NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView,
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
initialize: function () {
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
if (!this.model) {
|
|
|
|
|
throw "model is required.";
|
|
|
|
|
}
|
2013-01-31 22:40:51 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection();
|
|
|
|
|
this.refreshItems();
|
|
|
|
|
this.listenTo(qualityProfileCollection, 'reset', this.refreshItems, this);
|
|
|
|
|
},
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
refreshItems: function () {
|
|
|
|
|
this.collection.importItems(this.model);
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
NzbDrone.AddSeries.Existing.ImportSeriesView = Backbone.Marionette.CollectionView.extend({
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
itemView: NzbDrone.AddSeries.Existing.RootFolderCompositeView,
|
2013-02-02 03:33:23 +00:00
|
|
|
|
|
2013-03-29 19:17:03 +00:00
|
|
|
|
initialize: function () {
|
|
|
|
|
this.collection = rootFolders;
|
|
|
|
|
}
|
2013-02-14 02:28:56 +00:00
|
|
|
|
});
|
2013-03-29 19:17:03 +00:00
|
|
|
|
});
|