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

135 lines
3.9 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
2014-03-30 19:33:10 -07:00
$('#txtServerName', page).val(config.ServerName || '');
$('#selectLocalizationLanguage', page).html(languageOptions.map(function (l) {
return '<option value="' + l.Value + '">' + l.Name + '</option>';
})).val(config.UICulture).selectmenu('refresh');
currentLanguage = config.UICulture;
2015-01-18 21:29:57 -07:00
$('#txtCachePath', page).val(config.CachePath || '');
2014-07-19 21:46:29 -07:00
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
}
$(document).on('pageshow', "#dashboardGeneralPage", function () {
Dashboard.showLoadingMsg();
var page = this;
var promise1 = ApiClient.getServerConfiguration();
2014-07-01 22:16:59 -07:00
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Localization/Options"));
2014-03-30 19:33:10 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
loadPage(page, response1[0], response2[0]);
});
2014-07-10 21:27:46 -07:00
ApiClient.getNamedConfiguration(brandingConfigKey).done(function (config) {
2015-01-18 22:41:56 -07:00
currentBrandingOptions = config;
2014-07-10 21:27:46 -07:00
$('#txtLoginDisclaimer', page).val(config.LoginDisclaimer || '');
2015-01-18 22:41:56 -07:00
$('#txtCustomCss', page).val(config.CustomCss || '');
2014-07-10 21:27:46 -07:00
});
2014-07-19 21:46:29 -07:00
}).on('pageinit', "#dashboardGeneralPage", function () {
var page = this;
$('#btnSelectCachePath', page).on("click.selectDirectory", function () {
var picker = new DirectoryBrowser(page);
picker.show({
callback: function (path) {
if (path) {
$('#txtCachePath', page).val(path);
}
picker.close();
},
header: Globalize.translate('HeaderSelectServerCachePath'),
instruction: Globalize.translate('HeaderSelectServerCachePathHelp')
});
});
2014-03-30 19:33:10 -07:00
});
window.DashboardGeneralPage = {
onSubmit: function () {
Dashboard.showLoadingMsg();
var form = this;
2015-01-18 21:29:57 -07:00
var page = $(form).parents('.page');
2014-03-30 19:33:10 -07:00
ApiClient.getServerConfiguration().done(function (config) {
config.ServerName = $('#txtServerName', form).val();
config.UICulture = $('#selectLocalizationLanguage', form).val();
2014-07-19 21:46:29 -07:00
config.CachePath = $('#txtCachePath', form).val();
if (config.UICulture != currentLanguage) {
Dashboard.showDashboardRefreshNotification();
}
2014-07-19 21:46:29 -07:00
ApiClient.updateServerConfiguration(config).done(function () {
2015-01-18 21:29:57 -07:00
refreshPageTitle(page);
2014-07-10 21:27:46 -07:00
ApiClient.getNamedConfiguration(brandingConfigKey).done(function (brandingConfig) {
brandingConfig.LoginDisclaimer = $('#txtLoginDisclaimer', form).val();
2015-01-18 22:41:56 -07:00
brandingConfig.CustomCss = $('#txtCustomCss', form).val();
var cssChanged = currentBrandingOptions && brandingConfig.CustomCss != currentBrandingOptions.CustomCss;
2014-07-10 21:27:46 -07:00
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).done(Dashboard.processServerConfigurationUpdateResult);
2015-01-18 22:41:56 -07:00
if (cssChanged) {
Dashboard.showDashboardRefreshNotification();
}
2014-07-10 21:27:46 -07:00
});
});
2014-03-30 19:33:10 -07:00
});
// Disable default form submission
return false;
}
};
})(jQuery, document, window);