Apply suggestions from JustAMan code review

https://www.youtube.com/watch?v=-CmadmM5cOk

Co-Authored-By: LogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>
This commit is contained in:
Vasily 2019-03-19 23:12:23 -07:00 committed by GitHub
parent dab41fe6e1
commit 22649b66a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 54 deletions

View File

@ -22,42 +22,52 @@ define(["jQuery", "loading", "libraryMenu", "fnchecked"], function($, loading, l
}
function loadUser(page, user) {
currentUser = user,
currentUser = user;
ApiClient.getJSON(ApiClient.getUrl("Auth/Providers")).then(function(providers) {
loadAuthProviders(page, user, providers)
}),
});
ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", {
IsHidden: !1
IsHidden: false
})).then(function(folders) {
loadDeleteFolders(page, user, folders.Items)
}),
user.Policy.IsDisabled ? $(".disabledUserBanner", page).show() : $(".disabledUserBanner", page).hide(),
});
if (user.Policy.IsDisabled) {
$(".disabledUserBanner", page).show();
} else {
$(".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),
page.querySelector(".username").innerHTML = user.Name,
$("#txtUserName", page).val(user.Name),
$("#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),
$("#chkRemoteAccess", page).checked(null == user.Policy.EnableRemoteAccess || user.Policy.EnableRemoteAccess),
$("#chkEnableSyncTranscoding", page).checked(user.Policy.EnableSyncTranscoding),
$("#chkEnableConversion", page).checked(user.Policy.EnableMediaConversion || !1),
$("#chkEnableSharing", page).checked(user.Policy.EnablePublicSharing),
$("#txtRemoteClientBitrateLimit", page).val(user.Policy.RemoteClientBitrateLimit / 1e6 || ""),
$("#txtLoginAttemptsBeforeLockout", page).val(user.Policy.LoginAttemptsBeforeLockout || "0"),
loading.hide()
if ("Guest" == user.ConnectLinkType) {
$("#fldConnectInfo", page).hide();
$("#txtUserName", page).prop("disabled", "disabled");
} else {
$("#txtUserName", page).prop("disabled", "").removeAttr("disabled");
$("#fldConnectInfo", page).show();
}
$(".lnkEditUserPreferences", page).attr("href", "mypreferencesmenu.html?userId=" + user.Id);
libraryMenu.setTitle(user.Name);
page.querySelector(".username").innerHTML = user.Name;
$("#txtUserName", page).val(user.Name);
$("#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);
$("#chkRemoteAccess", page).checked(null == user.Policy.EnableRemoteAccess || user.Policy.EnableRemoteAccess);
$("#chkEnableSyncTranscoding", page).checked(user.Policy.EnableSyncTranscoding);
$("#chkEnableConversion", page).checked(user.Policy.EnableMediaConversion || false);
$("#chkEnableSharing", page).checked(user.Policy.EnablePublicSharing);
$("#txtRemoteClientBitrateLimit", page).val(user.Policy.RemoteClientBitrateLimit / 1e6 || "");
$("#txtLoginAttemptsBeforeLockout", page).val(user.Policy.LoginAttemptsBeforeLockout || "0");
loading.hide();
}
function onSaveComplete(page, user) {
@ -69,32 +79,32 @@ define(["jQuery", "loading", "libraryMenu", "fnchecked"], function($, loading, l
}
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.EnableMediaConversion = $("#chkEnableConversion", page).checked(),
user.Policy.EnablePublicSharing = $("#chkEnableSharing", page).checked(),
user.Policy.EnableRemoteAccess = $("#chkRemoteAccess", page).checked(),
user.Policy.RemoteClientBitrateLimit = parseInt(1e6 * parseFloat($("#txtRemoteClientBitrateLimit", page).val() || "0")),
user.Policy.LoginAttemptsBeforeLockout = parseInt($("#txtLoginAttemptsBeforeLockout", page).val() || "0"),
user.Policy.AuthenticationProviderId = page.querySelector(".selectLoginProvider").value,
user.Policy.EnableContentDeletion = $("#chkEnableDeleteAllFolders", page).checked(),
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.EnableMediaConversion = $("#chkEnableConversion", page).checked();
user.Policy.EnablePublicSharing = $("#chkEnableSharing", page).checked();
user.Policy.EnableRemoteAccess = $("#chkRemoteAccess", page).checked();
user.Policy.RemoteClientBitrateLimit = parseInt(1e6 * parseFloat($("#txtRemoteClientBitrateLimit", page).val() || "0"));
user.Policy.LoginAttemptsBeforeLockout = parseInt($("#txtLoginAttemptsBeforeLockout", page).val() || "0");
user.Policy.AuthenticationProviderId = page.querySelector(".selectLoginProvider").value;
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)

View File

@ -1300,7 +1300,7 @@
"LabelUserAgent": "User agent:",
"LabelUserLibrary": "User library:",
"LabelUserLibraryHelp": "Select which user library to display to the device. Leave empty to inherit the default setting.",
"LabelUserLoginAttemptsBeforeLockout": "Failed Logins before Lockout:",
"LabelUserLoginAttemptsBeforeLockout": "Failed login attempts before user is locked out:",
"LabelUserRemoteClientBitrateLimitHelp": "This will override the default global value set in server playback settings.",
"LabelUsername": "Username:",
"LabelVaapiDevice": "VA API Device:",
@ -1697,8 +1697,8 @@
"OptionLikes": "Likes",
"OptionList": "List",
"OptionLocked": "Locked",
"OptionLoginAttemptsBeforeLockout": "Determines how many incorrect password attempts can be made before lockout occurs.",
"OptionLoginAttemptsBeforeLockoutHelp":"0 inherits the old default of 3 for non admin and 5 for admin, -1 to disable lockout",
"OptionLoginAttemptsBeforeLockout": "Determines how many incorrect login attempts can be made before lockout occurs.",
"OptionLoginAttemptsBeforeLockoutHelp": "0 means inheriting the default of 3 for non-admin and 5 for admin, -1 disables lockout",
"OptionLogo": "Logo",
"OptionMax": "Max",
"OptionMenu": "Menu",