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

382 lines
9.8 KiB
JavaScript
Raw Normal View History

2016-07-30 13:47:18 -07:00
define(['jQuery', 'paper-icon-button-light', 'cardStyle'], function ($) {
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
function deleteUser(page, id) {
2013-02-20 18:33:05 -07:00
2015-07-15 04:26:47 -07:00
var msg = Globalize.translate('DeleteUserConfirmation');
2013-02-20 18:33:05 -07:00
2016-02-22 11:35:44 -07:00
require(['confirm'], function (confirm) {
confirm(msg, Globalize.translate('DeleteUser')).then(function () {
2013-02-20 18:33:05 -07:00
2015-07-15 04:26:47 -07:00
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.deleteUser(id).then(function () {
2013-02-20 18:33:05 -07:00
2015-07-15 04:26:47 -07:00
loadData(page);
});
2016-02-22 11:35:44 -07:00
});
2015-07-15 04:26:47 -07:00
});
2014-09-14 08:10:51 -07:00
}
function showUserMenu(elem) {
2015-07-15 04:26:47 -07:00
var card = $(elem).parents('.card')[0];
var page = $(card).parents('.page')[0];
var userId = card.getAttribute('data-userid');
2014-09-14 08:10:51 -07:00
2015-07-15 04:26:47 -07:00
var menuItems = [];
2015-07-15 04:26:47 -07:00
menuItems.push({
name: Globalize.translate('ButtonOpen'),
id: 'open',
ironIcon: 'mode-edit'
});
2014-09-14 08:10:51 -07:00
2015-07-15 04:26:47 -07:00
menuItems.push({
name: Globalize.translate('ButtonLibraryAccess'),
id: 'access',
ironIcon: 'lock'
});
2014-09-14 08:10:51 -07:00
2015-07-15 04:26:47 -07:00
menuItems.push({
name: Globalize.translate('ButtonParentalControl'),
id: 'parentalcontrol',
ironIcon: 'person'
});
2014-09-14 08:10:51 -07:00
2015-07-15 04:26:47 -07:00
menuItems.push({
name: Globalize.translate('ButtonDelete'),
id: 'delete',
ironIcon: 'delete'
2014-09-14 08:10:51 -07:00
});
2016-01-30 21:04:00 -07:00
require(['actionsheet'], function (actionsheet) {
2015-07-15 04:26:47 -07:00
2016-01-30 21:04:00 -07:00
actionsheet.show({
2015-07-15 04:26:47 -07:00
items: menuItems,
positionTo: card,
callback: function (id) {
switch (id) {
case 'open':
Dashboard.navigate('useredit.html?userid=' + userId);
break;
case 'access':
Dashboard.navigate('userlibraryaccess.html?userid=' + userId);
break;
case 'parentalcontrol':
Dashboard.navigate('userparentalcontrol.html?userid=' + userId);
break;
case 'delete':
deleteUser(page, userId);
break;
default:
break;
}
}
});
2014-09-13 07:10:30 -07:00
});
}
2013-02-20 18:33:05 -07:00
2014-10-13 21:59:34 -07:00
function getUserHtml(user, addConnectIndicator) {
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
var html = '';
2013-02-20 18:33:05 -07:00
2016-07-30 13:47:18 -07:00
var cssClass = "card squareCard scalableCard";
2014-09-14 08:10:51 -07:00
2014-12-19 23:06:27 -07:00
if (user.Policy.IsDisabled) {
2014-09-14 08:10:51 -07:00
cssClass += ' grayscale';
}
html += "<div data-userid='" + user.Id + "' class='" + cssClass + "'>";
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable">';
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
html += '<div class="cardPadder"></div>';
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
var href = "useredit.html?userId=" + user.Id + "";
html += '<a class="cardContent" href="' + href + '">';
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
var imgUrl;
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
if (user.PrimaryImageTag) {
2014-09-13 07:10:30 -07:00
imgUrl = ApiClient.getUserImageUrl(user.Id, {
2014-09-14 08:10:51 -07:00
width: 300,
2014-09-13 07:10:30 -07:00
tag: user.PrimaryImageTag,
type: "Primary"
});
2014-09-13 07:10:30 -07:00
} else {
imgUrl = 'css/images/userflyoutdefault.png';
}
var imageClass = 'cardImage';
if (user.Policy.IsDisabled) {
imageClass += ' disabledUser';
}
html += '<div class="' + imageClass + '" style="background-image:url(\'' + imgUrl + '\');">';
2014-10-13 21:59:34 -07:00
if (user.ConnectUserId && addConnectIndicator) {
2016-08-06 23:25:51 -07:00
html += '<div class="indicators">';
html += '<div class="playedIndicator" title="' + Globalize.translate('TooltipLinkedToEmbyConnect') + '"><i class="md-icon playedIndicatorIcon indicatorIcon">cloud</i></div>';
html += "</div>";
2014-09-14 11:47:48 -07:00
}
2014-09-13 07:10:30 -07:00
html += "</div>";
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
// cardContent
html += "</a>";
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
// cardScalable
html += "</div>";
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
html += '<div class="cardFooter">';
2013-02-20 18:33:05 -07:00
2016-07-30 13:47:18 -07:00
html += '<div style="text-align:right; float:right;padding:0;">';
2016-06-19 09:53:53 -07:00
html += '<button type="button" is="paper-icon-button-light" class="btnUserMenu autoSize"><i class="md-icon">' + AppInfo.moreIcon.replace('-', '_') + '</i></button>';
2014-09-13 07:10:30 -07:00
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-06-17 23:23:44 -07:00
html += '<div class="cardText" style="padding-top:10px;padding-bottom:10px;">';
2014-09-13 07:10:30 -07:00
html += user.Name;
html += "</div>";
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
// cardFooter
html += "</div>";
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
// cardBox
html += "</div>";
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
// card
html += "</div>";
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
return html;
}
2013-02-20 18:33:05 -07:00
2014-10-13 21:59:34 -07:00
function getUserSectionHtml(users, addConnectIndicator) {
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
var html = '';
2014-09-13 07:10:30 -07:00
2014-10-13 21:59:34 -07:00
html += users.map(function (u) {
return getUserHtml(u, addConnectIndicator);
}).join('');
2014-09-13 07:10:30 -07:00
2014-09-14 08:10:51 -07:00
return html;
}
2014-09-13 07:10:30 -07:00
2014-10-13 21:59:34 -07:00
function renderUsersIntoElement(elem, users, addConnectIndicator) {
2014-10-13 13:14:53 -07:00
2014-10-13 21:59:34 -07:00
var html = getUserSectionHtml(users, addConnectIndicator);
2014-10-13 13:14:53 -07:00
2016-03-06 11:09:20 -07:00
elem.html(html);
2014-10-13 13:14:53 -07:00
$('.btnUserMenu', elem).on('click', function () {
showUserMenu(this);
});
}
2014-09-14 08:10:51 -07:00
function renderUsers(page, users) {
2014-09-13 07:10:30 -07:00
2014-10-13 21:22:17 -07:00
renderUsersIntoElement($('.localUsers', page), users.filter(function (u) {
return u.ConnectLinkType != 'Guest';
2014-10-13 21:59:34 -07:00
}), true);
2014-10-13 21:22:17 -07:00
renderUsersIntoElement($('.connectUsers', page), users.filter(function (u) {
return u.ConnectLinkType == 'Guest';
}));
2014-10-13 13:14:53 -07:00
}
function showPendingUserMenu(elem) {
2016-02-08 21:46:25 -07:00
var menuItems = [];
2014-10-13 13:14:53 -07:00
2016-02-08 21:46:25 -07:00
menuItems.push({
name: Globalize.translate('ButtonCancel'),
id: 'delete',
ironIcon: 'delete'
});
2014-10-13 13:14:53 -07:00
2016-02-08 21:46:25 -07:00
require(['actionsheet'], function (actionsheet) {
2014-10-13 13:14:53 -07:00
2016-02-08 21:46:25 -07:00
var card = $(elem).parents('.card');
var page = $(elem).parents('.page');
var id = card.attr('data-id');
2014-10-13 13:14:53 -07:00
2016-02-08 21:46:25 -07:00
actionsheet.show({
items: menuItems,
positionTo: card,
callback: function (menuItemId) {
2014-10-13 13:14:53 -07:00
2016-02-08 21:46:25 -07:00
switch (menuItemId) {
2014-10-13 13:14:53 -07:00
2016-02-08 21:46:25 -07:00
case 'delete':
cancelAuthorization(page, id);
break;
default:
break;
}
}
2015-08-31 21:15:10 -07:00
});
2014-10-13 13:14:53 -07:00
});
}
function getPendingUserHtml(user) {
2014-09-14 08:10:51 -07:00
var html = '';
2014-09-13 07:10:30 -07:00
2015-10-15 10:21:18 -07:00
var cssClass = "card squareCard bottomPaddedCard";
2014-10-13 13:14:53 -07:00
html += "<div data-id='" + user.Id + "' class='" + cssClass + "'>";
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable">';
html += '<div class="cardPadder"></div>';
var href = "#";
html += '<a class="cardContent" href="' + href + '">';
var imgUrl = user.ImageUrl || 'css/images/userflyoutdefault.png';
html += '<div class="cardImage" style="background-image:url(\'' + imgUrl + '\');">';
html += "</div>";
2014-09-13 07:10:30 -07:00
2014-10-13 13:14:53 -07:00
// cardContent
html += "</a>";
// cardScalable
html += "</div>";
html += '<div class="cardFooter">';
2015-09-06 12:09:36 -07:00
html += '<div class="cardText" style="text-align:right; float:right;padding:0;">';
2016-05-07 23:31:08 -07:00
html += '<button type="button" is="paper-icon-button-light" class="btnUserMenu"><iron-icon icon="' + AppInfo.moreIcon + '"></iron-icon></button>';
2014-10-13 13:14:53 -07:00
html += "</div>";
2015-10-22 08:03:08 -07:00
html += '<div class="cardText" style="padding-top:10px;padding-bottom:10px;">';
2014-10-13 13:14:53 -07:00
html += user.UserName;
html += "</div>";
// cardFooter
html += "</div>";
// cardBox
html += "</div>";
// card
html += "</div>";
return html;
}
function renderPendingGuests(page, users) {
if (users.length) {
$('.sectionPendingGuests', page).show();
} else {
$('.sectionPendingGuests', page).hide();
}
var html = users.map(getPendingUserHtml).join('');
2016-03-06 11:09:20 -07:00
var elem = $('.pending', page).html(html);
2014-09-13 07:10:30 -07:00
2014-09-14 08:10:51 -07:00
$('.btnUserMenu', elem).on('click', function () {
2014-10-13 13:14:53 -07:00
showPendingUserMenu(this);
});
}
function cancelAuthorization(page, id) {
2014-10-13 21:22:17 -07:00
2014-10-13 13:14:53 -07:00
Dashboard.showLoadingMsg();
// Add/Update connect info
ApiClient.ajax({
type: "DELETE",
url: ApiClient.getUrl('Connect/Pending', {
Id: id
})
2015-12-14 08:43:03 -07:00
}).then(function () {
2014-10-13 13:14:53 -07:00
loadData(page);
2014-09-14 08:10:51 -07:00
});
2014-09-13 07:10:30 -07:00
}
2014-10-13 13:14:53 -07:00
function loadData(page) {
2014-09-13 07:10:30 -07:00
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.getUsers().then(function (users) {
2014-09-14 08:10:51 -07:00
renderUsers(page, users);
2014-09-13 07:10:30 -07:00
Dashboard.hideLoadingMsg();
2013-02-20 18:33:05 -07:00
});
2014-10-13 13:14:53 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getJSON(ApiClient.getUrl('Connect/Pending')).then(function (pending) {
2014-10-13 13:14:53 -07:00
renderPendingGuests(page, pending);
});
2014-10-22 21:26:01 -07:00
}
2016-07-22 22:16:26 -07:00
function showLinkUser(page, userId) {
require(['components/guestinviter/connectlink'], function (connectlink) {
connectlink.show().then(function () {
loadData(page);
});
});
}
2014-10-13 21:22:17 -07:00
function showInvitePopup(page) {
2015-12-14 08:43:03 -07:00
Dashboard.getCurrentUser().then(function (user) {
2014-10-13 21:22:17 -07:00
2016-02-08 21:46:25 -07:00
if (!user.ConnectUserId) {
2014-11-18 19:45:12 -07:00
2016-07-22 22:16:26 -07:00
showLinkUser(page, user.Id);
2016-02-08 21:46:25 -07:00
return;
2014-11-18 19:45:12 -07:00
}
2016-02-08 21:46:25 -07:00
require(['components/guestinviter/guestinviter'], function (guestinviter) {
2015-06-08 22:56:46 -07:00
2016-02-08 21:46:25 -07:00
guestinviter.show().then(function () {
loadData(page);
});
});
});
2015-06-08 22:56:46 -07:00
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#userProfilesPage", function () {
2014-10-13 21:22:17 -07:00
var page = this;
$('.btnInvite', page).on('click', function () {
showInvitePopup(page);
});
2015-09-06 12:09:36 -07:00
$('.btnAddUser', page).on('click', function () {
Dashboard.navigate('usernew.html');
});
2015-08-31 23:22:46 -07:00
}).on('pagebeforeshow', "#userProfilesPage", function () {
2014-09-13 07:10:30 -07:00
var page = this;
2014-10-13 13:14:53 -07:00
loadData(page);
2014-09-13 07:10:30 -07:00
});
});