2020-07-09 13:47:12 +01:00
|
|
|
import $ from 'jQuery';
|
|
|
|
import loading from 'loading';
|
|
|
|
import libraryMenu from 'libraryMenu';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function loadDeleteFolders(page, user, mediaFolders) {
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Channels', {
|
2019-11-06 13:43:39 +03:00
|
|
|
SupportsMediaDeletion: true
|
|
|
|
})).then(function (channelsResult) {
|
2020-07-11 14:04:11 +01:00
|
|
|
let isChecked;
|
|
|
|
let checkedAttribute;
|
|
|
|
let html = '';
|
|
|
|
|
2020-07-24 13:08:49 +02:00
|
|
|
for (const folder of mediaFolders) {
|
2020-07-30 16:07:13 +02:00
|
|
|
isChecked = user.Policy.EnableContentDeletion || user.Policy.EnableContentDeletionFromFolders.indexOf(folder.Id) != -1;
|
2020-05-04 12:44:12 +02:00
|
|
|
checkedAttribute = isChecked ? ' checked="checked"' : '';
|
|
|
|
html += '<label><input type="checkbox" is="emby-checkbox" class="chkFolder" data-id="' + folder.Id + '" ' + checkedAttribute + '><span>' + folder.Name + '</span></label>';
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-07-25 13:42:03 +02:00
|
|
|
for (const folder of channelsResult.Items) {
|
2020-07-30 16:07:13 +02:00
|
|
|
isChecked = user.Policy.EnableContentDeletion || user.Policy.EnableContentDeletionFromFolders.indexOf(folder.Id) != -1;
|
2020-05-04 12:44:12 +02:00
|
|
|
checkedAttribute = isChecked ? ' checked="checked"' : '';
|
|
|
|
html += '<label><input type="checkbox" is="emby-checkbox" class="chkFolder" data-id="' + folder.Id + '" ' + checkedAttribute + '><span>' + folder.Name + '</span></label>';
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.deleteAccess', page).html(html).trigger('create');
|
2020-06-07 17:14:01 -06:00
|
|
|
$('#chkEnableDeleteAllFolders', page).prop('checked', user.Policy.EnableContentDeletion);
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadAuthProviders(page, user, providers) {
|
2019-11-06 13:43:39 +03:00
|
|
|
if (providers.length > 1) {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.fldSelectLoginProvider').classList.remove('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.fldSelectLoginProvider').classList.add('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-07-11 14:04:11 +01:00
|
|
|
const currentProviderId = user.Policy.AuthenticationProviderId;
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.selectLoginProvider').innerHTML = providers.map(function (provider) {
|
2020-07-11 14:04:11 +01:00
|
|
|
const selected = provider.Id === currentProviderId || providers.length < 2 ? ' selected' : '';
|
2020-05-04 12:44:12 +02:00
|
|
|
return '<option value="' + provider.Id + '"' + selected + '>' + provider.Name + '</option>';
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-03-22 00:12:01 -07:00
|
|
|
function loadPasswordResetProviders(page, user, providers) {
|
2019-11-06 13:43:39 +03:00
|
|
|
if (providers.length > 1) {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.fldSelectPasswordResetProvider').classList.remove('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.fldSelectPasswordResetProvider').classList.add('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-07-11 14:04:11 +01:00
|
|
|
const currentProviderId = user.Policy.PasswordResetProviderId;
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.selectPasswordResetProvider').innerHTML = providers.map(function (provider) {
|
2020-07-11 14:04:11 +01:00
|
|
|
const selected = provider.Id === currentProviderId || providers.length < 2 ? ' selected' : '';
|
2020-05-04 12:44:12 +02:00
|
|
|
return '<option value="' + provider.Id + '"' + selected + '>' + provider.Name + '</option>';
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2019-03-22 00:12:01 -07:00
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function loadUser(page, user) {
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Auth/Providers')).then(function (providers) {
|
2019-11-06 13:43:39 +03:00
|
|
|
loadAuthProviders(page, user, providers);
|
2019-03-19 23:12:23 -07:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Auth/PasswordResetProviders')).then(function (providers) {
|
2019-11-06 13:43:39 +03:00
|
|
|
loadPasswordResetProviders(page, user, providers);
|
2019-03-22 00:12:01 -07:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Library/MediaFolders', {
|
2019-11-06 13:43:39 +03:00
|
|
|
IsHidden: false
|
|
|
|
})).then(function (folders) {
|
|
|
|
loadDeleteFolders(page, user, folders.Items);
|
2019-03-19 23:12:23 -07:00
|
|
|
});
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-03-19 23:12:23 -07:00
|
|
|
if (user.Policy.IsDisabled) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.disabledUserBanner', page).show();
|
2019-03-19 23:12:23 -07:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.disabledUserBanner', page).hide();
|
2019-03-19 23:12:23 -07:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#txtUserName', page).prop('disabled', '').removeAttr('disabled');
|
|
|
|
$('#fldConnectInfo', page).show();
|
|
|
|
$('.lnkEditUserPreferences', page).attr('href', 'mypreferencesmenu.html?userId=' + user.Id);
|
2019-03-19 23:12:23 -07:00
|
|
|
libraryMenu.setTitle(user.Name);
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.username').innerHTML = user.Name;
|
|
|
|
$('#txtUserName', page).val(user.Name);
|
2020-06-07 17:14:01 -06:00
|
|
|
$('#chkIsAdmin', page).prop('checked', user.Policy.IsAdministrator);
|
|
|
|
$('#chkDisabled', page).prop('checked', user.Policy.IsDisabled);
|
|
|
|
$('#chkIsHidden', page).prop('checked', user.Policy.IsHidden);
|
|
|
|
$('#chkRemoteControlSharedDevices', page).prop('checked', user.Policy.EnableSharedDeviceControl);
|
|
|
|
$('#chkEnableRemoteControlOtherUsers', page).prop('checked', user.Policy.EnableRemoteControlOfOtherUsers);
|
|
|
|
$('#chkEnableDownloading', page).prop('checked', user.Policy.EnableContentDownloading);
|
|
|
|
$('#chkManageLiveTv', page).prop('checked', user.Policy.EnableLiveTvManagement);
|
|
|
|
$('#chkEnableLiveTvAccess', page).prop('checked', user.Policy.EnableLiveTvAccess);
|
|
|
|
$('#chkEnableMediaPlayback', page).prop('checked', user.Policy.EnableMediaPlayback);
|
|
|
|
$('#chkEnableAudioPlaybackTranscoding', page).prop('checked', user.Policy.EnableAudioPlaybackTranscoding);
|
|
|
|
$('#chkEnableVideoPlaybackTranscoding', page).prop('checked', user.Policy.EnableVideoPlaybackTranscoding);
|
|
|
|
$('#chkEnableVideoPlaybackRemuxing', page).prop('checked', user.Policy.EnablePlaybackRemuxing);
|
|
|
|
$('#chkForceRemoteSourceTranscoding', page).prop('checked', user.Policy.ForceRemoteSourceTranscoding);
|
2020-07-30 16:07:13 +02:00
|
|
|
$('#chkRemoteAccess', page).prop('checked', user.Policy.EnableRemoteAccess == null || user.Policy.EnableRemoteAccess);
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#txtRemoteClientBitrateLimit', page).val(user.Policy.RemoteClientBitrateLimit / 1e6 || '');
|
|
|
|
$('#txtLoginAttemptsBeforeLockout', page).val(user.Policy.LoginAttemptsBeforeLockout || '0');
|
2020-10-04 16:48:34 -04:00
|
|
|
$('#txtMaxActiveSessions', page).val(user.Policy.MaxActiveSessions || '0');
|
2020-07-22 18:49:35 +02:00
|
|
|
if (ApiClient.isMinServerVersion('10.6.0')) {
|
|
|
|
$('#selectSyncPlayAccess').val(user.Policy.SyncPlayAccess);
|
|
|
|
}
|
2019-03-19 23:12:23 -07:00
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSaveComplete(page, user) {
|
2020-05-04 12:44:12 +02:00
|
|
|
Dashboard.navigate('userprofiles.html');
|
2019-01-25 23:54:54 -05:00
|
|
|
loading.hide();
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-09 13:47:12 +01:00
|
|
|
import('toast').then(({default: toast}) => {
|
2020-05-04 12:44:12 +02:00
|
|
|
toast(globalize.translate('SettingsSaved'));
|
2019-01-25 23:54:54 -05:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveUser(user, page) {
|
2020-05-04 12:44:12 +02:00
|
|
|
user.Name = $('#txtUserName', page).val();
|
2020-06-07 17:14:01 -06:00
|
|
|
user.Policy.IsAdministrator = $('#chkIsAdmin', page).is(':checked');
|
|
|
|
user.Policy.IsHidden = $('#chkIsHidden', page).is(':checked');
|
|
|
|
user.Policy.IsDisabled = $('#chkDisabled', page).is(':checked');
|
|
|
|
user.Policy.EnableRemoteControlOfOtherUsers = $('#chkEnableRemoteControlOtherUsers', page).is(':checked');
|
|
|
|
user.Policy.EnableLiveTvManagement = $('#chkManageLiveTv', page).is(':checked');
|
|
|
|
user.Policy.EnableLiveTvAccess = $('#chkEnableLiveTvAccess', page).is(':checked');
|
|
|
|
user.Policy.EnableSharedDeviceControl = $('#chkRemoteControlSharedDevices', page).is(':checked');
|
|
|
|
user.Policy.EnableMediaPlayback = $('#chkEnableMediaPlayback', page).is(':checked');
|
|
|
|
user.Policy.EnableAudioPlaybackTranscoding = $('#chkEnableAudioPlaybackTranscoding', page).is(':checked');
|
|
|
|
user.Policy.EnableVideoPlaybackTranscoding = $('#chkEnableVideoPlaybackTranscoding', page).is(':checked');
|
|
|
|
user.Policy.EnablePlaybackRemuxing = $('#chkEnableVideoPlaybackRemuxing', page).is(':checked');
|
|
|
|
user.Policy.ForceRemoteSourceTranscoding = $('#chkForceRemoteSourceTranscoding', page).is(':checked');
|
|
|
|
user.Policy.EnableContentDownloading = $('#chkEnableDownloading', page).is(':checked');
|
|
|
|
user.Policy.EnableRemoteAccess = $('#chkRemoteAccess', page).is(':checked');
|
2020-05-04 12:44:12 +02:00
|
|
|
user.Policy.RemoteClientBitrateLimit = parseInt(1e6 * parseFloat($('#txtRemoteClientBitrateLimit', page).val() || '0'));
|
|
|
|
user.Policy.LoginAttemptsBeforeLockout = parseInt($('#txtLoginAttemptsBeforeLockout', page).val() || '0');
|
2020-10-04 16:48:34 -04:00
|
|
|
user.Policy.MaxActiveSessions = parseInt($('#txtMaxActiveSessions', page).val() || '0');
|
2020-05-04 12:44:12 +02:00
|
|
|
user.Policy.AuthenticationProviderId = page.querySelector('.selectLoginProvider').value;
|
|
|
|
user.Policy.PasswordResetProviderId = page.querySelector('.selectPasswordResetProvider').value;
|
2020-06-07 17:14:01 -06:00
|
|
|
user.Policy.EnableContentDeletion = $('#chkEnableDeleteAllFolders', page).is(':checked');
|
2020-05-04 12:44:12 +02:00
|
|
|
user.Policy.EnableContentDeletionFromFolders = user.Policy.EnableContentDeletion ? [] : $('.chkFolder', page).get().filter(function (c) {
|
2019-11-06 13:43:39 +03:00
|
|
|
return c.checked;
|
|
|
|
}).map(function (c) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return c.getAttribute('data-id');
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2020-07-22 18:49:35 +02:00
|
|
|
if (ApiClient.isMinServerVersion('10.6.0')) {
|
|
|
|
user.Policy.SyncPlayAccess = page.querySelector('#selectSyncPlayAccess').value;
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.updateUser(user).then(function () {
|
|
|
|
ApiClient.updateUserPolicy(user.Id, user.Policy).then(function () {
|
|
|
|
onSaveComplete(page, user);
|
|
|
|
});
|
2019-03-19 23:12:23 -07:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSubmit() {
|
2020-07-11 14:04:11 +01:00
|
|
|
const page = $(this).parents('.page')[0];
|
2019-11-06 13:43:39 +03:00
|
|
|
loading.show();
|
|
|
|
getUser().then(function (result) {
|
|
|
|
saveUser(result, page);
|
|
|
|
});
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getUser() {
|
2020-07-11 14:04:11 +01:00
|
|
|
const userId = getParameterByName('userId');
|
2019-11-06 13:43:39 +03:00
|
|
|
return ApiClient.getUser(userId);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadData(page) {
|
2019-11-06 13:43:39 +03:00
|
|
|
loading.show();
|
|
|
|
getUser().then(function (user) {
|
|
|
|
loadUser(page, user);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
$(document).on('pageinit', '#editUserPage', function () {
|
|
|
|
$('.editUserProfileForm').off('submit', onSubmit).on('submit', onSubmit);
|
|
|
|
this.querySelector('.sharingHelp').innerHTML = globalize.translate('OptionAllowLinkSharingHelp', 30);
|
2020-07-11 14:04:11 +01:00
|
|
|
const page = this;
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#chkEnableDeleteAllFolders', this).on('change', function () {
|
2019-11-06 13:43:39 +03:00
|
|
|
if (this.checked) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.deleteAccess', page).hide();
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.deleteAccess', page).show();
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
ApiClient.getServerConfiguration().then(function (config) {
|
|
|
|
if (config.EnableRemoteAccess) {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.fldRemoteAccess').classList.remove('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.fldRemoteAccess').classList.add('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
}).on('pagebeforeshow', '#editUserPage', function () {
|
2019-11-06 13:43:39 +03:00
|
|
|
loadData(this);
|
|
|
|
});
|
2020-07-09 13:47:12 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|