2013-05-26 05:54:02 +00:00
|
|
|
|
'use strict';
|
2013-06-21 01:43:58 +00:00
|
|
|
|
define(
|
|
|
|
|
[
|
|
|
|
|
'app',
|
|
|
|
|
'marionette',
|
2013-08-08 07:27:49 +00:00
|
|
|
|
|
2013-06-21 05:19:41 +00:00
|
|
|
|
'Quality/QualityProfileCollection',
|
|
|
|
|
'AddSeries/RootFolders/Collection',
|
2013-07-11 21:28:57 +00:00
|
|
|
|
'AddSeries/RootFolders/Layout',
|
2013-06-21 01:43:58 +00:00
|
|
|
|
'Series/SeriesCollection',
|
2013-06-21 05:19:41 +00:00
|
|
|
|
'Config',
|
2013-08-08 07:27:49 +00:00
|
|
|
|
'Shared/Messenger',
|
|
|
|
|
'jquery.dotdotdot'
|
2013-07-11 21:28:57 +00:00
|
|
|
|
], function (App, Marionette, QualityProfiles, RootFolders, RootFolderLayout, SeriesCollection, Config, Messenger) {
|
2013-06-21 01:43:58 +00:00
|
|
|
|
|
|
|
|
|
return Marionette.ItemView.extend({
|
|
|
|
|
|
2013-06-22 06:24:24 +00:00
|
|
|
|
template: 'AddSeries/SearchResultTemplate',
|
2013-06-21 01:43:58 +00:00
|
|
|
|
|
|
|
|
|
ui: {
|
|
|
|
|
qualityProfile: '.x-quality-profile',
|
|
|
|
|
rootFolder : '.x-root-folder',
|
|
|
|
|
addButton : '.x-add',
|
|
|
|
|
overview : '.x-overview'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
events: {
|
2013-06-30 19:57:26 +00:00
|
|
|
|
'click .x-add' : '_addSeries',
|
2013-07-11 21:28:57 +00:00
|
|
|
|
'change .x-quality-profile': '_qualityProfileChanged',
|
|
|
|
|
'change .x-root-folder' : '_rootFolderChanged'
|
2013-06-21 01:43:58 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
|
|
|
|
|
|
if (!this.model) {
|
|
|
|
|
throw 'model is required';
|
|
|
|
|
}
|
2013-05-28 05:40:58 +00:00
|
|
|
|
|
2013-06-30 19:57:26 +00:00
|
|
|
|
this.listenTo(App.vent, Config.Events.ConfigUpdatedEvent, this._onConfigUpdated);
|
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
2013-08-31 20:31:58 +00:00
|
|
|
|
this.listenTo(RootFolders, 'all', this.render);
|
2013-07-11 21:28:57 +00:00
|
|
|
|
|
|
|
|
|
this.rootFolderLayout = new RootFolderLayout();
|
|
|
|
|
this.listenTo(this.rootFolderLayout, 'folderSelected', this._setRootFolder);
|
2013-06-21 01:43:58 +00:00
|
|
|
|
},
|
2013-05-28 05:40:58 +00:00
|
|
|
|
|
2013-07-11 16:51:38 +00:00
|
|
|
|
onRender: function () {
|
|
|
|
|
|
2013-08-04 01:27:12 +00:00
|
|
|
|
var defaultQuality = Config.getValue(Config.Keys.DefaultQualityProfileId);
|
|
|
|
|
var defaultRoot = Config.getValue(Config.Keys.DefaultRootFolderId);
|
2013-07-11 16:51:38 +00:00
|
|
|
|
|
|
|
|
|
if (QualityProfiles.get(defaultQuality)) {
|
|
|
|
|
this.ui.qualityProfile.val(defaultQuality);
|
|
|
|
|
}
|
2013-07-11 21:28:57 +00:00
|
|
|
|
|
|
|
|
|
if (RootFolders.get(defaultRoot)) {
|
|
|
|
|
this.ui.rootFolder.val(defaultRoot);
|
|
|
|
|
}
|
2013-08-08 07:27:49 +00:00
|
|
|
|
|
|
|
|
|
//TODO: make this work via onRender, FM?
|
|
|
|
|
//works with onShow, but stops working after the first render
|
|
|
|
|
this.ui.overview.dotdotdot({
|
|
|
|
|
height: 120
|
|
|
|
|
});
|
2013-07-11 16:51:38 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
serializeData: function () {
|
|
|
|
|
var data = this.model.toJSON();
|
|
|
|
|
|
|
|
|
|
var existingSeries = SeriesCollection.where({tvdbId: this.model.get('tvdbId')});
|
|
|
|
|
|
|
|
|
|
if (existingSeries.length > 0) {
|
|
|
|
|
data.existing = existingSeries[0].toJSON();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.qualityProfiles = QualityProfiles.toJSON();
|
|
|
|
|
|
|
|
|
|
if (!data.isExisting) {
|
|
|
|
|
data.rootFolders = RootFolders.toJSON();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
},
|
2013-05-28 05:40:58 +00:00
|
|
|
|
|
2013-06-21 01:43:58 +00:00
|
|
|
|
_onConfigUpdated: function (options) {
|
|
|
|
|
if (options.key === Config.Keys.DefaultQualityProfileId) {
|
2013-07-11 21:28:57 +00:00
|
|
|
|
this.ui.qualityProfile.val(options.value);
|
|
|
|
|
}
|
|
|
|
|
else if (options.key === Config.Keys.DefaultRootFolderId) {
|
|
|
|
|
this.ui.rootFolder.val(options.value);
|
2013-06-21 01:43:58 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2013-05-28 05:40:58 +00:00
|
|
|
|
|
2013-06-21 01:43:58 +00:00
|
|
|
|
_qualityProfileChanged: function () {
|
2013-08-04 01:27:12 +00:00
|
|
|
|
Config.setValue(Config.Keys.DefaultQualityProfileId, this.ui.qualityProfile.val());
|
2013-06-21 01:43:58 +00:00
|
|
|
|
},
|
2013-05-28 05:40:58 +00:00
|
|
|
|
|
2013-07-11 21:28:57 +00:00
|
|
|
|
_rootFolderChanged: function () {
|
|
|
|
|
var rootFolderValue = this.ui.rootFolder.val();
|
|
|
|
|
if (rootFolderValue === 'addNew') {
|
|
|
|
|
App.modalRegion.show(this.rootFolderLayout);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-08-04 01:27:12 +00:00
|
|
|
|
Config.setValue(Config.Keys.DefaultRootFolderId, rootFolderValue);
|
2013-07-11 21:28:57 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_setRootFolder: function (options) {
|
2013-07-24 01:15:58 +00:00
|
|
|
|
App.vent.trigger(App.Commands.CloseModalCommand);
|
2013-07-11 21:28:57 +00:00
|
|
|
|
this.ui.rootFolder.val(options.model.id);
|
2013-08-31 20:31:58 +00:00
|
|
|
|
this._rootFolderChanged();
|
2013-07-11 21:28:57 +00:00
|
|
|
|
},
|
|
|
|
|
|
2013-07-01 17:41:15 +00:00
|
|
|
|
_addSeries: function () {
|
2013-06-21 01:43:58 +00:00
|
|
|
|
var icon = this.ui.addButton.find('icon');
|
|
|
|
|
icon.removeClass('icon-plus').addClass('icon-spin icon-spinner disabled');
|
2013-05-26 05:54:02 +00:00
|
|
|
|
|
2013-06-21 01:43:58 +00:00
|
|
|
|
var quality = this.ui.qualityProfile.val();
|
|
|
|
|
var rootFolderPath = this.ui.rootFolder.children(':selected').text();
|
2013-05-26 05:54:02 +00:00
|
|
|
|
|
2013-06-21 01:43:58 +00:00
|
|
|
|
this.model.set('qualityProfileId', quality);
|
|
|
|
|
this.model.set('rootFolderPath', rootFolderPath);
|
2013-05-26 05:54:02 +00:00
|
|
|
|
|
2013-06-21 01:43:58 +00:00
|
|
|
|
var self = this;
|
2013-05-26 05:54:02 +00:00
|
|
|
|
|
2013-06-28 23:06:16 +00:00
|
|
|
|
SeriesCollection.add(this.model);
|
|
|
|
|
|
|
|
|
|
|
2013-06-30 19:57:26 +00:00
|
|
|
|
this.model.save().done(function () {
|
|
|
|
|
self.close();
|
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
|
|
|
|
Messenger.show({
|
|
|
|
|
message: 'Added: ' + self.model.get('title')
|
|
|
|
|
});
|
2013-05-26 05:54:02 +00:00
|
|
|
|
|
2013-06-30 19:57:26 +00:00
|
|
|
|
App.vent.trigger(App.Events.SeriesAdded, { series: self.model });
|
|
|
|
|
}).fail(function () {
|
2013-06-21 01:43:58 +00:00
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
2013-06-28 23:06:16 +00:00
|
|
|
|
});
|
2013-06-21 01:43:58 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2013-05-26 05:54:02 +00:00
|
|
|
|
});
|