jellyfin-web/dashboard-ui/scripts/dashboardgeneral.js

173 lines
6.3 KiB
JavaScript
Raw Normal View History

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