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

159 lines
5.8 KiB
JavaScript
Raw Normal View History

2016-09-09 19:21:00 -07:00
define(['jQuery', 'fnchecked'], function ($) {
2016-10-22 22:11:46 -07:00
'use strict';
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);
LibraryMenu.setTitle(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);
2016-08-13 23:24:43 -07:00
$('#chkEnableVideoPlaybackRemuxing', page).checked(user.Policy.EnablePlaybackRemuxing);
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
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
2016-12-27 00:22:44 -07:00
require(['connectHelper'], function (connectHelper) {
connectHelper.updateUserLink(ApiClient, user, $('#txtConnectUserName', page).val()).then(function () {
2014-09-14 10:12:47 -07:00
2016-12-27 00:22:44 -07:00
loadData(page);
});
2014-10-29 15:01:02 -07:00
});
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();
2016-08-13 23:24:43 -07:00
user.Policy.EnablePlaybackRemuxing = $('#chkEnableVideoPlaybackRemuxing', 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
});