1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/controllers/dashboard/general.js

112 lines
5.3 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import 'jquery';
import loading from '../../components/loading/loading';
import globalize from '../../scripts/globalize';
import '../../elements/emby-checkbox/emby-checkbox';
import '../../elements/emby-textarea/emby-textarea';
import '../../elements/emby-input/emby-input';
import '../../elements/emby-select/emby-select';
import '../../elements/emby-button/emby-button';
import Dashboard from '../../scripts/clientUtils';
import alert from '../../components/alert';
/* eslint-disable indent */
2018-10-23 01:05:09 +03:00
function loadPage(page, config, languageOptions, systemInfo) {
2020-05-04 12:44:12 +02:00
page.querySelector('#txtServerName').value = systemInfo.ServerName;
page.querySelector('#txtCachePath').value = systemInfo.CachePath || '';
$('#txtMetadataPath', page).val(systemInfo.InternalMetadataPath || '');
$('#txtMetadataNetworkPath', page).val(systemInfo.MetadataNetworkPath || '');
$('#selectLocalizationLanguage', page).html(languageOptions.map(function (language) {
return '<option value="' + language.Value + '">' + language.Name + '</option>';
2019-03-05 21:30:06 +09:00
})).val(config.UICulture);
2020-01-22 03:30:33 +03:00
2019-03-05 21:30:06 +09:00
loading.hide();
2018-10-23 01:05:09 +03:00
}
function onSubmit() {
loading.show();
2020-07-16 11:25:17 +01:00
const form = this;
2020-05-04 12:44:12 +02:00
$(form).parents('.page');
2020-01-22 03:30:33 +03:00
ApiClient.getServerConfiguration().then(function (config) {
2020-05-04 12:44:12 +02:00
config.ServerName = $('#txtServerName', form).val();
config.UICulture = $('#selectLocalizationLanguage', form).val();
config.CachePath = form.querySelector('#txtCachePath').value;
config.MetadataPath = $('#txtMetadataPath', form).val();
config.MetadataNetworkPath = $('#txtMetadataNetworkPath', form).val();
ApiClient.updateServerConfiguration(config).then(function() {
2018-10-23 01:05:09 +03:00
ApiClient.getNamedConfiguration(brandingConfigKey).then(function(brandingConfig) {
2020-05-04 12:44:12 +02:00
brandingConfig.LoginDisclaimer = form.querySelector('#txtLoginDisclaimer').value;
brandingConfig.CustomCss = form.querySelector('#txtCustomCss').value;
2020-01-22 03:30:33 +03:00
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(function () {
Dashboard.processServerConfigurationUpdateResult();
});
2020-01-22 03:30:33 +03:00
});
}, function () {
alert(globalize.translate('ErrorDefault'));
Dashboard.processServerConfigurationUpdateResult();
2020-01-22 03:30:33 +03:00
});
});
return false;
2018-10-23 01:05:09 +03:00
}
2019-03-05 21:30:06 +09:00
2020-07-16 11:25:17 +01:00
const brandingConfigKey = 'branding';
2021-01-26 22:20:12 -05:00
export default function (view) {
2020-05-04 12:44:12 +02:00
$('#btnSelectCachePath', view).on('click.selectDirectory', function () {
2020-08-14 08:46:34 +02:00
import('../../components/directorybrowser/directorybrowser').then(({default: directoryBrowser}) => {
2020-07-16 11:25:17 +01:00
const picker = new directoryBrowser();
2018-10-23 01:05:09 +03:00
picker.show({
2020-01-22 03:30:33 +03:00
callback: function (path) {
if (path) {
2020-05-04 12:44:12 +02:00
view.querySelector('#txtCachePath').value = path;
}
2020-01-22 03:30:33 +03:00
2019-03-05 21:30:06 +09:00
picker.close();
2018-10-23 01:05:09 +03:00
},
2019-03-05 21:30:06 +09:00
validateWriteable: true,
2020-05-04 12:44:12 +02:00
header: globalize.translate('HeaderSelectServerCachePath'),
instruction: globalize.translate('HeaderSelectServerCachePathHelp')
2020-01-22 03:30:33 +03:00
});
});
});
2020-05-04 12:44:12 +02:00
$('#btnSelectMetadataPath', view).on('click.selectDirectory', function () {
2020-08-14 08:46:34 +02:00
import('../../components/directorybrowser/directorybrowser').then(({default: directoryBrowser}) => {
2020-07-16 11:25:17 +01:00
const picker = new directoryBrowser();
picker.show({
2020-05-04 12:44:12 +02:00
path: $('#txtMetadataPath', view).val(),
networkSharePath: $('#txtMetadataNetworkPath', view).val(),
2020-01-22 03:30:33 +03:00
callback: function (path, networkPath) {
if (path) {
2020-05-04 12:44:12 +02:00
$('#txtMetadataPath', view).val(path);
}
2020-01-22 03:30:33 +03:00
2019-03-10 07:06:28 +09:00
if (networkPath) {
2020-05-04 12:44:12 +02:00
$('#txtMetadataNetworkPath', view).val(networkPath);
}
2020-01-22 03:30:33 +03:00
picker.close();
},
validateWriteable: true,
2020-05-04 12:44:12 +02:00
header: globalize.translate('HeaderSelectMetadataPath'),
instruction: globalize.translate('HeaderSelectMetadataPathHelp'),
2019-03-10 07:06:28 +09:00
enableNetworkSharePath: true
2020-01-22 03:30:33 +03:00
});
});
});
2020-05-04 12:44:12 +02:00
$('.dashboardGeneralForm', view).off('submit', onSubmit).on('submit', onSubmit);
view.addEventListener('viewshow', function () {
2020-07-16 11:25:17 +01:00
const promiseConfig = ApiClient.getServerConfiguration();
const promiseLanguageOptions = ApiClient.getJSON(ApiClient.getUrl('Localization/Options'));
const promiseSystemInfo = ApiClient.getSystemInfo();
2020-01-22 03:30:33 +03:00
Promise.all([promiseConfig, promiseLanguageOptions, promiseSystemInfo]).then(function (responses) {
2019-03-05 21:30:06 +09:00
loadPage(view, responses[0], responses[1], responses[2]);
});
2020-01-22 03:30:33 +03:00
ApiClient.getNamedConfiguration(brandingConfigKey).then(function (config) {
2020-05-04 12:44:12 +02:00
view.querySelector('#txtLoginDisclaimer').value = config.LoginDisclaimer || '';
view.querySelector('#txtCustomCss').value = config.CustomCss || '';
2019-03-05 21:30:06 +09:00
});
});
2020-07-16 11:25:17 +01:00
}
/* eslint-enable indent */