jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/usersettings/usersettingsbuilder.js

1 line
3.2 KiB
JavaScript
Raw Normal View History

2017-02-14 14:11:06 -07:00
define(["appSettings","events","browser"],function(appsettings,events,browser){"use strict";function UserSettings(){function onSaveTimeout(){saveTimeout=null,currentApiClient.updateDisplayPreferences("usersettings",displayPrefs,currentUserId,"emby")}function saveServerPreferences(){saveTimeout&&clearTimeout(saveTimeout),saveTimeout=setTimeout(onSaveTimeout,50)}var currentUserId,currentApiClient,displayPrefs,saveTimeout,self=this;self.setUserInfo=function(userId,apiClient){return saveTimeout&&clearTimeout(saveTimeout),currentUserId=userId,currentApiClient=apiClient,userId?apiClient.getDisplayPreferences("usersettings",userId,"emby").then(function(result){result.CustomPrefs=result.CustomPrefs||{},displayPrefs=result}):(displayPrefs=null,Promise.resolve())},self.getData=function(){return displayPrefs},self.importFrom=function(instance){displayPrefs=instance.getData()},self.set=function(name,value,enableOnServer){var userId=currentUserId;if(!userId)throw new Error("userId cannot be null");var currentValue=self.get(name);appsettings.set(name,value,userId),enableOnServer!==!1&&displayPrefs&&(displayPrefs.CustomPrefs[name]=null==value?value:value.toString(),saveServerPreferences()),currentValue!==value&&events.trigger(self,"change",[name])},self.get=function(name,enableOnServer){var userId=currentUserId;if(!userId)throw new Error("userId cannot be null");return enableOnServer!==!1&&displayPrefs?displayPrefs.CustomPrefs[name]:appsettings.get(name,userId)},self.serverConfig=function(config){var apiClient=currentApiClient;return config?apiClient.updateUserConfiguration(currentUserId,config):apiClient.getUser(currentUserId).then(function(user){return user.Configuration})},self.loadQuerySettings=function(){}}function getSavedQueryKey(context){return"query-"+context}return UserSettings.prototype.enableCinemaMode=function(val){return null!=val&&this.set("enableCinemaMode",val.toString(),!1),val=this.get("enableCinemaMode",!1),!val||"false"!==val},UserSettings.prototype.enableThemeSongs=function(val){return null!=val&&this.set("enableThemeSongs",val.toString(),!1),val=this.get("enableThemeSongs",!1),"false"!==val},UserSettings.prototype.enableThemeVideos=function(val){return null!=val&&this.set("enableThemeVideos",val.toString(),!1),val=this.get("enableThemeVideos",!1),val?"false"!==val:!browser.slow},UserSettings.prototype.language=function(val){return null!=val&&this.set("language",val.toString(),!1),this.get("language",!1)},UserSettings.prototype.skipBackLength=function(val){return null!=val&&this.set("skipBackLength",val.toString()),parseInt(this.get("skipBackLength")||"15000")},UserSettings.prototype.skipForwardLength=function(val){return null!=val&&this.set("skipForwardLength",val.toString()),parseInt(this.get("skipForwardLength")||"15000")},UserSettings.prototype.loadQuerySettings=function(query,context){var key=getSavedQueryKey(context),values=this.get(key);if(values)return values=JSON.parse(values),Object.assign(query,values)},UserSettings.prototype.saveQuerySettings=function(query,context){var key=getSavedQueryKey(context),values={};query.SortBy&&(values.SortBy=query.SortBy),query.SortOrder&&(values.SortOrder=query.SortOrder),this.set(key,JSON.stringify(values))},UserSettings});