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

136 lines
4.0 KiB
JavaScript
Raw Normal View History

2014-03-30 19:33:10 -07:00
(function ($, document, window) {
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;
2014-03-30 19:33:10 -07:00
function loadPage(page, config, languageOptions) {
2015-01-18 12:53:34 -07:00
if (Dashboard.lastSystemInfo) {
Dashboard.setPageTitle(Dashboard.lastSystemInfo.ServerName);
}
2015-01-18 21:29:57 -07:00
refreshPageTitle(page);
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;
2015-01-18 21:29:57 -07:00
Dashboard.hideLoadingMsg();
}
2015-01-18 21:29:57 -07:00
function refreshPageTitle(page) {
2014-07-19 21:46:29 -07:00
2015-01-18 21:29:57 -07:00
ApiClient.getSystemInfo().done(function (systemInfo) {
2014-07-19 21:46:29 -07:00
2015-01-18 21:29:57 -07:00
Dashboard.setPageTitle(systemInfo.ServerName);
});
2014-03-30 19:33:10 -07:00
}
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-06-08 14:32:20 -07:00
ApiClient.getServerConfiguration().done(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
2015-06-08 14:32:20 -07:00
ApiClient.updateServerConfiguration(config).done(function () {
2014-03-30 19:33:10 -07:00
2015-06-08 14:32:20 -07:00
refreshPageTitle(page);
2014-07-10 21:27:46 -07:00
2015-06-08 14:32:20 -07:00
ApiClient.getNamedConfiguration(brandingConfigKey).done(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;
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).done(Dashboard.processServerConfigurationUpdateResult);
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;
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#dashboardGeneralPage", function () {
2014-07-19 21:46:29 -07:00
var page = this;
$('#btnSelectCachePath', page).on("click.selectDirectory", function () {
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) {
page.querySelector('#txtCachePath').value = path;
}
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
2015-06-08 14:32:20 -07:00
$('.dashboardGeneralForm').off('submit', onSubmit).on('submit', onSubmit);
2014-03-30 19:33:10 -07:00
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#dashboardGeneralPage", function () {
2014-03-30 19:33:10 -07:00
2015-06-08 14:32:20 -07:00
Dashboard.showLoadingMsg();
2015-06-08 14:32:20 -07:00
var page = this;
2015-01-18 21:29:57 -07:00
2015-06-08 14:32:20 -07:00
var promise1 = ApiClient.getServerConfiguration();
2015-01-18 21:29:57 -07:00
2015-06-08 14:32:20 -07:00
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Localization/Options"));
2014-07-10 21:27:46 -07:00
2015-06-08 14:32:20 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
2015-01-18 22:41:56 -07:00
2015-06-08 14:32:20 -07:00
loadPage(page, response1[0], response2[0]);
2014-07-10 21:27:46 -07:00
2015-06-08 14:32:20 -07:00
});
2015-01-18 22:41:56 -07:00
2015-06-08 14:32:20 -07:00
ApiClient.getNamedConfiguration(brandingConfigKey).done(function (config) {
2014-07-10 21:27:46 -07:00
2015-06-08 14:32:20 -07:00
currentBrandingOptions = config;
2014-03-30 19:33:10 -07:00
2015-07-30 08:18:07 -07:00
page.querySelector('#txtLoginDisclaimer').value = config.LoginDisclaimer || '';
page.querySelector('#txtCustomCss').value = config.CustomCss || '';
2015-06-08 14:32:20 -07:00
});
2014-03-30 19:33:10 -07:00
2015-06-08 14:32:20 -07:00
});
2014-03-30 19:33:10 -07:00
})(jQuery, document, window);