jellyfish-web/src/components/groupedcards.js

46 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-06-16 18:45:21 +01:00
/* eslint-disable indent */
2020-08-14 08:46:34 +02:00
import dom from '../scripts/dom';
import appRouter from './appRouter';
import connectionManager from 'jellyfin-apiclient';
2020-06-16 18:45:21 +01:00
2018-10-23 01:05:09 +03:00
function onGroupedCardClick(e, card) {
2020-10-07 21:12:14 +09:00
const itemId = card.getAttribute('data-id');
const serverId = card.getAttribute('data-serverid');
const apiClient = window.connectionManager.getApiClient(serverId);
const userId = apiClient.getCurrentUserId();
const playedIndicator = card.querySelector('.playedIndicator');
const playedIndicatorHtml = playedIndicator ? playedIndicator.innerHTML : null;
const options = {
2020-05-04 12:44:12 +02:00
Limit: parseInt(playedIndicatorHtml || '10'),
Fields: 'PrimaryImageAspectRatio,DateCreated',
2019-10-09 19:26:18 +03:00
ParentId: itemId,
GroupItems: false
};
2020-10-07 21:12:14 +09:00
const actionableParent = dom.parentWithTag(e.target, ['A', 'BUTTON', 'INPUT']);
2019-10-09 19:26:18 +03:00
2020-05-04 12:44:12 +02:00
if (!actionableParent || actionableParent.classList.contains('cardContent')) {
apiClient.getJSON(apiClient.getUrl('Users/' + userId + '/Items/Latest', options)).then(function (items) {
2020-07-30 16:07:13 +02:00
if (items.length === 1) {
2019-10-09 19:26:18 +03:00
return void appRouter.showItem(items[0]);
}
2020-10-07 21:12:14 +09:00
const url = 'details?id=' + itemId + '&serverId=' + serverId;
2019-10-09 19:26:18 +03:00
Dashboard.navigate(url);
});
e.stopPropagation();
e.preventDefault();
return false;
}
2018-10-23 01:05:09 +03:00
}
2020-07-24 13:08:49 +02:00
export default function onItemsContainerClick(e) {
2020-10-07 21:12:14 +09:00
const groupedCard = dom.parentWithClass(e.target, 'groupedCard');
2019-10-09 19:26:18 +03:00
if (groupedCard) {
onGroupedCardClick(e, groupedCard);
}
2018-10-23 01:05:09 +03:00
}
2020-06-28 16:55:05 +09:00
/* eslint-enable indent */