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

107 lines
5.9 KiB
JavaScript
Raw Normal View History

2018-10-23 01:05:09 +03:00
define(["jQuery", "loading", "fnchecked", "emby-checkbox", "emby-textarea", "emby-input", "emby-select", "emby-linkbutton"], function($, loading) {
"use strict";
function loadPage(page, config, languageOptions, systemInfo) {
2019-03-05 21:30:06 +09:00
systemInfo.CanLaunchWebBrowser ? page.querySelector("#fldRunWebAppAtStartup").classList.remove("hide") : page.querySelector("#fldRunWebAppAtStartup").classList.add("hide");
page.querySelector("#txtCachePath").value = config.CachePath || "";
$("#txtMetadataPath", page).val(config.MetadataPath || "");
$("#txtMetadataNetworkPath", page).val(config.MetadataNetworkPath || "");
2019-03-05 21:30:06 +09:00
$("#selectLocalizationLanguage", page).html(languageOptions.map(function(l) {
2018-10-23 01:05:09 +03:00
return '<option value="' + l.Value + '">' + l.Name + "</option>"
2019-03-05 21:30:06 +09:00
})).val(config.UICulture);
currentLanguage = config.UICulture;
systemInfo.CanSelfUpdate ? page.querySelector(".fldAutomaticUpdates").classList.remove("hide") : page.querySelector(".fldAutomaticUpdates").classList.add("hide");
$("#chkEnableAutomaticServerUpdates", page).checked(config.EnableAutoUpdate);
$("#chkEnableAutomaticRestart", page).checked(config.EnableAutomaticRestart);
systemInfo.CanSelfRestart ? page.querySelector("#fldEnableAutomaticRestart").classList.remove("hide") : page.querySelector("#fldEnableAutomaticRestart").classList.add("hide");
systemInfo.CanSelfRestart || systemInfo.CanSelfUpdate ? $(".autoUpdatesContainer", page).removeClass("hide") : $(".autoUpdatesContainer", page).addClass("hide");
loading.hide();
2018-10-23 01:05:09 +03:00
}
function onSubmit() {
loading.show();
var form = this;
$(form).parents(".page");
return ApiClient.getServerConfiguration().then(function(config) {
config.UICulture = $("#selectLocalizationLanguage", form).val();
config.CachePath = form.querySelector("#txtCachePath").value;
config.MetadataPath = $("#txtMetadataPath", form).val();
config.MetadataNetworkPath = $("#txtMetadataNetworkPath", form).val();
var requiresReload = false;
if (config.UICulture !== currentLanguage) {
requiresReload = true;
}
config.EnableAutomaticRestart = $("#chkEnableAutomaticRestart", form).checked();
config.EnableAutoUpdate = $("#chkEnableAutomaticServerUpdates", form).checked();
ApiClient.updateServerConfiguration(config).then(function() {
2018-10-23 01:05:09 +03:00
ApiClient.getNamedConfiguration(brandingConfigKey).then(function(brandingConfig) {
brandingConfig.LoginDisclaimer = form.querySelector("#txtLoginDisclaimer").value;
brandingConfig.CustomCss = form.querySelector("#txtCustomCss").value;
currentBrandingOptions && brandingConfig.CustomCss !== currentBrandingOptions.CustomCss && (requiresReload = !0);
ApiClient.updateNamedConfiguration(brandingConfigKey, brandingConfig).then(function() {
Dashboard.processServerConfigurationUpdateResult();
if (requiresReload && !AppInfo.isNativeApp) {
window.location.reload(true);
}
});
2018-10-23 01:05:09 +03:00
})
})
}), !1
}
2019-03-05 21:30:06 +09:00
var currentBrandingOptions;
var currentLanguage;
var brandingConfigKey = "branding";
2018-10-23 01:05:09 +03:00
return function(view, params) {
$("#btnSelectCachePath", view).on("click.selectDirectory", function() {
require(["directorybrowser"], function(directoryBrowser) {
var picker = new directoryBrowser;
picker.show({
callback: function(path) {
2019-03-05 21:30:06 +09:00
path && (view.querySelector("#txtCachePath").value = path);
picker.close();
2018-10-23 01:05:09 +03:00
},
2019-03-05 21:30:06 +09:00
validateWriteable: true,
2018-10-23 01:05:09 +03:00
header: Globalize.translate("HeaderSelectServerCachePath"),
instruction: Globalize.translate("HeaderSelectServerCachePathHelp")
})
})
});
$("#btnSelectMetadataPath", view).on("click.selectDirectory", function() {
require(["directorybrowser"], function(directoryBrowser) {
var picker = new directoryBrowser;
picker.show({
path: $("#txtMetadataPath", view).val(),
networkSharePath: $("#txtMetadataNetworkPath", view).val(),
callback: function(path, networkPath) {
2019-03-05 21:59:52 +09:00
path && $("#txtMetadataPath", view).val(path);
networkPath && $("#txtMetadataNetworkPath", view).val(networkPath);
2019-03-05 21:30:06 +09:00
picker.close();
},
2019-03-05 21:30:06 +09:00
validateWriteable: true,
header: Globalize.translate("HeaderSelectMetadataPath"),
instruction: Globalize.translate("HeaderSelectMetadataPathHelp"),
2019-03-05 21:30:06 +09:00
enableNetworkSharePath: true
})
})
});
2019-03-05 21:30:06 +09:00
$(".dashboardGeneralForm", view).off("submit", onSubmit).on("submit", onSubmit);
view.addEventListener("viewshow", function() {
var promise1 = ApiClient.getServerConfiguration();
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Localization/Options"));
var promise3 = ApiClient.getSystemInfo();
2018-10-23 01:05:09 +03:00
Promise.all([promise1, promise2, promise3]).then(function(responses) {
2019-03-05 21:30:06 +09:00
loadPage(view, responses[0], responses[1], responses[2]);
});
ApiClient.getNamedConfiguration(brandingConfigKey).then(function(config) {
currentBrandingOptions = config;
view.querySelector("#txtLoginDisclaimer").value = config.LoginDisclaimer || "";
view.querySelector("#txtCustomCss").value = config.CustomCss || "";
});
});
2018-10-23 01:05:09 +03:00
}
});