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

249 lines
8.2 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
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
}
2015-07-28 12:42:24 -07:00
$('.lnkEditUserPreferences', page).attr('href', 'mypreferencesmenu.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
2016-02-22 09:00:17 -07:00
$('#chkIsAdmin', page).checked(user.Policy.IsAdministrator);
2013-02-20 18:33:05 -07:00
2016-04-09 12:04:14 -07:00
$('#chkDisabled', page).checked(user.Policy.IsDisabled);
$('#chkIsHidden', page).checked(user.Policy.IsHidden);
$('#chkRemoteControlSharedDevices', page).checked(user.Policy.EnableSharedDeviceControl);
$('#chkEnableRemoteControlOtherUsers', page).checked(user.Policy.EnableRemoteControlOfOtherUsers);
2015-02-05 22:39:07 -07:00
2016-04-09 12:04:14 -07:00
$('#chkEnableDownloading', page).checked(user.Policy.EnableContentDownloading);
2013-07-08 09:13:21 -07:00
2016-04-09 12:04:14 -07:00
$('#chkManageLiveTv', page).checked(user.Policy.EnableLiveTvManagement);
$('#chkEnableLiveTvAccess', page).checked(user.Policy.EnableLiveTvAccess);
$('#chkEnableContentDeletion', page).checked(user.Policy.EnableContentDeletion);
2016-04-09 12:04:14 -07:00
$('#chkDisableUserPreferences', page).checked((!user.Policy.EnableUserPreferenceAccess));
2014-10-23 21:54:35 -07:00
2016-04-09 12:04:14 -07:00
$('#chkEnableMediaPlayback', page).checked(user.Policy.EnableMediaPlayback);
$('#chkEnableAudioPlaybackTranscoding', page).checked(user.Policy.EnableAudioPlaybackTranscoding);
$('#chkEnableVideoPlaybackTranscoding', page).checked(user.Policy.EnableVideoPlaybackTranscoding);
2015-04-05 08:01:57 -07:00
2016-04-09 12:04:14 -07:00
$('#chkEnableSync', page).checked(user.Policy.EnableSync);
$('#chkEnableSyncTranscoding', page).checked(user.Policy.EnableSyncTranscoding);
$('#chkEnableSharing', page).checked(user.Policy.EnablePublicSharing);
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
2015-12-14 08:43:03 -07:00
}).then(function () {
2015-06-12 20:42:19 -07:00
Dashboard.alert({
message: Globalize.translate('MessageEmbyAccontRemoved'),
title: Globalize.translate('HeaderEmbyAccountRemoved'),
callback: actionCallback
2015-10-26 09:21:00 -07:00
});
2015-12-14 08:43:03 -07:00
}, function () {
2015-10-26 09:21:00 -07:00
Dashboard.alert({
message: Globalize.translate('ErrorRemovingEmbyConnectAccount')
2015-06-12 20:42:19 -07:00
});
});
}
else if (currentConnectUsername != enteredConnectUsername) {
// Add/Update connect info
ApiClient.ajax({
type: "POST",
url: linkUrl,
data: {
ConnectUsername: enteredConnectUsername
},
dataType: 'json'
2015-12-14 08:43:03 -07:00
}).then(function (result) {
2015-06-12 20:42:19 -07:00
var msgKey = result.IsPending ? 'MessagePendingEmbyAccountAdded' : 'MessageEmbyAccountAdded';
Dashboard.alert({
message: Globalize.translate(msgKey),
title: Globalize.translate('HeaderEmbyAccountAdded'),
callback: actionCallback
2015-11-28 14:37:27 -07:00
});
2015-12-14 08:43:03 -07:00
}, function () {
2015-10-26 09:21:00 -07:00
2015-12-30 15:07:48 -07:00
showEmbyConnectErrorMessage('.');
2015-06-12 20:42:19 -07:00
});
2015-11-28 14:37:27 -07:00
2015-06-12 20:42:19 -07:00
} else {
if (noActionCallback) {
noActionCallback();
}
}
2016-07-22 22:16:26 -07:00
}
function showEmbyConnectErrorMessage(username) {
2015-12-30 15:07:48 -07:00
2016-04-10 14:11:06 -07:00
var html;
var text;
2015-12-30 15:07:48 -07:00
if (username) {
2016-04-10 14:11:06 -07:00
html = Globalize.translate('ErrorAddingEmbyConnectAccount1', '<a href="https://emby.media/connect" target="_blank">https://emby.media/connect</a>');
html += '<br/><br/>' + Globalize.translate('ErrorAddingEmbyConnectAccount2', 'apps@emby.media');
text = Globalize.translate('ErrorAddingEmbyConnectAccount1', 'https://emby.media/connect');
text += '\n\n' + Globalize.translate('ErrorAddingEmbyConnectAccount2', 'apps@emby.media');
2015-12-30 15:07:48 -07:00
} else {
2016-04-10 14:11:06 -07:00
html = text = Globalize.translate('DefaultErrorMessage');
2015-12-30 15:07:48 -07:00
}
2016-04-10 14:11:06 -07:00
require(['alert'], function (alert) {
alert({
text: text,
html: html
});
2015-12-30 15:07:48 -07:00
});
2015-06-12 20:42:19 -07:00
}
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) {
2016-02-24 23:38:12 -07:00
require(['toast'], function (toast) {
toast(Globalize.translate('SettingsSaved'));
});
2014-10-29 15:01:02 -07:00
} 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();
2015-06-30 16:59:45 -07:00
user.Policy.EnablePublicSharing = $('#chkEnableSharing', page).checked();
2014-12-18 21:20:07 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.updateUser(user).then(function () {
2014-12-18 21:20:07 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.updateUserPolicy(user.Id, user.Policy).then(function () {
2014-12-18 21:20:07 -07:00
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-12-14 08:43:03 -07:00
getUser().then(function (result) {
2015-06-12 20:42:19 -07:00
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();
2015-12-14 08:43:03 -07:00
getUser().then(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-09-01 07:01:59 -07:00
$(document).on('pageinit', "#editUserPage", function () {
2015-06-12 20:42:19 -07:00
$('.editUserProfileForm').off('submit', onSubmit).on('submit', onSubmit);
2013-02-20 18:33:05 -07:00
2016-06-29 19:38:20 -07:00
this.querySelector('.sharingHelp').innerHTML = Globalize.translate('OptionAllowLinkSharingHelp', 30);
2015-08-31 23:22:46 -07:00
}).on('pagebeforeshow', "#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
});