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

131 lines
6.1 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['jQuery', 'loading', 'globalize', 'fnchecked', 'emby-checkbox', 'emby-textarea', 'emby-input', 'emby-select', 'emby-button'], function ($, loading, globalize) {
'use strict';
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;
$('#chkAutoRunWebApp', page).checked(config.AutoRunWebApp);
2020-01-22 03:30:33 +03:00
if (systemInfo.CanLaunchWebBrowser) {
2020-05-04 12:44:12 +02:00
page.querySelector('#fldAutoRunWebApp').classList.remove('hide');
} else {
2020-05-04 12:44:12 +02:00
page.querySelector('#fldAutoRunWebApp').classList.add('hide');
}
2020-01-22 03:30:33 +03:00
2020-05-04 12:44:12 +02:00
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);
currentLanguage = config.UICulture;
if (systemInfo.CanSelfRestart || systemInfo.CanSelfUpdate) {
2020-05-04 12:44:12 +02:00
$('.autoUpdatesContainer', page).removeClass('hide');
} else {
2020-05-04 12:44:12 +02:00
$('.autoUpdatesContainer', page).addClass('hide');
}
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();
var 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();
2020-01-22 03:30:33 +03:00
var requiresReload = config.UICulture !== currentLanguage;
2020-05-04 12:44:12 +02:00
config.AutoRunWebApp = $('#chkAutoRunWebApp', form).checked();
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
if (currentBrandingOptions && brandingConfig.CustomCss !== currentBrandingOptions.CustomCss) {
requiresReload = true;
}
2020-01-22 03:30:33 +03:00
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(function () {
Dashboard.processServerConfigurationUpdateResult();
2020-01-22 03:30:33 +03:00
if (requiresReload && !AppInfo.isNativeApp) {
window.location.reload(true);
}
});
2020-01-22 03:30:33 +03:00
});
}, function () {
2020-05-04 12:44:12 +02:00
require(['alert'], function (alert) {
alert(globalize.translate('DefaultErrorMessage'));
});
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
var currentBrandingOptions;
var currentLanguage;
2020-05-04 12:44:12 +02:00
var brandingConfigKey = 'branding';
2020-01-22 03:30:33 +03:00
return function (view, params) {
2020-05-04 12:44:12 +02:00
$('#btnSelectCachePath', view).on('click.selectDirectory', function () {
require(['directorybrowser'], function (directoryBrowser) {
2020-01-22 03:30:33 +03:00
var 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 () {
require(['directorybrowser'], function (directoryBrowser) {
var 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 () {
var promiseConfig = ApiClient.getServerConfiguration();
2020-05-04 12:44:12 +02:00
var promiseLanguageOptions = ApiClient.getJSON(ApiClient.getUrl('Localization/Options'));
var 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) {
2019-03-05 21:30:06 +09:00
currentBrandingOptions = 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-01-22 03:30:33 +03:00
};
});