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

486 lines
13 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-10-30 21:57:24 -07:00
function renderLibrarySharingList(page, result) {
var folderHtml = '';
folderHtml += '<div data-role="controlgroup">';
folderHtml += result.Items.map(function (i) {
var currentHtml = '';
var id = 'chkShareFolder' + i.Id;
currentHtml += '<label for="' + id + '">' + i.Name + '</label>';
var isChecked = true;
var checkedHtml = isChecked ? ' checked="checked"' : '';
currentHtml += '<input data-mini="true" class="chkShareFolder" data-folderid="' + i.Id + '" type="checkbox" id="' + id + '"' + checkedHtml + ' />';
return currentHtml;
}).join('');
folderHtml += '</div>';
$('.librarySharingList', page).html(folderHtml).trigger('create');
}
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
2015-07-15 04:26:47 -07:00
Dashboard.confirm(msg, Globalize.translate('DeleteUser'), function (result) {
2013-02-20 18:33:05 -07:00
2015-07-15 04:26:47 -07:00
if (result) {
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2015-11-28 01:07:44 -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);
});
}
});
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
});
2015-07-15 04:26:47 -07:00
require(['actionsheet'], function () {
ActionSheetElement.show({
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
2015-10-15 10:21:18 -07:00
var cssClass = "card squareCard bottomPaddedCard";
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) {
2015-06-29 21:33:53 -07:00
html += '<div class="playedIndicator" title="' + Globalize.translate('TooltipLinkedToEmbyConnect') + '"><iron-icon icon="cloud"></iron-icon></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
2015-06-23 21:38:46 -07:00
html += '<div class="cardText" style="text-align:right; float:right;padding:0;">';
2015-07-14 09:39:34 -07:00
html += '<paper-icon-button icon="' + AppInfo.moreIcon + '" class="btnUserMenu"></paper-icon-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
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) {
2015-09-06 12:09:36 -07:00
require(['jqmpopup'], function () {
2015-08-31 21:15:10 -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
2015-08-31 21:15:10 -07:00
$('.userMenu', page).popup("close").remove();
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
var html = '<div data-role="popup" class="userMenu tapHoldMenu" data-theme="a">';
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
html += '<ul data-role="listview" style="min-width: 180px;">';
html += '<li data-role="list-divider">' + Globalize.translate('HeaderMenu') + '</li>';
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
html += '<li><a href="#" class="btnDelete" data-id="' + id + '">' + Globalize.translate('ButtonCancel') + '</a></li>';
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
html += '</ul>';
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
html += '</div>';
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
page.append(html);
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
var flyout = $('.userMenu', page).popup({ positionTo: elem || "window" }).trigger('create').popup("open").on("popupafterclose", function () {
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
$(this).off("popupafterclose").remove();
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
});
2014-10-13 13:14:53 -07:00
2015-08-31 21:15:10 -07:00
$('.btnDelete', flyout).on('click', function () {
cancelAuthorization(page, this.getAttribute('data-id'));
$('.userMenu', page).popup("close").remove();
});
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;">';
html += '<paper-icon-button icon="' + AppInfo.moreIcon + '" class="btnUserMenu"></paper-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('');
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
})
2015-11-28 01:07:44 -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-11-28 01:07:44 -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-11-28 01:07:44 -07:00
ApiClient.getJSON(ApiClient.getUrl('Connect/Pending')).then(function (pending) {
2014-10-13 13:14:53 -07:00
renderPendingGuests(page, pending);
});
2014-10-30 21:57:24 -07:00
2015-11-28 01:07:44 -07:00
ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", { IsHidden: false })).then(function (result) {
2014-10-30 21:57:24 -07:00
renderLibrarySharingList(page, result);
});
2014-10-13 13:14:53 -07:00
}
function inviteUser(page) {
Dashboard.showLoadingMsg();
2015-11-28 01:07:44 -07:00
ApiClient.getJSON(ApiClient.getUrl("Channels", {})).then(function (channelsResult) {
2014-10-13 13:14:53 -07:00
2015-01-19 22:19:13 -07:00
var shareExcludes = $(".chkShareFolder:checked", page).get().map(function (i) {
2014-10-13 13:14:53 -07:00
2014-10-30 21:57:24 -07:00
return i.getAttribute('data-folderid');
});
2014-10-13 13:14:53 -07:00
2014-10-30 21:57:24 -07:00
// Add/Update connect info
ApiClient.ajax({
2014-10-13 13:14:53 -07:00
2014-10-30 21:57:24 -07:00
type: "POST",
url: ApiClient.getUrl('Connect/Invite'),
dataType: 'json',
data: {
2014-10-13 13:14:53 -07:00
2014-10-30 21:57:24 -07:00
ConnectUsername: $('#txtConnectUsername', page).val(),
2015-01-19 22:19:13 -07:00
EnabledLibraries: shareExcludes.join(','),
2014-10-30 21:57:24 -07:00
SendingUserId: Dashboard.getCurrentUserId(),
EnableLiveTv: false
}
2014-10-22 21:26:01 -07:00
2015-11-28 01:07:44 -07:00
}).then(function (result) {
2014-10-22 21:26:01 -07:00
2014-10-30 21:57:24 -07:00
$('#popupInvite').popup('close');
2014-10-13 13:14:53 -07:00
2014-10-30 21:57:24 -07:00
Dashboard.hideLoadingMsg();
2014-10-13 13:14:53 -07:00
2014-10-30 21:57:24 -07:00
showNewUserInviteMessage(page, result);
});
});
2013-02-20 18:33:05 -07:00
}
2014-10-22 21:26:01 -07:00
function showNewUserInviteMessage(page, result) {
if (!result.IsNewUserInvitation && !result.IsPending) {
// It was immediately approved
loadData(page);
return;
}
var message = result.IsNewUserInvitation ?
Globalize.translate('MessageInvitationSentToNewUser', result.GuestDisplayName) :
Globalize.translate('MessageInvitationSentToUser', result.GuestDisplayName);
// Need a timeout because jquery mobile will not show a popup while a previous one is in the act of closing
setTimeout(function () {
Dashboard.alert({
message: message,
title: Globalize.translate('HeaderInvitationSent'),
callback: function () {
loadData(page);
}
});
}, 300);
}
2014-10-13 21:22:17 -07:00
function showInvitePopup(page) {
2015-11-27 18:18:15 -07:00
Dashboard.getCurrentUser().then(function (user) {
2014-10-13 21:22:17 -07:00
2014-11-18 19:45:12 -07:00
if (user.ConnectUserId) {
2014-10-13 21:22:17 -07:00
2014-11-18 19:45:12 -07:00
$('#popupInvite', page).popup('open');
$('#txtConnectUsername', page).val('');
} else {
var msg = Globalize.translate('MessageConnectAccountRequiredToInviteGuest');
msg += '<br/>';
msg += '<br/>';
2015-03-21 11:12:12 -07:00
msg += '<a href="useredit.html?userId=' + user.Id + '">' + Globalize.translate('ButtonLinkMyEmbyAccount') + '</a>';
2014-11-18 19:45:12 -07:00
msg += '<br/>';
Dashboard.alert({
message: msg,
title: Globalize.translate('HeaderInviteGuest')
});
}
});
2014-10-13 21:22:17 -07:00
}
2015-06-08 22:56:46 -07:00
function onSubmit() {
var form = this;
var page = $(form).parents('.page');
inviteUser(page);
return false;
}
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-06-08 22:56:46 -07:00
$('.addUserForm').off('submit', onSubmit).on('submit', onSubmit);
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
});
})(document, window, jQuery);