jellyfin-web/src/controllers/userprofilespage.js

269 lines
9.3 KiB
JavaScript
Raw Normal View History

define(["loading", "dom", "globalize", "humanedate", "paper-icon-button-light", "cardStyle", "emby-button", "indicators", "flexStyles"], function (loading, dom, globalize) {
2018-10-22 15:05:09 -07:00
"use strict";
function deleteUser(page, id) {
var msg = globalize.translate("DeleteUserConfirmation");
2019-01-04 04:32:24 -07:00
require(["confirm"], function (confirm) {
2018-10-22 15:05:09 -07:00
confirm({
title: globalize.translate("DeleteUser"),
text: msg,
confirmText: globalize.translate("ButtonDelete"),
primary: "delete"
2019-01-04 04:32:24 -07:00
}).then(function () {
loading.show();
ApiClient.deleteUser(id).then(function () {
loadData(page);
});
});
});
2018-10-22 15:05:09 -07:00
}
function showUserMenu(elem) {
2019-01-04 04:32:24 -07:00
var card = dom.parentWithClass(elem, "card");
var page = dom.parentWithClass(card, "page");
var userId = card.getAttribute("data-userid");
var menuItems = [];
2018-10-22 15:05:09 -07:00
menuItems.push({
name: globalize.translate("ButtonOpen"),
id: "open",
2019-11-05 08:24:39 -07:00
icon: "mode_edit"
2019-01-04 04:32:24 -07:00
});
menuItems.push({
2018-10-22 15:05:09 -07:00
name: globalize.translate("ButtonLibraryAccess"),
id: "access",
2019-11-05 08:24:39 -07:00
icon: "lock"
2019-01-04 04:32:24 -07:00
});
menuItems.push({
2018-10-22 15:05:09 -07:00
name: globalize.translate("ButtonParentalControl"),
id: "parentalcontrol",
2019-11-05 08:24:39 -07:00
icon: "person"
2019-01-04 04:32:24 -07:00
});
menuItems.push({
2018-10-22 15:05:09 -07:00
name: globalize.translate("ButtonDelete"),
id: "delete",
2019-11-05 08:24:39 -07:00
icon: "delete"
2019-01-04 04:32:24 -07:00
});
require(["actionsheet"], function (actionsheet) {
2018-10-22 15:05:09 -07:00
actionsheet.show({
items: menuItems,
positionTo: card,
2019-01-04 04:32:24 -07:00
callback: function (id) {
2018-10-22 15:05:09 -07:00
switch (id) {
case "open":
Dashboard.navigate("useredit.html?userId=" + userId);
break;
2019-01-04 04:32:24 -07:00
2018-10-22 15:05:09 -07:00
case "access":
Dashboard.navigate("userlibraryaccess.html?userId=" + userId);
break;
2019-01-04 04:32:24 -07:00
2018-10-22 15:05:09 -07:00
case "parentalcontrol":
Dashboard.navigate("userparentalcontrol.html?userId=" + userId);
break;
2019-01-04 04:32:24 -07:00
2018-10-22 15:05:09 -07:00
case "delete":
2019-01-04 04:32:24 -07:00
deleteUser(page, userId);
2018-10-22 15:05:09 -07:00
}
}
2019-01-04 04:32:24 -07:00
});
});
2018-10-22 15:05:09 -07:00
}
function getUserHtml(user, addConnectIndicator) {
2019-01-04 04:32:24 -07:00
var html = "";
var cssClass = "card squareCard scalableCard squareCard-scalable";
if (user.Policy.IsDisabled) {
cssClass += " grayscale";
}
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-22 15:05:09 -07:00
var imgUrl;
2019-01-04 04:32:24 -07:00
if (user.PrimaryImageTag) {
imgUrl = ApiClient.getUserImageUrl(user.Id, {
width: 300,
tag: user.PrimaryImageTag,
type: "Primary"
});
}
2018-10-22 15:05:09 -07:00
var imageClass = "cardImage";
2019-01-04 04:32:24 -07:00
if (user.Policy.IsDisabled) {
imageClass += " disabledUser";
}
if (imgUrl) {
html += '<div class="' + imageClass + '" style="background-image:url(\'' + imgUrl + "');\">";
} else {
html += '<div class="' + imageClass + ' flex align-items-center justify-content-center">';
html += '<i class="material-icons cardImageIcon">person</i>';
2019-01-04 04:32:24 -07:00
}
html += "</div>";
html += "</a>";
html += "</div>";
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;
html += "</div>";
html += '<button type="button" is="paper-icon-button-light" class="btnUserMenu flex-shrink-zero"><i class="material-icons more_horiz"></i></button>';
2019-01-04 04:32:24 -07:00
html += "</div>";
html += '<div class="cardText cardText-secondary">';
2018-10-22 15:05:09 -07:00
var lastSeen = getLastSeenText(user.LastActivityDate);
2019-01-04 04:32:24 -07:00
html += "" != lastSeen ? lastSeen : "&nbsp;";
html += "</div>";
html += "</div>";
html += "</div>";
return html + "</div>";
2018-10-22 15:05:09 -07:00
}
function getLastSeenText(lastActivityDate) {
2019-01-04 04:32:24 -07:00
if (lastActivityDate) {
2019-09-11 03:50:29 -07:00
return "Last seen " + humaneDate(lastActivityDate);
2019-01-04 04:32:24 -07:00
}
return "";
2018-10-22 15:05:09 -07:00
}
function getUserSectionHtml(users, addConnectIndicator) {
2019-01-04 04:32:24 -07:00
return users.map(function (u__q) {
return getUserHtml(u__q, addConnectIndicator);
}).join("");
2018-10-22 15:05:09 -07:00
}
function renderUsers(page, users) {
2019-01-04 04:32:24 -07:00
page.querySelector(".localUsers").innerHTML = getUserSectionHtml(users, true);
2018-10-22 15:05:09 -07:00
}
function showPendingUserMenu(elem) {
var menuItems = [];
menuItems.push({
name: globalize.translate("ButtonCancel"),
id: "delete",
2019-11-05 08:24:39 -07:00
icon: "delete"
2019-01-04 04:32:24 -07: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-22 15:05:09 -07:00
actionsheet.show({
items: menuItems,
positionTo: card,
2019-01-04 04:32:24 -07:00
callback: function (menuItemId) {
2018-10-22 15:05:09 -07:00
switch (menuItemId) {
case "delete":
2019-01-04 04:32:24 -07:00
cancelAuthorization(page, id);
2018-10-22 15:05:09 -07:00
}
}
2019-01-04 04:32:24 -07:00
});
});
2018-10-22 15:05:09 -07:00
}
function getPendingUserHtml(user) {
var html = "";
2019-01-04 04:32:24 -07: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 + "');\">";
html += "</div>";
} else {
html += '<i class="cardImageIcon material-icons">person</i>';
2019-01-04 04:32:24 -07:00
}
html += "</a>";
html += "</div>";
html += '<div class="cardFooter visualCardBox-cardFooter">';
html += '<div class="cardText" style="text-align:right; float:right;padding:0;">';
html += '<button type="button" is="paper-icon-button-light" class="btnUserMenu"><i class="material-icons more_horiz"></i></button>';
2019-01-04 04:32:24 -07:00
html += "</div>";
html += '<div class="cardText" style="padding-top:10px;padding-bottom:10px;">';
html += user.UserName;
html += "</div>";
html += "</div>";
html += "</div>";
return html + "</div>";
2018-10-22 15:05:09 -07:00
}
function renderPendingGuests(page, users) {
2019-01-04 04:32:24 -07:00
if (users.length) {
page.querySelector(".sectionPendingGuests").classList.remove("hide");
} else {
page.querySelector(".sectionPendingGuests").classList.add("hide");
}
2018-10-22 15:05:09 -07:00
2019-01-04 04:32:24 -07:00
page.querySelector(".pending").innerHTML = users.map(getPendingUserHtml).join("");
}
2019-01-04 04:32:24 -07:00
// TODO cvium: maybe reuse for invitation system
2018-10-22 15:05:09 -07:00
function cancelAuthorization(page, id) {
2019-01-04 04:32:24 -07:00
loading.show();
ApiClient.ajax({
2018-10-22 15:05:09 -07:00
type: "DELETE",
url: ApiClient.getUrl("Connect/Pending", {
Id: id
})
2019-01-04 04:32:24 -07:00
}).then(function () {
loadData(page);
});
2018-10-22 15:05:09 -07:00
}
function loadData(page) {
2019-01-04 04:32:24 -07: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 04:32:24 -07:00
// });
2018-10-22 15:05:09 -07:00
}
function showInvitePopup(page) {
2019-01-04 04:32:24 -07:00
require(["components/guestinviter/guestinviter"], function (guestinviter) {
guestinviter.show().then(function () {
loadData(page);
});
});
2018-10-22 15:05:09 -07:00
}
2019-01-04 04:32:24 -07:00
pageIdOn("pageinit", "userProfilesPage", function () {
2018-10-22 15:05:09 -07:00
var page = this;
page.querySelector(".btnAddUser").addEventListener("click", function() {
Dashboard.navigate("usernew.html");
});
2019-01-04 04:32:24 -07:00
page.querySelector(".localUsers").addEventListener("click", function (e__e) {
var btnUserMenu = dom.parentWithClass(e__e.target, "btnUserMenu");
if (btnUserMenu) {
showUserMenu(btnUserMenu);
}
});
page.querySelector(".pending").addEventListener("click", function (e__r) {
var btnUserMenu = dom.parentWithClass(e__r.target, "btnUserMenu");
if (btnUserMenu) {
showPendingUserMenu(btnUserMenu);
}
});
});
pageIdOn("pagebeforeshow", "userProfilesPage", function () {
loadData(this);
});
});