jellyfin-web/dashboard-ui/scripts/mypreferencesdisplay.js
Luke Pulverenti a0034208f6 update themes
2017-07-30 14:05:24 -04:00

1 line
3.2 KiB
JavaScript

define(["userSettingsBuilder","appStorage","loading","skinManager","emby-linkbutton"],function(userSettingsBuilder,appStorage,loading,skinManager){"use strict";return function(view,params){function loadForm(page,user){user.Policy.IsAdministrator?page.querySelector(".selectDashboardThemeContainer").classList.remove("hide"):page.querySelector(".selectDashboardThemeContainer").classList.add("hide"),userSettingsInstance.setUserInfo(userId,ApiClient).then(function(){userSettingsLoaded=!0,page.querySelector(".chkDisplayMissingEpisodes").checked=user.Configuration.DisplayMissingEpisodes||!1,page.querySelector(".chkDisplayUnairedEpisodes").checked=user.Configuration.DisplayUnairedEpisodes||!1,page.querySelector("#chkThemeSong").checked=userSettingsInstance.enableThemeSongs(),page.querySelector("#selectBackdrop").value=appStorage.getItem("enableBackdrops-"+user.Id)||"0",page.querySelector("#selectLanguage").value=userSettingsInstance.language()||"",page.querySelector("#selectDashboardTheme").value=userSettingsInstance.dashboardTheme()||"",page.querySelector("#selectTheme").value=userSettingsInstance.appTheme()||"",loading.hide()})}function refreshGlobalUserSettings(){require(["userSettings"],function(userSettings){userSettings.importFrom(userSettingsInstance)})}function saveUser(page,user){return user.Configuration.DisplayMissingEpisodes=page.querySelector(".chkDisplayMissingEpisodes").checked,user.Configuration.DisplayUnairedEpisodes=page.querySelector(".chkDisplayUnairedEpisodes").checked,userSettingsLoaded&&(AppInfo.supportsUserDisplayLanguageSetting&&userSettingsInstance.language(page.querySelector("#selectLanguage").value),userSettingsInstance.enableThemeSongs(page.querySelector("#chkThemeSong").checked),userSettingsInstance.dashboardTheme(page.querySelector("#selectDashboardTheme").value),userSettingsInstance.appTheme(page.querySelector("#selectTheme").value),userId===Dashboard.getCurrentUserId()&&(skinManager.setTheme(userSettingsInstance.appTheme()||"dark"),refreshGlobalUserSettings())),appStorage.setItem("enableBackdrops-"+user.Id,page.querySelector("#selectBackdrop").value),ApiClient.updateUserConfiguration(user.Id,user.Configuration)}function save(page){AppInfo.enableAutoSave||loading.show(),ApiClient.getUser(userId).then(function(user){saveUser(page,user).then(function(){loading.hide(),AppInfo.enableAutoSave||require(["toast"],function(toast){toast(Globalize.translate("SettingsSaved"))})},function(){loading.hide()})})}var userSettingsLoaded,userId=params.userId||Dashboard.getCurrentUserId(),userSettingsInstance=new userSettingsBuilder;view.querySelector(".displayPreferencesForm").addEventListener("submit",function(e){return save(view),e.preventDefault(),!1}),AppInfo.enableAutoSave?view.querySelector(".btnSave").classList.add("hide"):view.querySelector(".btnSave").classList.remove("hide"),view.addEventListener("viewshow",function(){var page=this;loading.show(),ApiClient.getUser(userId).then(function(user){loadForm(page,user)}),AppInfo.supportsUserDisplayLanguageSetting?page.querySelector(".languageSection").classList.remove("hide"):page.querySelector(".languageSection").classList.add("hide")}),view.addEventListener("viewbeforehide",function(){var page=this;AppInfo.enableAutoSave&&save(page)})}});