jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/listview/listview.js

416 lines
14 KiB
JavaScript
Raw Normal View History

2016-09-07 13:11:16 -07:00
define(['itemHelper', 'mediaInfo', 'indicators', 'connectionManager', 'layoutManager', 'globalize', 'datetime', 'userdataButtons', 'apphost', 'css!./listview'], function (itemHelper, mediaInfo, indicators, connectionManager, layoutManager, globalize, datetime, userdataButtons, appHost) {
2016-07-15 14:16:18 -07:00
function getIndex(item, options) {
if (options.index == 'disc') {
2016-07-15 22:05:40 -07:00
return item.ParentIndexNumber == null ? '' : globalize.translate('sharedcomponents#ValueDiscNumber', item.ParentIndexNumber);
2016-07-15 14:16:18 -07:00
}
var sortBy = (options.sortBy || '').toLowerCase();
var code, name;
if (sortBy.indexOf('sortname') == 0) {
if (item.Type == 'Episode') return '';
// SortName
name = (item.SortName || item.Name || '?')[0].toUpperCase();
code = name.charCodeAt(0);
if (code < 65 || code > 90) {
return '#';
}
return name.toUpperCase();
}
if (sortBy.indexOf('officialrating') == 0) {
return item.OfficialRating || globalize.translate('sharedcomponents#Unrated');
}
if (sortBy.indexOf('communityrating') == 0) {
if (item.CommunityRating == null) {
return globalize.translate('sharedcomponents#Unrated');
}
return Math.floor(item.CommunityRating);
}
if (sortBy.indexOf('criticrating') == 0) {
if (item.CriticRating == null) {
return globalize.translate('sharedcomponents#Unrated');
}
return Math.floor(item.CriticRating);
}
if (sortBy.indexOf('metascore') == 0) {
if (item.Metascore == null) {
return globalize.translate('sharedcomponents#Unrated');
}
return Math.floor(item.Metascore);
}
if (sortBy.indexOf('albumartist') == 0) {
// SortName
if (!item.AlbumArtist) return '';
name = item.AlbumArtist[0].toUpperCase();
code = name.charCodeAt(0);
if (code < 65 || code > 90) {
return '#';
}
return name.toUpperCase();
}
return '';
}
function getImageUrl(item, width) {
var apiClient = connectionManager.getApiClient(item.ServerId);
var options = {
width: width,
type: "Primary"
};
if (item.ImageTags && item.ImageTags['Primary']) {
options.tag = item.ImageTags['Primary'];
return apiClient.getScaledImageUrl(item.Id, options);
}
if (item.AlbumId && item.AlbumPrimaryImageTag) {
options.tag = item.AlbumPrimaryImageTag;
return apiClient.getScaledImageUrl(item.AlbumId, options);
}
else if (item.SeriesId && item.SeriesPrimaryImageTag) {
options.tag = item.SeriesPrimaryImageTag;
return apiClient.getScaledImageUrl(item.SeriesId, options);
}
else if (item.ParentPrimaryImageTag) {
options.tag = item.ParentPrimaryImageTag;
return apiClient.getScaledImageUrl(item.ParentPrimaryImageItemId, options);
}
return null;
}
2016-05-30 09:09:47 -07:00
2016-07-22 12:48:47 -07:00
function getTextLinesHtml(textlines, isLargeStyle) {
2016-05-30 09:09:47 -07:00
2016-07-22 12:48:47 -07:00
var html = '';
for (var i = 0, length = textlines.length; i < length; i++) {
2016-10-03 22:15:39 -07:00
var text = textlines[i];
if (!text) {
continue;
}
2016-07-22 12:48:47 -07:00
if (i === 0) {
if (isLargeStyle) {
2016-08-05 12:34:10 -07:00
html += '<h2 class="listItemBodyText">';
2016-07-22 12:48:47 -07:00
} else {
2016-08-05 12:34:10 -07:00
html += '<div class="listItemBodyText">';
2016-07-22 12:48:47 -07:00
}
} else {
2016-08-05 12:34:10 -07:00
html += '<div class="secondary listItemBodyText">';
2016-07-22 12:48:47 -07:00
}
html += (textlines[i] || '&nbsp;');
if (i === 0 && isLargeStyle) {
html += '</h2>';
} else {
html += '</div>';
}
2016-07-15 14:16:18 -07:00
}
2016-05-30 09:09:47 -07:00
2016-07-22 12:48:47 -07:00
return html;
}
function getListViewHtml(options) {
var items = options.items;
2016-05-30 09:09:47 -07:00
var groupTitle = '';
var action = options.action || 'link';
var isLargeStyle = options.imageSize == 'large';
var enableOverview = options.enableOverview;
2016-07-15 14:16:18 -07:00
var clickEntireItem = layoutManager.tv ? true : false;
var outerTagName = clickEntireItem ? 'button' : 'div';
2016-10-03 22:15:39 -07:00
var enableSideMediaInfo = options.enableSideMediaInfo != null ? options.enableSideMediaInfo : true;
2016-07-15 14:16:18 -07:00
2016-07-15 22:05:40 -07:00
var outerHtml = '';
2016-07-22 12:48:47 -07:00
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
2016-05-30 09:09:47 -07:00
var html = '';
2016-07-15 22:05:40 -07:00
if (options.showIndex) {
2016-07-15 14:16:18 -07:00
2016-07-15 22:05:40 -07:00
var itemGroupTitle = getIndex(item, options);
2016-07-15 14:16:18 -07:00
2016-07-15 22:05:40 -07:00
if (itemGroupTitle != groupTitle) {
2016-07-15 14:16:18 -07:00
2016-07-15 22:05:40 -07:00
if (html) {
html += '</div>';
}
2016-07-15 14:16:18 -07:00
2016-07-22 12:48:47 -07:00
if (i == 0) {
2016-08-05 12:34:10 -07:00
html += '<h1 class="listGroupHeader listGroupHeader-first">';
2016-07-15 22:05:40 -07:00
}
else {
html += '<h1 class="listGroupHeader">';
}
html += itemGroupTitle;
html += '</h1>';
2016-07-15 14:16:18 -07:00
2016-07-15 22:05:40 -07:00
html += '<div>';
2016-07-15 14:16:18 -07:00
2016-07-15 22:05:40 -07:00
groupTitle = itemGroupTitle;
}
}
2016-07-15 14:16:18 -07:00
2016-10-03 22:15:39 -07:00
var cssClass = "listItem";
2016-09-07 13:11:16 -07:00
2016-10-02 23:28:45 -07:00
if (options.highlight !== false) {
if (i % 2 == 1) {
cssClass += ' listItem-odd';
}
2016-09-07 13:11:16 -07:00
}
2016-07-16 11:02:39 -07:00
if (clickEntireItem) {
2016-08-07 13:57:46 -07:00
cssClass += ' itemAction listItem-button';
2016-07-16 11:02:39 -07:00
}
2016-05-30 09:09:47 -07:00
2016-08-08 11:13:52 -07:00
if (layoutManager.tv) {
cssClass += ' listItem-focusscale';
}
2016-05-30 09:09:47 -07:00
var downloadWidth = 80;
if (isLargeStyle) {
2016-08-05 12:34:10 -07:00
cssClass += " listItem-largeImage";
2016-05-30 09:09:47 -07:00
downloadWidth = 500;
}
2016-07-16 11:02:39 -07:00
var playlistItemId = item.PlaylistItemId ? (' data-playlistitemid="' + item.PlaylistItemId + '"') : '';
2016-07-18 20:57:55 -07:00
var positionTicksData = item.UserData && item.UserData.PlaybackPositionTicks ? (' data-positionticks="' + item.UserData.PlaybackPositionTicks + '"') : '';
var collectionIdData = options.collectionId ? (' data-collectionid="' + options.collectionId + '"') : '';
var playlistIdData = options.playlistId ? (' data-playlistid="' + options.playlistId + '"') : '';
2016-07-29 21:21:03 -07:00
var mediaTypeData = item.MediaType ? (' data-mediatype="' + item.MediaType + '"') : '';
var collectionTypeData = item.CollectionType ? (' data-collectiontype="' + item.CollectionType + '"') : '';
var channelIdData = item.ChannelId ? (' data-channelid="' + item.ChannelId + '"') : '';
2016-07-18 20:57:55 -07:00
2016-07-29 21:21:03 -07:00
html += '<' + outerTagName + ' class="' + cssClass + '" data-index="' + i + '"' + playlistItemId + ' data-action="' + action + '" data-isfolder="' + item.IsFolder + '" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-type="' + item.Type + '"' + mediaTypeData + collectionTypeData + channelIdData + positionTicksData + collectionIdData + playlistIdData + '>';
2016-07-16 11:02:39 -07:00
if (!clickEntireItem && options.dragHandle) {
2016-08-07 11:46:11 -07:00
html += '<button is="paper-icon-button-light" class="listViewDragHandle autoSize listItemButton"><i class="md-icon">&#xE25D;</i></button>';
2016-07-16 11:02:39 -07:00
}
2016-05-30 09:09:47 -07:00
2016-09-07 13:11:16 -07:00
if (options.image !== false) {
var imgUrl = getImageUrl(item, downloadWidth);
2016-05-30 09:09:47 -07:00
2016-09-07 13:11:16 -07:00
var imageClass = isLargeStyle ? 'listItemImage listItemImage-large' : 'listItemImage';
2016-08-05 12:34:10 -07:00
2016-09-07 13:11:16 -07:00
if (imgUrl) {
html += '<div class="' + imageClass + ' lazy" data-src="' + imgUrl + '" item-icon>';
} else {
html += '<div class="' + imageClass + '">';
}
2016-05-30 09:09:47 -07:00
2016-09-07 13:11:16 -07:00
var indicatorsHtml = '';
indicatorsHtml += indicators.getPlayedIndicatorHtml(item);
2016-05-30 09:09:47 -07:00
2016-09-07 13:11:16 -07:00
if (indicatorsHtml) {
html += '<div class="indicators listItemIndicators">' + indicatorsHtml + '</div>';
}
2016-05-30 09:09:47 -07:00
2016-09-07 13:11:16 -07:00
var progressHtml = indicators.getProgressBarHtml(item, {
containerClass: 'listItemProgressBar'
});
2016-05-30 09:09:47 -07:00
2016-09-07 13:11:16 -07:00
if (progressHtml) {
html += progressHtml;
}
html += '</div>';
}
2016-10-02 23:28:45 -07:00
var textlines = [];
if (options.showProgramDateTime) {
textlines.push(datetime.toLocaleString(datetime.parseISO8601Date(item.StartDate), {
weekday: 'long',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit'
}));
2016-05-30 09:09:47 -07:00
}
2016-10-02 23:28:45 -07:00
if (options.showProgramTime) {
textlines.push(datetime.getDisplayTime(datetime.parseISO8601Date(item.StartDate)));
}
2016-10-07 08:08:13 -07:00
var parentTitle = null;
2016-05-30 09:09:47 -07:00
if (options.showParentTitle) {
if (item.Type == 'Episode') {
2016-10-02 23:28:45 -07:00
parentTitle = item.SeriesName;
2016-05-30 09:09:47 -07:00
}
2016-09-07 13:11:16 -07:00
2016-10-02 23:28:45 -07:00
else if (item.IsSeries) {
parentTitle = item.Name;
2016-09-07 19:55:54 -07:00
}
2016-05-30 09:09:47 -07:00
}
var displayName = itemHelper.getDisplayName(item);
if (options.showIndexNumber && item.IndexNumber != null) {
displayName = item.IndexNumber + ". " + displayName;
}
2016-10-02 23:28:45 -07:00
if (options.showParentTitle && options.parentTitleWithTitle) {
2016-10-07 08:08:13 -07:00
if (displayName) {
if (parentTitle) {
parentTitle += ' - ';
}
parentTitle = (parentTitle || '') + displayName;
2016-10-02 23:28:45 -07:00
}
2016-10-03 22:15:39 -07:00
textlines.push(parentTitle || '');
2016-10-02 23:28:45 -07:00
}
else if (options.showParentTitle) {
2016-10-03 22:15:39 -07:00
textlines.push(parentTitle || '');
2016-10-02 23:28:45 -07:00
}
if (displayName && !options.parentTitleWithTitle) {
2016-09-22 23:57:24 -07:00
textlines.push(displayName);
}
2016-05-30 09:09:47 -07:00
2016-10-03 22:15:39 -07:00
if (options.artist !== false) {
if (item.ArtistItems && item.Type != 'MusicAlbum') {
textlines.push(item.ArtistItems.map(function (a) {
return a.Name;
2016-05-30 09:09:47 -07:00
2016-10-03 22:15:39 -07:00
}).join(', '));
}
2016-05-30 09:09:47 -07:00
2016-10-03 22:15:39 -07:00
if (item.AlbumArtist && item.Type == 'MusicAlbum') {
textlines.push(item.AlbumArtist);
}
2016-07-16 14:28:15 -07:00
}
if (item.Type == 'Game') {
2016-10-03 22:15:39 -07:00
textlines.push(item.GameSystem);
2016-07-16 14:28:15 -07:00
}
if (item.Type == 'TvChannel') {
if (item.CurrentProgram) {
textlines.push(itemHelper.getDisplayName(item.CurrentProgram));
}
}
2016-10-03 22:15:39 -07:00
cssClass = 'listItemBody';
2016-07-16 11:02:39 -07:00
if (!clickEntireItem) {
cssClass += ' itemAction';
}
2016-10-03 22:15:39 -07:00
if (options.image === false) {
cssClass += ' itemAction listItemBody-noleftpadding';
}
2016-07-16 11:02:39 -07:00
html += '<div class="' + cssClass + '">';
2016-05-30 09:09:47 -07:00
2016-07-21 13:51:43 -07:00
var moreIcon = appHost.moreIcon == 'dots-horiz' ? '&#xE5D3;' : '&#xE5D4;';
2016-07-22 12:48:47 -07:00
html += getTextLinesHtml(textlines, isLargeStyle);
2016-05-30 09:09:47 -07:00
2016-10-02 23:28:45 -07:00
if (options.mediaInfo !== false) {
if (!enableSideMediaInfo) {
2016-08-08 11:13:52 -07:00
2016-10-02 23:28:45 -07:00
var mediaInfoClass = 'secondary listItemMediaInfo listItemBodyText';
2016-08-08 11:13:52 -07:00
2016-10-02 23:28:45 -07:00
html += '<div class="' + mediaInfoClass + '">' + mediaInfo.getPrimaryMediaInfoHtml(item, {
episodeTitle: false,
originalAirDate: false
}) + '</div>';
}
2016-05-30 09:09:47 -07:00
}
if (enableOverview && item.Overview) {
2016-08-05 12:34:10 -07:00
html += '<div class="secondary overview listItemBodyText">';
2016-05-30 09:09:47 -07:00
html += item.Overview;
html += '</div>';
}
html += '</div>';
2016-10-02 23:28:45 -07:00
if (options.mediaInfo !== false) {
if (enableSideMediaInfo) {
html += '<div class="secondary listItemMediaInfo">' + mediaInfo.getPrimaryMediaInfoHtml(item, {
2016-07-17 11:55:07 -07:00
2016-10-02 23:28:45 -07:00
year: false,
container: false,
episodeTitle: false
2016-07-17 11:55:07 -07:00
2016-10-02 23:28:45 -07:00
}) + '</div>';
}
2016-07-16 16:08:21 -07:00
}
2016-10-03 22:15:39 -07:00
if (!options.recordButton && (item.Type == 'Timer' || item.Type == 'Program')) {
html += indicators.getTimerIndicator(item).replace('indicatorIcon', 'indicatorIcon listItemAside');
}
2016-07-15 14:16:18 -07:00
if (!clickEntireItem) {
2016-10-02 23:28:45 -07:00
if (options.moreButton !== false) {
html += '<button is="paper-icon-button-light" class="listItemButton itemAction autoSize" data-action="menu"><i class="md-icon">' + moreIcon + '</i></button>';
}
2016-09-07 13:11:16 -07:00
2016-10-03 22:15:39 -07:00
if (options.recordButton) {
html += '<button is="paper-icon-button-light" class="listItemButton itemAction autoSize" data-action="programdialog">' + indicators.getTimerIndicator(item) + '</button>';
}
2016-09-07 13:11:16 -07:00
if (options.enableUserDataButtons !== false) {
html += '<span class="listViewUserDataButtons">';
html += userdataButtons.getIconsHtml({
item: item,
includePlayed: false,
cssClass: 'listItemButton'
});
html += '</span>';
}
2016-07-15 14:16:18 -07:00
}
html += '</' + outerTagName + '>';
2016-05-30 09:09:47 -07:00
2016-07-22 12:48:47 -07:00
outerHtml += html;
}
2016-07-15 22:05:40 -07:00
return outerHtml;
2016-05-30 09:09:47 -07:00
}
return {
getListViewHtml: getListViewHtml
};
});