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

158 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-08-26 12:29:28 -07:00
define(['jQuery', 'fnchecked', 'emby-checkbox', 'emby-collapse', 'emby-textarea', 'emby-input', 'emby-select'], 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('#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();
} else {
$('.fldAutomaticUpdates', page).hide();
}
$('#chkEnableAutomaticServerUpdates', page).checked(config.EnableAutoUpdate);
$('#chkEnableAutomaticRestart', page).checked(config.EnableAutomaticRestart);
if (systemInfo.CanSelfRestart) {
$('#fldEnableAutomaticRestart', page).show();
} else {
$('#fldEnableAutomaticRestart', page).hide();
}
2016-09-05 13:07:36 -07:00
if (systemInfo.CanSelfRestart || systemInfo.CanSelfUpdate) {
$('.autoUpdatesContainer', page).removeClass('hide');
} else {
$('.autoUpdatesContainer', page).addClass('hide');
}
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-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
2016-08-13 15:27:14 -07:00
var requiresReload = false;
2015-06-08 14:32:20 -07:00
if (config.UICulture != currentLanguage) {
2016-08-13 15:27:14 -07:00
requiresReload = true;
2015-06-08 14:32:20 -07:00
}
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.EnableAutomaticRestart = $('#chkEnableAutomaticRestart', form).checked();
config.EnableAutoUpdate = $('#chkEnableAutomaticServerUpdates', form).checked();
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
2016-08-13 15:27:14 -07:00
if (currentBrandingOptions && brandingConfig.CustomCss != currentBrandingOptions.CustomCss) {
requiresReload = true;
}
2015-06-08 14:32:20 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(Dashboard.processServerConfigurationUpdateResult);
2015-06-08 14:32:20 -07:00
2016-08-13 15:27:14 -07:00
if (requiresReload && !AppInfo.isNativeApp) {
window.location.reload(true);
2015-06-08 14:32:20 -07:00
}
});
});
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-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
};
});