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

204 lines
6.5 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;
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
2014-12-19 23:06:27 -07:00
$('#chkIsAdmin', page).checked(user.Policy.IsAdministrator || false).checkboxradio("refresh");
2013-02-20 18:33:05 -07:00
2014-12-19 23:06:27 -07:00
$('#chkDisabled', page).checked(user.Policy.IsDisabled || false).checkboxradio("refresh");
$('#chkIsHidden', page).checked(user.Policy.IsHidden || false).checkboxradio("refresh");
$('#chkRemoteControlSharedDevices', page).checked(user.Policy.EnableSharedDeviceControl);
$('#chkEnableRemoteControlOtherUsers', page).checked(user.Policy.EnableRemoteControlOfOtherUsers).checkboxradio("refresh");
$('#chkEnableMediaPlayback', page).checked(user.Policy.EnableMediaPlayback || false).checkboxradio("refresh");
2013-07-08 09:13:21 -07:00
2014-12-19 23:06:27 -07:00
$('#chkManageLiveTv', page).checked(user.Policy.EnableLiveTvManagement || false).checkboxradio("refresh");
$('#chkEnableLiveTvAccess', page).checked(user.Policy.EnableLiveTvAccess || false).checkboxradio("refresh");
$('#chkEnableContentDeletion', page).checked(user.Policy.EnableContentDeletion || false).checkboxradio("refresh");
2014-12-19 23:06:27 -07:00
$('#chkDisableUserPreferences', page).checked((!user.Policy.EnableUserPreferenceAccess) || false).checkboxradio("refresh");
2014-10-23 21:54:35 -07:00
2014-12-18 21:20:07 -07:00
$('#chkEnableSync', page).checked(user.Policy.EnableSync).checkboxradio("refresh");
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) {
Dashboard.alert(Globalize.translate('SettingsSaved'));
} else {
2014-09-14 08:10:51 -07:00
2014-10-29 15:01:02 -07:00
ConnectHelper.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.EnableMediaPlayback = $('#chkEnableMediaPlayback', 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
2014-12-18 21:20:07 -07:00
user.Policy.EnableSync = $('#chkEnableSync', page).checked();
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
function editUserPage() {
2013-02-20 18:33:05 -07:00
var self = this;
2013-02-20 18:33:05 -07:00
self.onSubmit = function () {
2013-02-20 18:33:05 -07:00
var page = $(this).parents('.page');
Dashboard.showLoadingMsg();
2014-09-14 08:10:51 -07:00
getUser().done(function (result) {
saveUser(result, page);
});
// 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
});
}
window.EditUserPage = new editUserPage();
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
$(document).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
2014-10-19 20:04:45 -07:00
})(jQuery, window, document);
(function () {
window.ConnectHelper = {
updateUserInfo: function (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('MessageMediaBrowserAccontRemoved'),
title: Globalize.translate('HeaderMediaBrowserAccountRemoved'),
callback: actionCallback
});
});
}
else if (currentConnectUsername != enteredConnectUsername) {
// Add/Update connect info
ApiClient.ajax({
type: "POST",
url: linkUrl,
data: {
ConnectUsername: enteredConnectUsername
},
dataType: 'json'
2014-10-29 15:01:02 -07:00
}).done(function (result) {
2014-10-19 20:04:45 -07:00
var msgKey = result.IsPending ? 'MessagePendingMediaBrowserAccountAdded' : 'MessageMediaBrowserAccountAdded';
Dashboard.alert({
message: Globalize.translate(msgKey),
title: Globalize.translate('HeaderMediaBrowserAccountAdded'),
callback: actionCallback
});
});
} else {
if (noActionCallback) {
noActionCallback();
}
}
}
};
})();