1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/controllers/dashboard/users/userprofilespage.js

270 lines
9.7 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['loading', 'dom', 'globalize', 'date-fns', 'dfnshelper', 'paper-icon-button-light', 'cardStyle', 'emby-button', 'indicators', 'flexStyles'], function (loading, dom, globalize, datefns, dfnshelper) {
'use strict';
2018-10-23 01:05:09 +03:00
function deleteUser(page, id) {
2020-05-04 12:44:12 +02:00
var msg = globalize.translate('DeleteUserConfirmation');
2019-01-04 12:32:24 +01:00
2020-05-04 12:44:12 +02:00
require(['confirm'], function (confirm) {
2020-06-18 22:41:43 +03:00
confirm.default({
2020-05-04 12:44:12 +02:00
title: globalize.translate('DeleteUser'),
2018-10-23 01:05:09 +03:00
text: msg,
2020-05-04 12:44:12 +02:00
confirmText: globalize.translate('ButtonDelete'),
primary: 'delete'
2019-01-04 12:32:24 +01:00
}).then(function () {
loading.show();
ApiClient.deleteUser(id).then(function () {
loadData(page);
});
});
});
2018-10-23 01:05:09 +03:00
}
function showUserMenu(elem) {
2020-05-04 12:44:12 +02:00
var card = dom.parentWithClass(elem, 'card');
var page = dom.parentWithClass(card, 'page');
var userId = card.getAttribute('data-userid');
2019-01-04 12:32:24 +01:00
var menuItems = [];
2018-10-23 01:05:09 +03:00
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ButtonOpen'),
id: 'open',
icon: 'mode_edit'
2019-01-04 12:32:24 +01:00
});
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ButtonLibraryAccess'),
id: 'access',
icon: 'lock'
2019-01-04 12:32:24 +01:00
});
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ButtonParentalControl'),
id: 'parentalcontrol',
icon: 'person'
2019-01-04 12:32:24 +01:00
});
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ButtonDelete'),
id: 'delete',
icon: 'delete'
2019-01-04 12:32:24 +01:00
});
2020-05-04 12:44:12 +02:00
require(['actionsheet'], function (actionsheet) {
2018-10-23 01:05:09 +03:00
actionsheet.show({
items: menuItems,
positionTo: card,
2019-01-04 12:32:24 +01:00
callback: function (id) {
2018-10-23 01:05:09 +03:00
switch (id) {
2020-05-04 12:44:12 +02:00
case 'open':
Dashboard.navigate('useredit.html?userId=' + userId);
2018-10-23 01:05:09 +03:00
break;
2019-01-04 12:32:24 +01:00
2020-05-04 12:44:12 +02:00
case 'access':
Dashboard.navigate('userlibraryaccess.html?userId=' + userId);
2018-10-23 01:05:09 +03:00
break;
2019-01-04 12:32:24 +01:00
2020-05-04 12:44:12 +02:00
case 'parentalcontrol':
Dashboard.navigate('userparentalcontrol.html?userId=' + userId);
2018-10-23 01:05:09 +03:00
break;
2019-01-04 12:32:24 +01:00
2020-05-04 12:44:12 +02:00
case 'delete':
2019-01-04 12:32:24 +01:00
deleteUser(page, userId);
2018-10-23 01:05:09 +03:00
}
}
2019-01-04 12:32:24 +01:00
});
});
2018-10-23 01:05:09 +03:00
}
function getUserHtml(user, addConnectIndicator) {
2020-05-04 12:44:12 +02:00
var html = '';
var cssClass = 'card squareCard scalableCard squareCard-scalable';
2019-01-04 12:32:24 +01:00
if (user.Policy.IsDisabled) {
2020-05-04 12:44:12 +02:00
cssClass += ' grayscale';
2019-01-04 12:32:24 +01:00
}
html += "<div data-userid='" + user.Id + "' class='" + cssClass + "'>";
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable visualCardBox-cardScalable">';
html += '<div class="cardPadder cardPadder-square"></div>';
html += '<a is="emby-linkbutton" class="cardContent" href="useredit.html?userId=' + user.Id + '">';
2018-10-23 01:05:09 +03:00
var imgUrl;
2019-01-04 12:32:24 +01:00
if (user.PrimaryImageTag) {
imgUrl = ApiClient.getUserImageUrl(user.Id, {
width: 300,
tag: user.PrimaryImageTag,
2020-05-04 12:44:12 +02:00
type: 'Primary'
2019-01-04 12:32:24 +01:00
});
}
2020-05-04 12:44:12 +02:00
var imageClass = 'cardImage';
2019-01-04 12:32:24 +01:00
if (user.Policy.IsDisabled) {
2020-05-04 12:44:12 +02:00
imageClass += ' disabledUser';
2019-01-04 12:32:24 +01:00
}
if (imgUrl) {
html += '<div class="' + imageClass + '" style="background-image:url(\'' + imgUrl + "');\">";
} else {
html += '<div class="' + imageClass + ' flex align-items-center justify-content-center">';
2020-04-26 02:37:28 +03:00
html += '<span class="material-icons cardImageIcon person"></span>';
2019-01-04 12:32:24 +01:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '</a>';
html += '</div>';
2019-01-04 12:32:24 +01:00
html += '<div class="cardFooter visualCardBox-cardFooter">';
html += '<div class="cardText flex align-items-center">';
html += '<div class="flex-grow" style="overflow:hidden;text-overflow:ellipsis;">';
html += user.Name;
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '<button type="button" is="paper-icon-button-light" class="btnUserMenu flex-shrink-zero"><span class="material-icons more_vert"></span></button>';
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-01-04 12:32:24 +01:00
html += '<div class="cardText cardText-secondary">';
2018-10-23 01:05:09 +03:00
var lastSeen = getLastSeenText(user.LastActivityDate);
2020-05-04 12:44:12 +02:00
html += '' != lastSeen ? lastSeen : '&nbsp;';
html += '</div>';
html += '</div>';
html += '</div>';
return html + '</div>';
2018-10-23 01:05:09 +03:00
}
2020-04-02 20:11:10 +02:00
// FIXME: It seems that, sometimes, server sends date in the future, so date-fns displays messages like 'in less than a minute'. We should fix
// how dates are returned by the server when the session is active and show something like 'Active now', instead of past/future sentences
2018-10-23 01:05:09 +03:00
function getLastSeenText(lastActivityDate) {
2019-01-04 12:32:24 +01:00
if (lastActivityDate) {
2020-05-04 12:44:12 +02:00
return globalize.translate('LastSeen', datefns.formatDistanceToNow(Date.parse(lastActivityDate), dfnshelper.localeWithSuffix));
2019-01-04 12:32:24 +01:00
}
2020-05-04 12:44:12 +02:00
return '';
2018-10-23 01:05:09 +03:00
}
function getUserSectionHtml(users, addConnectIndicator) {
2019-01-04 12:32:24 +01:00
return users.map(function (u__q) {
return getUserHtml(u__q, addConnectIndicator);
2020-05-04 12:44:12 +02:00
}).join('');
2018-10-23 01:05:09 +03:00
}
function renderUsers(page, users) {
2020-05-04 12:44:12 +02:00
page.querySelector('.localUsers').innerHTML = getUserSectionHtml(users, true);
2018-10-23 01:05:09 +03:00
}
function showPendingUserMenu(elem) {
var menuItems = [];
menuItems.push({
2020-05-04 12:44:12 +02:00
name: globalize.translate('ButtonCancel'),
id: 'delete',
icon: 'delete'
2019-01-04 12:32:24 +01:00
});
2020-05-04 12:44:12 +02:00
require(['actionsheet'], function (actionsheet) {
var card = dom.parentWithClass(elem, 'card');
var page = dom.parentWithClass(card, 'page');
var id = card.getAttribute('data-id');
2018-10-23 01:05:09 +03:00
actionsheet.show({
items: menuItems,
positionTo: card,
2019-01-04 12:32:24 +01:00
callback: function (menuItemId) {
2018-10-23 01:05:09 +03:00
switch (menuItemId) {
2020-05-04 12:44:12 +02:00
case 'delete':
2019-01-04 12:32:24 +01:00
cancelAuthorization(page, id);
2018-10-23 01:05:09 +03:00
}
}
2019-01-04 12:32:24 +01:00
});
});
2018-10-23 01:05:09 +03:00
}
function getPendingUserHtml(user) {
2020-05-04 12:44:12 +02:00
var html = '';
2019-01-04 12:32:24 +01:00
html += "<div data-id='" + user.Id + "' class='card squareCard scalableCard squareCard-scalable'>";
html += '<div class="cardBox cardBox-bottompadded visualCardBox">';
html += '<div class="cardScalable visualCardBox-cardScalable">';
html += '<div class="cardPadder cardPadder-square"></div>';
html += '<a class="cardContent cardImageContainer" is="emby-linkbutton" href="#">';
if (user.ImageUrl) {
html += '<div class="cardImage" style="background-image:url(\'' + user.ImageUrl + "');\">";
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-01-04 12:32:24 +01:00
} else {
2020-04-26 02:37:28 +03:00
html += '<span class="cardImageIcon material-icons person"></span>';
2019-01-04 12:32:24 +01:00
}
2020-05-04 12:44:12 +02:00
html += '</a>';
html += '</div>';
2019-01-04 12:32:24 +01:00
html += '<div class="cardFooter visualCardBox-cardFooter">';
html += '<div class="cardText" style="text-align:right; float:right;padding:0;">';
2020-05-16 18:07:32 +02:00
html += '<button type="button" is="paper-icon-button-light" class="btnUserMenu"><span class="material-icons more_vert"></span></button>';
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-01-04 12:32:24 +01:00
html += '<div class="cardText" style="padding-top:10px;padding-bottom:10px;">';
html += user.UserName;
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '</div>';
html += '</div>';
return html + '</div>';
2018-10-23 01:05:09 +03:00
}
function renderPendingGuests(page, users) {
2019-01-04 12:32:24 +01:00
if (users.length) {
2020-05-04 12:44:12 +02:00
page.querySelector('.sectionPendingGuests').classList.remove('hide');
2019-01-04 12:32:24 +01:00
} else {
2020-05-04 12:44:12 +02:00
page.querySelector('.sectionPendingGuests').classList.add('hide');
2019-01-04 12:32:24 +01:00
}
2018-10-23 01:05:09 +03:00
2020-05-04 12:44:12 +02:00
page.querySelector('.pending').innerHTML = users.map(getPendingUserHtml).join('');
2019-01-04 12:32:24 +01:00
}
2019-01-04 12:32:24 +01:00
// TODO cvium: maybe reuse for invitation system
2018-10-23 01:05:09 +03:00
function cancelAuthorization(page, id) {
2019-01-04 12:32:24 +01:00
loading.show();
ApiClient.ajax({
2020-05-04 12:44:12 +02:00
type: 'DELETE',
url: ApiClient.getUrl('Connect/Pending', {
2018-10-23 01:05:09 +03:00
Id: id
})
2019-01-04 12:32:24 +01:00
}).then(function () {
loadData(page);
});
2018-10-23 01:05:09 +03:00
}
function loadData(page) {
2019-01-04 12:32:24 +01:00
loading.show();
ApiClient.getUsers().then(function (users) {
renderUsers(page, users);
loading.hide();
});
// TODO cvium
renderPendingGuests(page, []);
// ApiClient.getJSON(ApiClient.getUrl("Connect/Pending")).then(function (pending) {
//
2019-01-04 12:32:24 +01:00
// });
2018-10-23 01:05:09 +03:00
}
function showInvitePopup(page) {
2020-05-04 12:44:12 +02:00
require(['components/guestinviter/guestinviter'], function (guestinviter) {
2019-01-04 12:32:24 +01:00
guestinviter.show().then(function () {
loadData(page);
});
});
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
pageIdOn('pageinit', 'userProfilesPage', function () {
2018-10-23 01:05:09 +03:00
var page = this;
2020-05-04 12:44:12 +02:00
page.querySelector('.btnAddUser').addEventListener('click', function() {
Dashboard.navigate('usernew.html');
});
2020-05-04 12:44:12 +02:00
page.querySelector('.localUsers').addEventListener('click', function (e__e) {
var btnUserMenu = dom.parentWithClass(e__e.target, 'btnUserMenu');
2019-01-04 12:32:24 +01:00
if (btnUserMenu) {
showUserMenu(btnUserMenu);
}
});
2020-05-04 12:44:12 +02:00
page.querySelector('.pending').addEventListener('click', function (e__r) {
var btnUserMenu = dom.parentWithClass(e__r.target, 'btnUserMenu');
2019-01-04 12:32:24 +01:00
if (btnUserMenu) {
showPendingUserMenu(btnUserMenu);
}
});
});
2020-05-04 12:44:12 +02:00
pageIdOn('pagebeforeshow', 'userProfilesPage', function () {
2019-01-04 12:32:24 +01:00
loadData(this);
});
});