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

175 lines
4.5 KiB
JavaScript
Raw Normal View History

2014-09-13 07:10:30 -07:00
(function (document, window, $) {
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
2014-09-14 08:10:51 -07:00
$('.userMenu', page).on("popupafterclose.deleteuser", function() {
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
$(this).off('popupafterclose.deleteuser');
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
var msg = Globalize.translate('DeleteUserConfirmation');
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
Dashboard.confirm(msg, Globalize.translate('DeleteUser'), function (result) {
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
if (result) {
Dashboard.showLoadingMsg();
ApiClient.deleteUser(id).done(function () {
loadUsers(page);
});
}
});
}).popup('close');
}
function closeUserMenu(page) {
$('.userMenu', page).popup('close').remove();
}
function showUserMenu(elem) {
var card = $(elem).parents('.card');
var page = $(elem).parents('.page');
var userId = card.attr('data-userid');
$('.userMenu', page).popup("close").remove();
var html = '<div data-role="popup" class="userMenu" data-history="false" data-theme="a">';
html += '<ul data-role="listview" style="min-width: 180px;">';
html += '<li data-role="list-divider">Menu</li>';
html += '<li><a href="#" class="btnDeleteUser" data-userid="' + userId + '">' + Globalize.translate('ButtonDelete') + '</a></li>';
html += '<li><a href="useredit.html?userid=' + userId + '">' + Globalize.translate('ButtonOpen') + '</a></li>';
html += '</ul>';
html += '</div>';
page.append(html);
var flyout = $('.userMenu', page).popup({ positionTo: elem || "window" }).trigger('create').popup("open").on("popupafterclose", function () {
$(this).off("popupafterclose").remove();
});
$('.btnDeleteUser', flyout).on('click', function () {
deleteUser(page, this);
2014-09-13 07:10:30 -07:00
});
}
2013-02-20 18:33:05 -07:00
2014-09-13 07:10:30 -07:00
function getUserHtml(user) {
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
2014-09-14 08:10:51 -07:00
var cssClass = "card homePageSquareCard alternateHover bottomPaddedCard";
if (user.Configuration.IsDisabled) {
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';
}
2014-09-13 07:10:30 -07:00
html += '<div class="cardImage" style="background-image:url(\'' + imgUrl + '\');">';
2014-09-14 11:47:48 -07:00
if (user.ConnectUserId) {
html += '<div class="playedIndicator"><div class="ui-icon-cloud ui-btn-icon-notext"></div></div>';
}
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
2014-09-13 07:10:30 -07:00
html += '<div class="cardText" style="text-align:right; float:right;">';
2013-02-20 18:33:05 -07:00
2014-09-14 08:10:51 -07:00
html += '<button class="btnUserMenu" type="button" data-inline="true" data-iconpos="notext" data-icon="ellipsis-v" style="margin: 2px 0 0;"></button>';
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
html += '<div class="cardText" style="margin-right: 30px; padding: 11px 0 10px;">';
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-09-14 08:10:51 -07:00
function getUserSectionHtml(users) {
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-09-14 08:10:51 -07:00
html += users.map(getUserHtml).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-09-14 08:10:51 -07:00
function renderUsers(page, users) {
2014-09-13 07:10:30 -07:00
2014-09-14 08:10:51 -07:00
var html = '';
2014-09-13 07:10:30 -07:00
2014-09-14 08:10:51 -07:00
html += getUserSectionHtml(users);
2014-09-13 07:10:30 -07:00
2014-09-14 08:10:51 -07:00
var elem = $('.users', page).html(html).trigger('create');
2014-09-13 07:10:30 -07:00
2014-09-14 08:10:51 -07:00
$('.btnUserMenu', elem).on('click', function () {
showUserMenu(this);
});
2014-09-13 07:10:30 -07:00
}
function loadUsers(page) {
Dashboard.showLoadingMsg();
ApiClient.getUsers().done(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-09-13 07:10:30 -07:00
$(document).on('pagebeforeshow', "#userProfilesPage", function () {
var page = this;
loadUsers(page);
});
})(document, window, jQuery);