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

261 lines
8.0 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-09-14 11:47:48 -07:00
function loadUser(page, user, loggedInUser) {
2014-09-14 08:10:51 -07:00
2014-09-14 11:47:48 -07:00
currentUser = user;
if (!loggedInUser.Configuration.IsAdministrator) {
2013-02-20 18:33:05 -07:00
$('#fldIsAdmin', page).hide();
$('#featureAccessFields', page).hide();
2013-07-08 12:31:45 -07:00
$('#accessControlDiv', page).hide();
2013-02-20 18:33:05 -07:00
} else {
2013-07-08 09:13:21 -07:00
$('#accessControlDiv', page).show();
2013-02-20 18:33:05 -07:00
$('#fldIsAdmin', page).show();
$('#featureAccessFields', page).show();
$('.lnkEditUserPreferencesContainer', page).show();
}
2014-10-13 13:23:31 -07:00
if (user.Id && loggedInUser.Configuration.IsAdministrator && user.ConnectLinkType != 'Guest') {
2014-10-12 10:31:41 -07:00
$('#fldConnectInfo', page).show();
2014-09-14 08:10:51 -07:00
} else {
$('#fldConnectInfo', page).hide();
}
2014-06-17 22:16:00 -07:00
if (!loggedInUser.Configuration.IsAdministrator || !user.Id) {
$('.lnkEditUserPreferencesContainer', page).hide();
} else {
$('.lnkEditUserPreferencesContainer', page).show();
$('.lnkEditUserPreferences', page).attr('href', 'mypreferencesdisplay.html?userId=' + user.Id);
2013-02-20 18:33:05 -07:00
}
2014-05-30 12:23:56 -07:00
Dashboard.setPageTitle(user.Name || Globalize.translate('AddUser'));
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
$('#chkIsAdmin', page).checked(user.Configuration.IsAdministrator || false).checkboxradio("refresh");
2013-05-23 08:07:25 -07:00
$('#chkBlockNotRated', page).checked(user.Configuration.BlockNotRated || false).checkboxradio("refresh");
2013-02-20 18:33:05 -07:00
2013-07-08 09:13:21 -07:00
$('#chkDisabled', page).checked(user.Configuration.IsDisabled || false).checkboxradio("refresh");
$('#chkIsHidden', page).checked(user.Configuration.IsHidden || false).checkboxradio("refresh");
$('#chkEnableRemoteControlOtherUsers', page).checked(user.Configuration.EnableRemoteControlOfOtherUsers || false).checkboxradio("refresh");
$('#chkEnableMediaPlayback', page).checked(user.Configuration.EnableMediaPlayback || false).checkboxradio("refresh");
2013-07-08 09:13:21 -07:00
$('#chkManageLiveTv', page).checked(user.Configuration.EnableLiveTvManagement || false).checkboxradio("refresh");
$('#chkEnableLiveTvAccess', page).checked(user.Configuration.EnableLiveTvAccess || false).checkboxradio("refresh");
2014-03-25 14:13:55 -07:00
$('#chkEnableContentDeletion', page).checked(user.Configuration.EnableContentDeletion || false).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
var userId = getParameterByName("userId");
2013-02-20 18:33:05 -07:00
if (userId) {
2014-09-14 08:10:51 -07:00
2014-09-14 11:47:48 -07:00
var currentConnectUsername = currentUser.ConnectUserName || '';
2014-09-14 08:10:51 -07:00
var enteredConnectUsername = $('#txtConnectUserName', page).val();
if (currentConnectUsername == enteredConnectUsername) {
Dashboard.alert(Globalize.translate('SettingsSaved'));
} else {
updateConnectInfo(page, user);
}
} else {
Dashboard.navigate("userprofiles.html");
2013-02-20 18:33:05 -07:00
}
}
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
function updateConnectInfo(page, user) {
2014-09-14 11:47:48 -07:00
var currentConnectUsername = currentUser.ConnectUserName || '';
2014-09-14 08:10:51 -07:00
var enteredConnectUsername = $('#txtConnectUserName', page).val();
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 () {
2014-09-14 10:12:47 -07:00
Dashboard.alert({
message: Globalize.translate('MessageMediaBrowserAccontRemoved'),
title: Globalize.translate('HeaderMediaBrowserAccountRemoved'),
callback: function () {
loadData(page);
}
});
2014-09-14 08:10:51 -07:00
});
}
else if (currentConnectUsername != enteredConnectUsername) {
// Add/Update connect info
ApiClient.ajax({
type: "POST",
url: linkUrl,
data: {
ConnectUsername: enteredConnectUsername
2014-09-14 16:39:06 -07:00
},
dataType: 'json'
2014-09-14 08:10:51 -07:00
2014-09-14 16:39:06 -07:00
}).done(function (result) {
var msgKey = result.IsPending ? 'MessagePendingMediaBrowserAccountAdded' : 'MessageMediaBrowserAccountAdded';
2014-09-14 08:10:51 -07:00
Dashboard.alert({
2014-09-14 16:39:06 -07:00
message: Globalize.translate(msgKey),
2014-09-14 08:10:51 -07:00
title: Globalize.translate('HeaderMediaBrowserAccountAdded'),
callback: function () {
loadData(page);
}
});
});
}
}
function saveUser(user, page) {
2013-02-20 18:33:05 -07:00
user.Name = $('#txtUserName', page).val();
user.Configuration.IsAdministrator = $('#chkIsAdmin', page).checked();
2013-05-23 08:07:25 -07:00
user.Configuration.BlockNotRated = $('#chkBlockNotRated', page).checked();
2013-02-20 18:33:05 -07:00
2013-07-08 09:13:21 -07:00
user.Configuration.IsHidden = $('#chkIsHidden', page).checked();
user.Configuration.IsDisabled = $('#chkDisabled', page).checked();
user.Configuration.EnableRemoteControlOfOtherUsers = $('#chkEnableRemoteControlOtherUsers', page).checked();
user.Configuration.EnableLiveTvManagement = $('#chkManageLiveTv', page).checked();
user.Configuration.EnableMediaPlayback = $('#chkEnableMediaPlayback', page).checked();
user.Configuration.EnableLiveTvAccess = $('#chkEnableLiveTvAccess', page).checked();
2014-03-25 14:13:55 -07:00
user.Configuration.EnableContentDeletion = $('#chkEnableContentDeletion', page).checked();
2013-07-08 09:13:21 -07:00
2013-02-20 18:33:05 -07:00
var userId = getParameterByName("userId");
if (userId) {
ApiClient.updateUser(user).done(function () {
2014-09-14 08:10:51 -07:00
onSaveComplete(page, user);
});
2013-02-20 18:33:05 -07:00
} else {
ApiClient.createUser(user).done(function () {
2014-09-14 08:10:51 -07:00
onSaveComplete(page, user);
});
2013-02-20 18:33:05 -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");
if (userId) {
return ApiClient.getUser(userId);
}
var deferred = $.Deferred();
deferred.resolveWith(null, [{
Configuration: {
IsAdministrator: false,
EnableLiveTvManagement: true,
EnableLiveTvAccess: true,
EnableRemoteControlOfOtherUsers: true,
EnableMediaPlayback: true
}
}]);
return deferred.promise();
}
function loadData(page) {
Dashboard.showLoadingMsg();
var promise1 = getUser();
var promise2 = Dashboard.getCurrentUser();
2014-09-14 11:47:48 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
2014-09-14 08:10:51 -07:00
2014-09-14 11:47:48 -07:00
loadUser(page, response1[0] || response1, response2[0]);
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;
2013-02-20 18:33:05 -07:00
var userId = getParameterByName("userId");
if (userId) {
$('#userProfileNavigation', page).show();
} else {
$('#userProfileNavigation', page).hide();
}
2013-04-18 12:09:07 -07:00
Dashboard.getCurrentUser().done(function (loggedInUser) {
if (loggedInUser.Configuration.IsAdministrator) {
$('#lnkParentalControl', page).show();
2013-04-18 12:09:07 -07:00
} else {
$('#lnkParentalControl', page).hide();
2013-04-18 12:09:07 -07:00
}
});
}).on('pageshow', "#editUserPage", function () {
var page = this;
2014-09-14 08:10:51 -07:00
loadData(page);
$("form input:first", page).focus();
});
2013-02-20 18:33:05 -07:00
})(jQuery, window, document);