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

366 lines
9.4 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 12:27:29 -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 () {
2014-10-13 13:14:53 -07:00
loadData(page);
2014-09-14 08:10:51 -07:00
});
}
});
}).popup('close');
}
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;">';
2014-09-15 20:33:30 -07:00
html += '<li data-role="list-divider">' + Globalize.translate('HeaderMenu') + '</li>';
2014-09-14 08:10:51 -07:00
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 () {
2014-09-23 18:44:05 -07:00
deleteUser(page, this.getAttribute('data-userid'));
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
2014-10-13 21:22:17 -07:00
var cssClass = "card squareCard alternateHover bottomPaddedCard";
2014-09-14 08:10:51 -07:00
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-10-13 21:59:34 -07:00
if (user.ConnectUserId && addConnectIndicator) {
2014-09-14 12:27:29 -07:00
html += '<div class="playedIndicator" title="' + Globalize.translate('TooltipLinkedToMediaBrowserConnect') + '"><div class="ui-icon-cloud ui-btn-icon-notext"></div></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
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-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
elem.html(html).trigger('create');
$('.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) {
var card = $(elem).parents('.card');
var page = $(elem).parents('.page');
var id = card.attr('data-id');
$('.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">' + Globalize.translate('HeaderMenu') + '</li>';
html += '<li><a href="#" class="btnDelete" data-id="' + id + '">' + Globalize.translate('ButtonCancel') + '</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();
});
$('.btnDelete', flyout).on('click', function () {
cancelAuthorization(page, this.getAttribute('data-id'));
$('.userMenu', page).popup("close").remove();
});
}
function getPendingUserHtml(user) {
2014-09-14 08:10:51 -07:00
var html = '';
2014-09-13 07:10:30 -07:00
2014-10-13 21:22:17 -07:00
var cssClass = "card squareCard alternateHover 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">';
html += '<div class="cardText" style="text-align:right; float:right;">';
html += '<button class="btnUserMenu" type="button" data-inline="true" data-iconpos="notext" data-icon="ellipsis-v" style="margin: 2px 0 0;"></button>';
html += "</div>";
html += '<div class="cardText" style="margin-right: 30px; padding: 11px 0 10px;">';
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('');
var elem = $('.pending', 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 () {
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
})
}).done(function () {
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();
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-10-13 13:14:53 -07:00
2014-10-13 21:22:17 -07:00
ApiClient.getJSON(ApiClient.getUrl('Connect/Pending')).done(function (pending) {
2014-10-13 13:14:53 -07:00
renderPendingGuests(page, pending);
});
}
function inviteUser(page) {
Dashboard.showLoadingMsg();
// Add/Update connect info
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl('Connect/Invite', {
ConnectUsername: $('#txtConnectUsername', page).val(),
SendingUserId: Dashboard.getCurrentUserId()
}),
dataType: 'json'
}).done(function (result) {
$('#popupInvite').popup('close');
loadData(page);
});
2013-02-20 18:33:05 -07:00
}
2014-10-13 21:22:17 -07:00
function showInvitePopup(page) {
$('#popupInvite', page).popup('open');
$('#txtConnectUsername', page).val('');
}
$(document).on('pageinit', "#userProfilesPage", function () {
var page = this;
$('.btnInvite', page).on('click', function () {
showInvitePopup(page);
});
}).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
});
2014-10-13 13:14:53 -07:00
window.UserProfilesPage = {
onSubmit: function () {
var form = this;
var page = $(form).parents('.page');
inviteUser(page);
return false;
}
};
2014-09-13 07:10:30 -07:00
})(document, window, jQuery);