2013-05-26 08:54:02 +03:00
|
|
|
'use strict';
|
2013-06-21 04:43:58 +03:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'app',
|
|
|
|
'marionette',
|
2013-06-21 08:19:41 +03:00
|
|
|
'Quality/QualityProfileCollection',
|
|
|
|
'AddSeries/RootFolders/Collection',
|
2013-06-21 04:43:58 +03:00
|
|
|
'Series/SeriesCollection',
|
2013-06-21 08:19:41 +03:00
|
|
|
'Config',
|
|
|
|
'Shared/Messenger'
|
|
|
|
], function (App, Marionette, QualityProfiles, RootFolders, SeriesCollection, Config, Messenger) {
|
2013-06-21 04:43:58 +03:00
|
|
|
|
|
|
|
return Marionette.ItemView.extend({
|
|
|
|
|
2013-06-22 09:24:24 +03:00
|
|
|
template: 'AddSeries/SearchResultTemplate',
|
2013-06-21 04:43:58 +03:00
|
|
|
|
|
|
|
ui: {
|
|
|
|
qualityProfile: '.x-quality-profile',
|
|
|
|
rootFolder : '.x-root-folder',
|
|
|
|
addButton : '.x-add',
|
|
|
|
overview : '.x-overview'
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .x-add' : 'addSeries',
|
|
|
|
'change .x-quality-profile': '_qualityProfileChanged'
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
|
|
|
|
if (!this.model) {
|
|
|
|
throw 'model is required';
|
|
|
|
}
|
2013-05-28 08:40:58 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
this.model.set('isExisting', this.options.isExisting);
|
|
|
|
this.model.set('path', this.options.folder);
|
2013-05-28 08:40:58 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
App.vent.on(Config.Events.ConfigUpdatedEvent, this._onConfigUpdated, this);
|
|
|
|
},
|
2013-05-28 08:40:58 +03:00
|
|
|
|
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
_onConfigUpdated: function (options) {
|
2013-05-26 08:54:02 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
if (options.key === Config.Keys.DefaultQualityProfileId) {
|
|
|
|
this.$('.x-quality-profile').val(options.value);
|
|
|
|
}
|
|
|
|
},
|
2013-05-28 08:40:58 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
_qualityProfileChanged: function () {
|
|
|
|
Config.SetValue(Config.Keys.DefaultQualityProfileId, this.ui.qualityProfile.val());
|
|
|
|
},
|
2013-05-28 08:40:58 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
onRender: function () {
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
2013-05-26 08:54:02 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
var defaultQuality = Config.GetValue(Config.Keys.DefaultQualityProfileId);
|
2013-05-28 08:40:58 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
if (QualityProfiles.get(defaultQuality)) {
|
|
|
|
this.ui.qualityProfile.val(defaultQuality);
|
|
|
|
}
|
|
|
|
},
|
2013-05-26 08:54:02 +03:00
|
|
|
|
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
addSeries: function () {
|
|
|
|
var icon = this.ui.addButton.find('icon');
|
|
|
|
icon.removeClass('icon-plus').addClass('icon-spin icon-spinner disabled');
|
2013-05-26 08:54:02 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
var quality = this.ui.qualityProfile.val();
|
|
|
|
var rootFolderPath = this.ui.rootFolder.children(':selected').text();
|
2013-05-26 08:54:02 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
this.model.set('qualityProfileId', quality);
|
|
|
|
this.model.set('rootFolderPath', rootFolderPath);
|
2013-05-26 08:54:02 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
var self = this;
|
2013-05-26 08:54:02 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
this.model.save(undefined, {
|
|
|
|
url : SeriesCollection.prototype.url,
|
|
|
|
success: function () {
|
|
|
|
self.close();
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
|
|
|
Messenger.show({
|
|
|
|
message: 'Added: ' + self.model.get('title')
|
|
|
|
});
|
2013-05-26 08:54:02 +03:00
|
|
|
|
2013-06-21 04:43:58 +03:00
|
|
|
App.vent.trigger(App.Events.SeriesAdded, { series: self.model });
|
|
|
|
self.model.collection.remove(self.model);
|
|
|
|
},
|
|
|
|
fail : function () {
|
|
|
|
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
|
|
|
|
}
|
|
|
|
});
|
2013-06-21 08:19:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
serializeData: function () {
|
|
|
|
var data = this.model.toJSON();
|
|
|
|
data.rootFolders = RootFolders.toJSON();
|
|
|
|
data.qualityProfiles = QualityProfiles.toJSON();
|
|
|
|
|
|
|
|
return data;
|
2013-06-21 04:43:58 +03:00
|
|
|
}
|
|
|
|
});
|
2013-05-26 08:54:02 +03:00
|
|
|
|
|
|
|
});
|