jellyfin-web/dashboard-ui/scripts/useredit.js

206 lines
7.2 KiB
JavaScript
Raw Normal View History

(function ($, window, document) {
2013-02-20 18:33:05 -07:00
2014-09-14 11:47:48 -07:00
var currentUser;
2014-09-14 08:10:51 -07:00
2014-10-29 15:01:02 -07:00
function loadUser(page, user) {
2014-09-14 08:10:51 -07:00
2014-09-14 11:47:48 -07:00
currentUser = user;
if (user.Policy.IsDisabled) {
$('.disabledUserBanner', page).show();
} else {
$('.disabledUserBanner', page).hide();
}
2014-10-13 21:22:17 -07:00
if (user.ConnectLinkType == 'Guest') {
2014-10-29 15:01:02 -07:00
$('#fldConnectInfo', page).hide();
2014-10-13 21:22:17 -07:00
$('#txtUserName', page).prop("disabled", "disabled");
} else {
$('#txtUserName', page).prop("disabled", "").removeAttr('disabled');
2014-10-29 15:01:02 -07:00
$('#fldConnectInfo', page).show();
2014-10-13 21:22:17 -07:00
}
2014-10-29 15:01:02 -07:00
$('.lnkEditUserPreferences', page).attr('href', 'mypreferencesdisplay.html?userId=' + user.Id);
2014-10-29 15:01:02 -07:00
Dashboard.setPageTitle(user.Name);
2013-02-20 18:33:05 -07:00
$('#txtUserName', page).val(user.Name);
2014-09-14 11:47:48 -07:00
$('#txtConnectUserName', page).val(currentUser.ConnectUserName);
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
$('#chkIsAdmin', page).checked(user.Policy.IsAdministrator).checkboxradio("refresh");
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
$('#chkDisabled', page).checked(user.Policy.IsDisabled).checkboxradio("refresh");
$('#chkIsHidden', page).checked(user.Policy.IsHidden).checkboxradio("refresh");
$('#chkRemoteControlSharedDevices', page).checked(user.Policy.EnableSharedDeviceControl).checkboxradio("refresh");
2014-12-19 23:06:27 -07:00
$('#chkEnableRemoteControlOtherUsers', page).checked(user.Policy.EnableRemoteControlOfOtherUsers).checkboxradio("refresh");
2015-02-05 22:39:07 -07:00
$('#chkEnableDownloading', page).checked(user.Policy.EnableContentDownloading).checkboxradio("refresh");
2013-07-08 09:13:21 -07:00
2015-01-09 22:53:35 -07:00
$('#chkManageLiveTv', page).checked(user.Policy.EnableLiveTvManagement).checkboxradio("refresh");
$('#chkEnableLiveTvAccess', page).checked(user.Policy.EnableLiveTvAccess).checkboxradio("refresh");
$('#chkEnableContentDeletion', page).checked(user.Policy.EnableContentDeletion).checkboxradio("refresh");
2015-01-09 22:53:35 -07:00
$('#chkDisableUserPreferences', page).checked((!user.Policy.EnableUserPreferenceAccess)).checkboxradio("refresh");
2014-10-23 21:54:35 -07:00
2015-04-05 08:01:57 -07:00
$('#chkEnableMediaPlayback', page).checked(user.Policy.EnableMediaPlayback).checkboxradio("refresh");
2015-04-08 22:20:23 -07:00
$('#chkEnableAudioPlaybackTranscoding', page).checked(user.Policy.EnableAudioPlaybackTranscoding).checkboxradio("refresh");
$('#chkEnableVideoPlaybackTranscoding', page).checked(user.Policy.EnableVideoPlaybackTranscoding).checkboxradio("refresh");
2015-04-05 08:01:57 -07:00
2014-12-18 21:20:07 -07:00
$('#chkEnableSync', page).checked(user.Policy.EnableSync).checkboxradio("refresh");
2015-04-05 08:01:57 -07:00
$('#chkEnableSyncTranscoding', page).checked(user.Policy.EnableSyncTranscoding).checkboxradio("refresh");
2014-12-18 21:20:07 -07:00
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
}
2013-02-20 18:33:05 -07:00
2015-06-12 20:42:19 -07:00
function updateUserInfo(user, newConnectUsername, actionCallback, noActionCallback) {
var currentConnectUsername = user.ConnectUserName || '';
var enteredConnectUsername = newConnectUsername;
var linkUrl = ApiClient.getUrl('Users/' + user.Id + '/Connect/Link');
if (currentConnectUsername && !enteredConnectUsername) {
// Remove connect info
// Add/Update connect info
ApiClient.ajax({
type: "DELETE",
url: linkUrl
}).done(function () {
Dashboard.alert({
message: Globalize.translate('MessageEmbyAccontRemoved'),
title: Globalize.translate('HeaderEmbyAccountRemoved'),
callback: actionCallback
});
});
}
else if (currentConnectUsername != enteredConnectUsername) {
// Add/Update connect info
ApiClient.ajax({
type: "POST",
url: linkUrl,
data: {
ConnectUsername: enteredConnectUsername
},
dataType: 'json'
}).done(function (result) {
var msgKey = result.IsPending ? 'MessagePendingEmbyAccountAdded' : 'MessageEmbyAccountAdded';
Dashboard.alert({
message: Globalize.translate(msgKey),
title: Globalize.translate('HeaderEmbyAccountAdded'),
callback: actionCallback
});
});
} else {
if (noActionCallback) {
noActionCallback();
}
}
}
2014-09-14 08:10:51 -07:00
function onSaveComplete(page, user) {
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
2013-02-20 18:33:05 -07:00
2014-10-29 15:01:02 -07:00
var currentConnectUsername = currentUser.ConnectUserName || '';
var enteredConnectUsername = $('#txtConnectUserName', page).val();
2014-09-14 08:10:51 -07:00
2014-10-29 15:01:02 -07:00
if (currentConnectUsername == enteredConnectUsername) {
Dashboard.alert(Globalize.translate('SettingsSaved'));
} else {
2014-09-14 08:10:51 -07:00
2015-06-12 20:42:19 -07:00
updateUserInfo(user, $('#txtConnectUserName', page).val(), function () {
2014-09-14 10:12:47 -07:00
2014-10-29 15:01:02 -07:00
loadData(page);
});
2014-09-14 08:10:51 -07:00
}
}
function saveUser(user, page) {
2013-02-20 18:33:05 -07:00
user.Name = $('#txtUserName', page).val();
2014-12-19 23:06:27 -07:00
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.EnableContentDeletion = $('#chkEnableContentDeletion', page).checked();
user.Policy.EnableUserPreferenceAccess = !$('#chkDisableUserPreferences', page).checked();
user.Policy.EnableSharedDeviceControl = $('#chkRemoteControlSharedDevices', page).checked();
2013-07-08 09:13:21 -07:00
2015-02-05 22:39:07 -07:00
user.Policy.EnableMediaPlayback = $('#chkEnableMediaPlayback', page).checked();
2015-04-08 22:20:23 -07:00
user.Policy.EnableAudioPlaybackTranscoding = $('#chkEnableAudioPlaybackTranscoding', page).checked();
user.Policy.EnableVideoPlaybackTranscoding = $('#chkEnableVideoPlaybackTranscoding', page).checked();
2015-04-05 08:01:57 -07:00
2015-02-05 22:39:07 -07:00
user.Policy.EnableContentDownloading = $('#chkEnableDownloading', page).checked();
2014-12-18 21:20:07 -07:00
user.Policy.EnableSync = $('#chkEnableSync', page).checked();
2015-04-05 08:01:57 -07:00
user.Policy.EnableSyncTranscoding = $('#chkEnableSyncTranscoding', page).checked();
2014-12-18 21:20:07 -07:00
2014-10-29 15:01:02 -07:00
ApiClient.updateUser(user).done(function () {
2014-12-18 21:20:07 -07:00
ApiClient.updateUserPolicy(user.Id, user.Policy).done(function () {
onSaveComplete(page, user);
});
2014-10-29 15:01:02 -07:00
});
}
2013-02-20 18:33:05 -07:00
2015-06-12 20:42:19 -07:00
function onSubmit() {
var page = $(this).parents('.page');
2013-02-20 18:33:05 -07:00
2015-06-12 20:42:19 -07:00
Dashboard.showLoadingMsg();
2015-06-12 20:42:19 -07:00
getUser().done(function (result) {
saveUser(result, page);
});
2015-06-12 20:42:19 -07:00
// Disable default form submission
return false;
}
2014-09-14 08:10:51 -07:00
function getUser() {
var userId = getParameterByName("userId");
2014-10-29 15:01:02 -07:00
return ApiClient.getUser(userId);
2014-09-14 08:10:51 -07:00
}
function loadData(page) {
Dashboard.showLoadingMsg();
2014-10-29 15:01:02 -07:00
getUser().done(function (user) {
2014-09-14 08:10:51 -07:00
2014-10-29 15:01:02 -07:00
loadUser(page, user);
2014-09-14 08:10:51 -07:00
});
}
2015-06-12 20:42:19 -07:00
$(document).on('pageinitdepends', "#editUserPage", function () {
$('.editUserProfileForm').off('submit', onSubmit).on('submit', onSubmit);
2013-02-20 18:33:05 -07:00
2015-06-12 20:42:19 -07:00
}).on('pagebeforeshowready', "#editUserPage", function () {
var page = this;
2014-09-14 08:10:51 -07:00
loadData(page);
2014-10-15 20:26:39 -07:00
});
2013-02-20 18:33:05 -07:00
2015-06-12 20:42:19 -07:00
})(jQuery, window, document);