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

181 lines
6.4 KiB
JavaScript
Raw Normal View History

2016-08-26 15:29:28 -04:00
define(['jQuery', 'fnchecked', 'emby-checkbox', 'emby-collapse', 'emby-textarea', 'emby-input', 'emby-select'], function ($) {
2014-03-30 22:33:10 -04:00
2014-07-11 00:27:46 -04:00
var brandingConfigKey = "branding";
2015-01-19 00:41:56 -05:00
var currentBrandingOptions;
2014-07-11 00:27:46 -04:00
var currentLanguage;
2016-03-27 23:37:33 -04:00
function loadPage(page, config, languageOptions, systemInfo) {
2014-03-30 22:33:10 -04:00
2016-03-27 23:37:33 -04:00
var os = systemInfo.OperatingSystem.toLowerCase();
if (os.indexOf('windows') != -1) {
$('#windowsStartupDescription', page).show();
} else {
$('#windowsStartupDescription', page).hide();
2015-01-18 14:53:34 -05:00
}
2016-03-27 23:37:33 -04:00
if (systemInfo.SupportsAutoRunAtStartup) {
$('#fldRunAtStartup', page).show();
} else {
$('#fldRunAtStartup', page).hide();
}
2015-01-18 14:53:34 -05:00
2015-07-30 11:18:07 -04:00
page.querySelector('#txtServerName').value = config.ServerName || '';
page.querySelector('#txtCachePath').value = config.CachePath || '';
2014-03-30 22:33:10 -04:00
$('#selectLocalizationLanguage', page).html(languageOptions.map(function (l) {
return '<option value="' + l.Value + '">' + l.Name + '</option>';
2015-09-03 13:01:51 -04:00
})).val(config.UICulture);
2014-03-30 22:33:10 -04:00
currentLanguage = config.UICulture;
2016-03-27 23:37:33 -04:00
$('#chkUsageData', page).checked(config.EnableAnonymousUsageReporting);
$('#chkRunAtStartup', page).checked(config.RunAtStartup);
2016-03-29 01:16:44 -04:00
if (systemInfo.CanSelfUpdate) {
$('.fldAutomaticUpdates', page).show();
} else {
$('.fldAutomaticUpdates', page).hide();
}
$('#chkEnableAutomaticServerUpdates', page).checked(config.EnableAutoUpdate);
$('#chkEnableAutomaticRestart', page).checked(config.EnableAutomaticRestart);
if (systemInfo.CanSelfRestart) {
$('#fldEnableAutomaticRestart', page).show();
} else {
$('#fldEnableAutomaticRestart', page).hide();
}
$('#chkEnableDashboardResponseCache', page).checked(config.EnableDashboardResponseCaching);
$('#chkEnableMinification', page).checked(config.EnableDashboardResourceMinification);
$('#txtDashboardSourcePath', page).val(config.DashboardSourcePath).trigger('change');
2015-01-18 23:29:57 -05:00
Dashboard.hideLoadingMsg();
}
2015-06-08 17:32:20 -04:00
function onSubmit() {
2014-03-30 22:33:10 -04:00
Dashboard.showLoadingMsg();
2015-06-08 17:32:20 -04:00
var form = this;
var page = $(form).parents('.page');
2014-03-30 22:33:10 -04:00
2015-12-14 10:43:03 -05:00
ApiClient.getServerConfiguration().then(function (config) {
2014-03-30 22:33:10 -04:00
2015-07-30 11:18:07 -04:00
config.ServerName = form.querySelector('#txtServerName').value;
2015-06-08 17:32:20 -04:00
config.UICulture = $('#selectLocalizationLanguage', form).val();
2014-03-30 22:33:10 -04:00
2015-07-30 11:18:07 -04:00
config.CachePath = form.querySelector('#txtCachePath').value;
2014-03-30 22:33:10 -04:00
2016-08-13 18:27:14 -04:00
var requiresReload = false;
2015-06-08 17:32:20 -04:00
if (config.UICulture != currentLanguage) {
2016-08-13 18:27:14 -04:00
requiresReload = true;
2015-06-08 17:32:20 -04:00
}
2014-03-30 22:33:10 -04:00
2016-03-27 23:37:33 -04:00
config.EnableAnonymousUsageReporting = $('#chkUsageData', form).checked();
config.RunAtStartup = $('#chkRunAtStartup', form).checked();
2014-03-30 22:33:10 -04:00
2016-03-29 01:16:44 -04:00
config.EnableAutomaticRestart = $('#chkEnableAutomaticRestart', form).checked();
config.EnableAutoUpdate = $('#chkEnableAutomaticServerUpdates', form).checked();
config.EnableDashboardResourceMinification = $('#chkEnableMinification', form).checked();
config.EnableDashboardResponseCaching = $('#chkEnableDashboardResponseCache', form).checked();
config.DashboardSourcePath = $('#txtDashboardSourcePath', form).val();
2016-03-27 23:37:33 -04:00
ApiClient.updateServerConfiguration(config).then(function () {
2014-07-11 00:27:46 -04:00
2015-12-14 10:43:03 -05:00
ApiClient.getNamedConfiguration(brandingConfigKey).then(function (brandingConfig) {
2015-01-19 00:41:56 -05:00
2015-07-30 11:18:07 -04:00
brandingConfig.LoginDisclaimer = form.querySelector('#txtLoginDisclaimer').value;
brandingConfig.CustomCss = form.querySelector('#txtCustomCss').value;
2015-06-08 17:32:20 -04:00
2016-08-13 18:27:14 -04:00
if (currentBrandingOptions && brandingConfig.CustomCss != currentBrandingOptions.CustomCss) {
requiresReload = true;
}
2015-06-08 17:32:20 -04:00
2015-12-14 10:43:03 -05:00
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(Dashboard.processServerConfigurationUpdateResult);
2015-06-08 17:32:20 -04:00
2016-08-13 18:27:14 -04:00
if (requiresReload && !AppInfo.isNativeApp) {
window.location.reload(true);
2015-06-08 17:32:20 -04:00
}
});
});
2014-07-11 00:27:46 -04:00
});
2014-07-20 00:46:29 -04:00
2015-06-08 17:32:20 -04:00
// Disable default form submission
return false;
}
2016-03-27 23:37:33 -04:00
return function (view, params) {
2014-07-20 00:46:29 -04:00
2016-03-27 23:37:33 -04:00
$('#btnSelectCachePath', view).on("click.selectDirectory", function () {
2014-07-20 00:46:29 -04:00
2015-10-13 15:22:45 -04:00
require(['directorybrowser'], function (directoryBrowser) {
2014-07-20 00:46:29 -04:00
2015-10-13 15:22:45 -04:00
var picker = new directoryBrowser();
2014-07-20 00:46:29 -04:00
2015-10-13 15:22:45 -04:00
picker.show({
2014-07-20 00:46:29 -04:00
2015-10-13 15:22:45 -04:00
callback: function (path) {
if (path) {
2016-03-27 23:37:33 -04:00
view.querySelector('#txtCachePath').value = path;
2015-10-13 15:22:45 -04:00
}
picker.close();
},
2014-07-20 00:46:29 -04:00
2015-10-13 15:22:45 -04:00
header: Globalize.translate('HeaderSelectServerCachePath'),
2014-07-20 00:46:29 -04:00
2015-10-13 15:22:45 -04:00
instruction: Globalize.translate('HeaderSelectServerCachePathHelp')
});
2014-07-20 00:46:29 -04:00
});
});
2014-03-30 22:33:10 -04:00
2016-04-18 13:40:48 -04:00
$('#btnSelectDashboardSourcePath', view).on("click.selectDirectory", function () {
require(['directorybrowser'], function (directoryBrowser) {
var picker = new directoryBrowser();
picker.show({
callback: function (path) {
if (path) {
view.querySelector('#txtDashboardSourcePath').value = path;
}
picker.close();
}
});
});
});
2016-03-27 23:37:33 -04:00
$('.dashboardGeneralForm', view).off('submit', onSubmit).on('submit', onSubmit);
2014-03-30 22:33:10 -04:00
2016-03-27 23:37:33 -04:00
view.addEventListener('viewshow', function () {
2014-03-30 22:33:10 -04:00
2016-03-27 23:37:33 -04:00
var promise1 = ApiClient.getServerConfiguration();
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Localization/Options"));
var promise3 = ApiClient.getSystemInfo();
2015-01-18 23:29:57 -05:00
2016-03-27 23:37:33 -04:00
Promise.all([promise1, promise2, promise3]).then(function (responses) {
2014-07-11 00:27:46 -04:00
2016-03-27 23:37:33 -04:00
loadPage(view, responses[0], responses[1], responses[2]);
2015-01-19 00:41:56 -05:00
2016-03-27 23:37:33 -04:00
});
2015-01-19 00:41:56 -05:00
2016-03-27 23:37:33 -04:00
ApiClient.getNamedConfiguration(brandingConfigKey).then(function (config) {
2014-07-11 00:27:46 -04:00
2016-03-27 23:37:33 -04:00
currentBrandingOptions = config;
2014-03-30 22:33:10 -04:00
2016-03-27 23:37:33 -04:00
view.querySelector('#txtLoginDisclaimer').value = config.LoginDisclaimer || '';
view.querySelector('#txtCustomCss').value = config.CustomCss || '';
});
2015-06-08 17:32:20 -04:00
});
2016-03-27 23:37:33 -04:00
};
});