jellyfin-web/dashboard-ui/scripts/useredit.js
2017-10-16 14:27:12 -04:00

1 line
5.6 KiB
JavaScript

define(["jQuery","loading","libraryMenu","fnchecked"],function($,loading,libraryMenu){"use strict";function loadDeleteFolders(page,user,mediaFolders){var html="";html+='<h3 class="checkboxListLabel">'+Globalize.translate("HeaderLibraries")+"</h3>",html+='<div class="checkboxList paperList checkboxList-paperList">';for(var i=0,length=mediaFolders.length;i<length;i++){var folder=mediaFolders[i],isChecked=user.Policy.EnableContentDeletion||user.Policy.EnableContentDeletionFromFolders.indexOf(folder.Id)!=-1,checkedAttribute=isChecked?' checked="checked"':"";html+='<label><input type="checkbox" is="emby-checkbox" class="chkFolder" data-id="'+folder.Id+'" '+checkedAttribute+"><span>"+folder.Name+"</span></label>"}html+="</div>",$(".deleteAccess",page).html(html).trigger("create"),$("#chkEnableDeleteAllFolders",page).checked(user.Policy.EnableContentDeletion).trigger("change")}function loadUser(page,user){currentUser=user,ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders",{IsHidden:!1})).then(function(folders){loadDeleteFolders(page,user,folders.Items)}),user.Policy.IsDisabled?$(".disabledUserBanner",page).show():$(".disabledUserBanner",page).hide(),"Guest"==user.ConnectLinkType?($("#fldConnectInfo",page).hide(),$("#txtUserName",page).prop("disabled","disabled")):($("#txtUserName",page).prop("disabled","").removeAttr("disabled"),$("#fldConnectInfo",page).show()),$(".lnkEditUserPreferences",page).attr("href","mypreferencesmenu.html?userId="+user.Id),libraryMenu.setTitle(user.Name),$("#txtUserName",page).val(user.Name),$("#txtConnectUserName",page).val(currentUser.ConnectUserName),$("#chkIsAdmin",page).checked(user.Policy.IsAdministrator),$("#chkDisabled",page).checked(user.Policy.IsDisabled),$("#chkIsHidden",page).checked(user.Policy.IsHidden),$("#chkRemoteControlSharedDevices",page).checked(user.Policy.EnableSharedDeviceControl),$("#chkEnableRemoteControlOtherUsers",page).checked(user.Policy.EnableRemoteControlOfOtherUsers),$("#chkEnableDownloading",page).checked(user.Policy.EnableContentDownloading),$("#chkManageLiveTv",page).checked(user.Policy.EnableLiveTvManagement),$("#chkEnableLiveTvAccess",page).checked(user.Policy.EnableLiveTvAccess),$("#chkEnableMediaPlayback",page).checked(user.Policy.EnableMediaPlayback),$("#chkEnableAudioPlaybackTranscoding",page).checked(user.Policy.EnableAudioPlaybackTranscoding),$("#chkEnableVideoPlaybackTranscoding",page).checked(user.Policy.EnableVideoPlaybackTranscoding),$("#chkEnableVideoPlaybackRemuxing",page).checked(user.Policy.EnablePlaybackRemuxing),$("#chkEnableSyncTranscoding",page).checked(user.Policy.EnableSyncTranscoding),$("#chkEnableSharing",page).checked(user.Policy.EnablePublicSharing),$("#txtRemoteClientBitrateLimit",page).val(user.Policy.RemoteClientBitrateLimit/1e6||""),loading.hide()}function onSaveComplete(page,user){loading.hide();var currentConnectUsername=currentUser.ConnectUserName||"",enteredConnectUsername=$("#txtConnectUserName",page).val();currentConnectUsername==enteredConnectUsername?require(["toast"],function(toast){toast(Globalize.translate("SettingsSaved"))}):require(["connectHelper"],function(connectHelper){connectHelper.updateUserLink(ApiClient,user,$("#txtConnectUserName",page).val()).then(function(){loadData(page)})})}function saveUser(user,page){user.Name=$("#txtUserName",page).val(),user.Policy.IsAdministrator=$("#chkIsAdmin",page).checked(),user.Policy.IsHidden=$("#chkIsHidden",page).checked(),user.Policy.IsDisabled=$("#chkDisabled",page).checked(),user.Policy.EnableRemoteControlOfOtherUsers=$("#chkEnableRemoteControlOtherUsers",page).checked(),user.Policy.EnableLiveTvManagement=$("#chkManageLiveTv",page).checked(),user.Policy.EnableLiveTvAccess=$("#chkEnableLiveTvAccess",page).checked(),user.Policy.EnableSharedDeviceControl=$("#chkRemoteControlSharedDevices",page).checked(),user.Policy.EnableMediaPlayback=$("#chkEnableMediaPlayback",page).checked(),user.Policy.EnableAudioPlaybackTranscoding=$("#chkEnableAudioPlaybackTranscoding",page).checked(),user.Policy.EnableVideoPlaybackTranscoding=$("#chkEnableVideoPlaybackTranscoding",page).checked(),user.Policy.EnablePlaybackRemuxing=$("#chkEnableVideoPlaybackRemuxing",page).checked(),user.Policy.EnableContentDownloading=$("#chkEnableDownloading",page).checked(),user.Policy.EnableSyncTranscoding=$("#chkEnableSyncTranscoding",page).checked(),user.Policy.EnablePublicSharing=$("#chkEnableSharing",page).checked(),user.Policy.RemoteClientBitrateLimit=parseInt(1e6*parseFloat($("#txtRemoteClientBitrateLimit",page).val()||"0")),user.Policy.EnableContentDeletion=$("#chkEnableDeleteAllFolders",page).checked(),user.Policy.EnableContentDeletionFromFolders=user.Policy.EnableContentDeletion?[]:$(".chkFolder",page).get().filter(function(c){return c.checked}).map(function(c){return c.getAttribute("data-id")}),ApiClient.updateUser(user).then(function(){ApiClient.updateUserPolicy(user.Id,user.Policy).then(function(){onSaveComplete(page,user)})})}function onSubmit(){var page=$(this).parents(".page");return loading.show(),getUser().then(function(result){saveUser(result,page)}),!1}function getUser(){var userId=getParameterByName("userId");return ApiClient.getUser(userId)}function loadData(page){loading.show(),getUser().then(function(user){loadUser(page,user)})}var currentUser;$(document).on("pageinit","#editUserPage",function(){$(".editUserProfileForm").off("submit",onSubmit).on("submit",onSubmit),this.querySelector(".sharingHelp").innerHTML=Globalize.translate("OptionAllowLinkSharingHelp",30);var page=this;$("#chkEnableDeleteAllFolders",this).on("change",function(){this.checked?$(".deleteAccessListContainer",page).hide():$(".deleteAccessListContainer",page).show()})}).on("pagebeforeshow","#editUserPage",function(){var page=this;loadData(page)})});