1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-18 23:48:35 +02:00
Sonarr/src/UI/Settings/SettingsLayout.js

220 lines
7.8 KiB
JavaScript
Raw Normal View History

2013-10-09 04:43:41 +03:00
'use strict';
define(
[
'jquery',
2013-10-09 04:43:41 +03:00
'vent',
'marionette',
2013-10-09 04:43:41 +03:00
'backbone',
'Settings/SettingsModel',
'Settings/General/GeneralSettingsModel',
'Settings/MediaManagement/Naming/NamingModel',
2013-09-25 08:04:33 +03:00
'Settings/MediaManagement/MediaManagementLayout',
'Settings/Quality/QualityLayout',
2013-09-25 08:04:33 +03:00
'Settings/Indexers/IndexerLayout',
'Settings/Indexers/Collection',
'Settings/DownloadClient/Layout',
'Settings/Notifications/CollectionView',
'Settings/Notifications/Collection',
'Settings/General/GeneralView',
2013-09-25 07:51:44 +03:00
'Shared/LoadingView',
'Config'
], function ($,
vent,
Marionette,
2013-10-09 04:43:41 +03:00
Backbone,
SettingsModel,
GeneralSettingsModel,
NamingModel,
2013-07-05 06:26:07 +03:00
MediaManagementLayout,
QualityLayout,
IndexerLayout,
IndexerCollection,
DownloadClientLayout,
NotificationCollectionView,
NotificationCollection,
GeneralView,
2013-09-25 07:51:44 +03:00
LoadingView,
Config) {
2013-06-19 04:02:23 +03:00
return Marionette.Layout.extend({
2013-03-04 03:09:43 +03:00
template: 'Settings/SettingsLayoutTemplate',
regions: {
2013-07-05 06:26:07 +03:00
mediaManagement : '#media-management',
quality : '#quality',
indexers : '#indexers',
downloadClient : '#download-client',
notifications : '#notifications',
general : '#general',
loading : '#loading-region'
2013-03-04 03:09:43 +03:00
},
ui: {
2013-07-05 06:26:07 +03:00
mediaManagementTab : '.x-media-management-tab',
qualityTab : '.x-quality-tab',
indexersTab : '.x-indexers-tab',
downloadClientTab : '.x-download-client-tab',
notificationsTab : '.x-notifications-tab',
2013-09-25 07:51:44 +03:00
generalTab : '.x-general-tab',
advancedSettings : '.x-advanced-settings'
2013-03-04 03:09:43 +03:00
},
events: {
2013-07-05 06:26:07 +03:00
'click .x-media-management-tab' : '_showMediaManagement',
'click .x-quality-tab' : '_showQuality',
'click .x-indexers-tab' : '_showIndexers',
'click .x-download-client-tab' : '_showDownloadClient',
'click .x-notifications-tab' : '_showNotifications',
'click .x-general-tab' : '_showGeneral',
2013-09-25 07:51:44 +03:00
'click .x-save-settings' : '_save',
'change .x-advanced-settings' : '_toggleAdvancedSettings'
},
initialize: function (options) {
if (options.action) {
this.action = options.action.toLowerCase();
}
},
onRender: function () {
this.loading.show(new LoadingView());
var self = this;
this.settings = new SettingsModel();
this.generalSettings = new GeneralSettingsModel();
this.namingSettings = new NamingModel();
this.indexerSettings = new IndexerCollection();
this.notificationSettings = new NotificationCollection();
2013-11-11 07:09:11 +03:00
Backbone.$.when(this.settings.fetch(),
2013-09-25 07:51:44 +03:00
this.generalSettings.fetch(),
this.namingSettings.fetch(),
this.indexerSettings.fetch(),
this.notificationSettings.fetch()
).done(function () {
2013-10-09 04:43:41 +03:00
if(!self.isClosed)
{
2013-09-25 07:51:44 +03:00
self.loading.$el.hide();
self.mediaManagement.show(new MediaManagementLayout({ settings: self.settings, namingSettings: self.namingSettings }));
self.quality.show(new QualityLayout({ settings: self.settings }));
self.indexers.show(new IndexerLayout({ settings: self.settings, indexersCollection: self.indexerSettings }));
self.downloadClient.show(new DownloadClientLayout({ model: self.settings }));
self.notifications.show(new NotificationCollectionView({ collection: self.notificationSettings }));
self.general.show(new GeneralView({ model: self.generalSettings }));
2013-10-09 04:43:41 +03:00
}
2013-09-25 07:51:44 +03:00
});
this._setAdvancedSettingsState();
},
onShow: function () {
switch (this.action) {
case 'quality':
this._showQuality();
break;
case 'indexers':
this._showIndexers();
break;
case 'downloadclient':
this._showDownloadClient();
break;
case 'connect':
this._showNotifications();
break;
case 'notifications':
this._showNotifications();
break;
case 'general':
this._showGeneral();
break;
default:
this._showMediaManagement();
}
2013-03-04 03:09:43 +03:00
},
2013-07-05 06:26:07 +03:00
_showMediaManagement: function (e) {
2013-03-04 03:09:43 +03:00
if (e) {
e.preventDefault();
}
2013-07-05 06:26:07 +03:00
this.ui.mediaManagementTab.tab('show');
this._navigate('settings/mediamanagement');
2013-03-04 03:09:43 +03:00
},
2013-07-05 06:26:07 +03:00
_showQuality: function (e) {
2013-03-04 03:09:43 +03:00
if (e) {
e.preventDefault();
}
this.ui.qualityTab.tab('show');
this._navigate('settings/quality');
2013-03-04 03:09:43 +03:00
},
2013-07-05 06:26:07 +03:00
_showIndexers: function (e) {
2013-03-04 03:09:43 +03:00
if (e) {
e.preventDefault();
}
this.ui.indexersTab.tab('show');
this._navigate('settings/indexers');
2013-03-04 03:09:43 +03:00
},
2013-07-05 06:26:07 +03:00
_showDownloadClient: function (e) {
2013-03-04 03:09:43 +03:00
if (e) {
e.preventDefault();
}
this.ui.downloadClientTab.tab('show');
this._navigate('settings/downloadclient');
2013-03-04 03:09:43 +03:00
},
2013-07-05 06:26:07 +03:00
_showNotifications: function (e) {
2013-03-04 03:09:43 +03:00
if (e) {
e.preventDefault();
}
this.ui.notificationsTab.tab('show');
this._navigate('settings/connect');
2013-03-04 03:09:43 +03:00
},
2013-07-05 06:26:07 +03:00
_showGeneral: function (e) {
2013-03-04 03:09:43 +03:00
if (e) {
e.preventDefault();
}
this.ui.generalTab.tab('show');
this._navigate('settings/general');
2013-03-04 03:09:43 +03:00
},
_navigate:function(route){
Backbone.history.navigate(route, { trigger: true, replace: true });
2013-03-04 03:09:43 +03:00
},
2013-09-25 07:51:44 +03:00
_save: function () {
2013-10-09 04:43:41 +03:00
vent.trigger(vent.Commands.SaveSettings);
2013-03-04 03:09:43 +03:00
},
2013-09-25 07:51:44 +03:00
_setAdvancedSettingsState: function () {
var checked = Config.getValueBoolean(Config.Keys.AdvancedSettings);
2013-09-25 07:51:44 +03:00
this.ui.advancedSettings.prop('checked', checked);
2013-09-25 07:51:44 +03:00
if (checked) {
$('body').addClass('show-advanced-settings');
2013-09-25 07:51:44 +03:00
}
2013-03-04 03:09:43 +03:00
},
2013-09-25 07:51:44 +03:00
_toggleAdvancedSettings: function () {
var checked = this.ui.advancedSettings.prop('checked');
Config.setValue(Config.Keys.AdvancedSettings, checked);
2013-09-25 07:51:44 +03:00
if (checked) {
$('body').addClass('show-advanced-settings');
2013-03-04 03:09:43 +03:00
}
2013-09-25 07:51:44 +03:00
else {
$('body').removeClass('show-advanced-settings');
2013-09-25 07:51:44 +03:00
}
2013-03-04 03:09:43 +03:00
}
2013-06-14 02:19:24 +03:00
});
});
2013-03-04 03:09:43 +03:00