2020-05-04 03:44:12 -07:00
|
|
|
define(['dom', 'appRouter', 'connectionManager'], function (dom, appRouter, connectionManager) {
|
|
|
|
'use strict';
|
2018-10-22 15:05:09 -07:00
|
|
|
|
|
|
|
function onGroupedCardClick(e, card) {
|
2020-05-04 03:44:12 -07:00
|
|
|
var itemId = card.getAttribute('data-id');
|
|
|
|
var serverId = card.getAttribute('data-serverid');
|
2019-10-09 09:26:18 -07:00
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
var userId = apiClient.getCurrentUserId();
|
2020-05-04 03:44:12 -07:00
|
|
|
var playedIndicator = card.querySelector('.playedIndicator');
|
2019-10-09 09:26:18 -07:00
|
|
|
var playedIndicatorHtml = playedIndicator ? playedIndicator.innerHTML : null;
|
|
|
|
var options = {
|
2020-05-04 03:44:12 -07:00
|
|
|
Limit: parseInt(playedIndicatorHtml || '10'),
|
|
|
|
Fields: 'PrimaryImageAspectRatio,DateCreated',
|
2019-10-09 09:26:18 -07:00
|
|
|
ParentId: itemId,
|
|
|
|
GroupItems: false
|
|
|
|
};
|
2020-05-04 03:44:12 -07:00
|
|
|
var actionableParent = dom.parentWithTag(e.target, ['A', 'BUTTON', 'INPUT']);
|
2019-10-09 09:26:18 -07:00
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (!actionableParent || actionableParent.classList.contains('cardContent')) {
|
|
|
|
apiClient.getJSON(apiClient.getUrl('Users/' + userId + '/Items/Latest', options)).then(function (items) {
|
2019-10-09 09:26:18 -07:00
|
|
|
if (1 === items.length) {
|
|
|
|
return void appRouter.showItem(items[0]);
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
var url = 'itemdetails.html?id=' + itemId + '&serverId=' + serverId;
|
2019-10-09 09:26:18 -07:00
|
|
|
Dashboard.navigate(url);
|
|
|
|
});
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onItemsContainerClick(e) {
|
2020-05-04 03:44:12 -07:00
|
|
|
var groupedCard = dom.parentWithClass(e.target, 'groupedCard');
|
2019-10-09 09:26:18 -07:00
|
|
|
|
|
|
|
if (groupedCard) {
|
|
|
|
onGroupedCardClick(e, groupedCard);
|
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-10-09 09:26:18 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
return {
|
|
|
|
onItemsContainerClick: onItemsContainerClick
|
2019-10-09 09:26:18 -07:00
|
|
|
};
|
|
|
|
});
|