2016-07-15 22:05:40 -07:00
|
|
|
define(['itemHelper', 'mediaInfo', 'indicators', 'connectionManager', 'layoutManager', 'globalize', 'userdataButtons', 'css!./listview'], function (itemHelper, mediaInfo, indicators, connectionManager, layoutManager, globalize, userdataButtons) {
|
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
|
|
|
|
|
|
|
function getListViewHtml(items, options) {
|
|
|
|
|
2016-07-15 14:16:18 -07:00
|
|
|
if (arguments.length == 1) {
|
|
|
|
options = items;
|
|
|
|
items = options.items;
|
|
|
|
}
|
2016-05-30 09:09:47 -07:00
|
|
|
|
|
|
|
var index = 0;
|
|
|
|
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-07-15 22:05:40 -07:00
|
|
|
var outerHtml = '';
|
|
|
|
|
|
|
|
outerHtml += items.map(function (item) {
|
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-15 22:05:40 -07:00
|
|
|
if (index == 0) {
|
|
|
|
html += '<h1 class="listGroupHeader first">';
|
|
|
|
}
|
|
|
|
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-07-16 11:02:39 -07:00
|
|
|
var cssClass = "listItem";
|
|
|
|
|
|
|
|
if (clickEntireItem) {
|
|
|
|
cssClass += ' itemAction';
|
|
|
|
}
|
2016-05-30 09:09:47 -07:00
|
|
|
|
|
|
|
var downloadWidth = 80;
|
|
|
|
|
|
|
|
if (isLargeStyle) {
|
|
|
|
cssClass += " largeImage";
|
|
|
|
downloadWidth = 500;
|
|
|
|
}
|
|
|
|
|
2016-07-16 11:02:39 -07:00
|
|
|
var playlistItemId = item.PlaylistItemId ? (' data-playlistitemid="' + item.PlaylistItemId + '"') : '';
|
|
|
|
|
|
|
|
html += '<' + outerTagName + ' class="' + cssClass + '" data-index="' + index + '"' + playlistItemId + ' data-action="' + action + '" data-isfolder="' + item.IsFolder + '" data-id="' + item.Id + '" data-serverid="' + item.ServerId + '" data-type="' + item.Type + '">';
|
|
|
|
|
|
|
|
if (!clickEntireItem && options.dragHandle) {
|
|
|
|
html += '<button is="paper-icon-button-light" class="listViewDragHandle autoSize"><i class="md-icon"></i></button>';
|
|
|
|
}
|
2016-05-30 09:09:47 -07:00
|
|
|
|
2016-07-15 14:16:18 -07:00
|
|
|
var imgUrl = getImageUrl(item, downloadWidth);
|
2016-05-30 09:09:47 -07:00
|
|
|
|
|
|
|
if (imgUrl) {
|
|
|
|
html += '<div class="listItemImage lazy" data-src="' + imgUrl + '" item-icon>';
|
|
|
|
} else {
|
2016-07-15 22:05:40 -07:00
|
|
|
html += '<div class="listItemImage">';
|
2016-05-30 09:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var indicatorsHtml = '';
|
|
|
|
indicatorsHtml += indicators.getPlayedIndicatorHtml(item);
|
|
|
|
|
|
|
|
if (indicatorsHtml) {
|
|
|
|
html += '<div class="indicators">' + indicatorsHtml + '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
var progressHtml = indicators.getProgressBarHtml(item);
|
|
|
|
|
|
|
|
if (progressHtml) {
|
|
|
|
html += progressHtml;
|
|
|
|
}
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
var textlines = [];
|
|
|
|
|
|
|
|
if (options.showParentTitle) {
|
|
|
|
if (item.Type == 'Episode') {
|
|
|
|
textlines.push(item.SeriesName || ' ');
|
|
|
|
} else if (item.Type == 'MusicAlbum') {
|
|
|
|
textlines.push(item.AlbumArtist || ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var displayName = itemHelper.getDisplayName(item);
|
|
|
|
|
|
|
|
if (options.showIndexNumber && item.IndexNumber != null) {
|
|
|
|
displayName = item.IndexNumber + ". " + displayName;
|
|
|
|
}
|
|
|
|
textlines.push(displayName);
|
|
|
|
|
|
|
|
if (item.Type == 'Audio') {
|
|
|
|
textlines.push(item.ArtistItems.map(function (a) {
|
|
|
|
return a.Name;
|
|
|
|
|
|
|
|
}).join(', ') || ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
var lineCount = textlines.length;
|
|
|
|
if (!options.enableSideMediaInfo) {
|
|
|
|
lineCount++;
|
|
|
|
}
|
|
|
|
if (enableOverview && item.Overview) {
|
|
|
|
lineCount++;
|
|
|
|
}
|
|
|
|
|
2016-07-16 11:02:39 -07:00
|
|
|
cssClass = 'listItemBody';
|
|
|
|
if (!clickEntireItem) {
|
|
|
|
cssClass += ' itemAction';
|
|
|
|
}
|
|
|
|
|
|
|
|
html += '<div class="' + cssClass + '">';
|
2016-05-30 09:09:47 -07:00
|
|
|
|
|
|
|
for (var i = 0, textLinesLength = textlines.length; i < textLinesLength; i++) {
|
|
|
|
|
|
|
|
if (i == 0 && isLargeStyle) {
|
2016-07-15 22:05:40 -07:00
|
|
|
html += '<h2>';
|
2016-05-30 09:09:47 -07:00
|
|
|
}
|
|
|
|
else if (i == 0) {
|
2016-07-15 22:05:40 -07:00
|
|
|
html += '<h3>';
|
2016-05-30 09:09:47 -07:00
|
|
|
} else {
|
|
|
|
html += '<div class="secondary">';
|
|
|
|
}
|
|
|
|
html += textlines[i] || ' ';
|
|
|
|
if (i == 0 && isLargeStyle) {
|
|
|
|
html += '</h2>';
|
2016-07-15 22:05:40 -07:00
|
|
|
} else if (i == 0) {
|
|
|
|
html += '</h3>';
|
2016-05-30 09:09:47 -07:00
|
|
|
} else {
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.enableSideMediaInfo) {
|
|
|
|
html += '<div class="secondary listItemMediaInfo">' + mediaInfo.getPrimaryMediaInfoHtml(item) + '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enableOverview && item.Overview) {
|
|
|
|
html += '<div class="secondary overview">';
|
|
|
|
html += item.Overview;
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
2016-07-15 14:16:18 -07:00
|
|
|
if (!clickEntireItem) {
|
|
|
|
html += '<button is="paper-icon-button-light" class="listviewMenuButton autoSize"><i class="md-icon"></i></button>';
|
|
|
|
html += '<span class="listViewUserDataButtons">';
|
2016-07-15 22:05:40 -07:00
|
|
|
html += userdataButtons.getIconsHtml(item, false);
|
2016-07-15 14:16:18 -07:00
|
|
|
html += '</span>';
|
|
|
|
}
|
|
|
|
|
2016-05-30 09:09:47 -07:00
|
|
|
if (options.enableSideMediaInfo) {
|
|
|
|
html += '<div class="secondary listItemMediaInfo">' + mediaInfo.getPrimaryMediaInfoHtml(item) + '</div>';
|
|
|
|
}
|
|
|
|
|
2016-07-15 14:16:18 -07:00
|
|
|
html += '</' + outerTagName + '>';
|
2016-05-30 09:09:47 -07:00
|
|
|
|
|
|
|
index++;
|
|
|
|
return html;
|
|
|
|
|
|
|
|
}).join('');
|
2016-07-15 22:05:40 -07:00
|
|
|
|
|
|
|
return outerHtml;
|
2016-05-30 09:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
getListViewHtml: getListViewHtml
|
|
|
|
};
|
|
|
|
});
|