2016-03-18 21:26:17 -07:00
|
|
|
|
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;
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
2015-02-28 06:43:06 -07:00
|
|
|
|
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-05-31 21:11:04 -07:00
|
|
|
|
|
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
|
|
|
|
|
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");
|
2014-01-13 13:31:09 -07:00
|
|
|
|
|
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");
|
2015-06-30 16:59:45 -07:00
|
|
|
|
$('#chkEnableSharing', page).checked(user.Policy.EnablePublicSharing).checkboxradio("refresh");
|
2014-12-18 21:20:07 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2013-04-18 09:59:54 -07:00
|
|
|
|
}
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-30 15:07:48 -07:00
|
|
|
|
} function showEmbyConnectErrorMessage(username) {
|
|
|
|
|
|
|
|
|
|
var msg;
|
|
|
|
|
|
|
|
|
|
if (username) {
|
|
|
|
|
|
|
|
|
|
msg = Globalize.translate('ErrorAddingEmbyConnectAccount1', '<a href="https://emby.media/connect" target="_blank">https://emby.media/connect</a>');
|
|
|
|
|
msg += '<br/><br/>' + Globalize.translate('ErrorAddingEmbyConnectAccount2', 'apps@emby.media');
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
msg = Globalize.translate('DefaultErrorMessage');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
|
|
|
|
|
message: msg
|
|
|
|
|
|
|
|
|
|
});
|
2015-06-12 20:42:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 15:07:48 -07:00
|
|
|
|
|
2014-09-14 08:10:51 -07:00
|
|
|
|
function onSaveComplete(page, user) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 09:59:54 -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-04-18 09:59:54 -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();
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
getUser().then(function (result) {
|
2015-06-12 20:42:19 -07:00
|
|
|
|
saveUser(result, page);
|
|
|
|
|
});
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
2015-06-12 20:42:19 -07:00
|
|
|
|
// Disable default form submission
|
|
|
|
|
return false;
|
2013-04-18 09:59:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2015-08-31 23:22:46 -07:00
|
|
|
|
}).on('pagebeforeshow', "#editUserPage", function () {
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
2013-04-22 09:04:54 -07:00
|
|
|
|
|
2014-09-14 08:10:51 -07:00
|
|
|
|
loadData(page);
|
2014-10-15 20:26:39 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|