jellyfin-web/dashboard-ui/scripts/Itemdetailpage.js

1144 lines
34 KiB
JavaScript
Raw Normal View History

2013-04-10 14:14:25 -07:00
(function ($, document, LibraryBrowser, window) {
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
var currentItem;
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
function reload(page) {
2013-03-06 16:28:43 -07:00
2013-02-20 18:33:05 -07:00
var id = getParameterByName('id');
Dashboard.showLoadingMsg();
2013-04-10 14:14:25 -07:00
ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) {
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
currentItem = item;
2013-02-20 18:33:05 -07:00
2013-04-22 07:44:11 -07:00
renderHeader(page, item);
LibraryBrowser.renderName(item, $('.itemName', page));
LibraryBrowser.renderParentName(item, $('.parentName', page));
2013-04-10 14:14:25 -07:00
2013-04-23 07:46:27 -07:00
var context = getContext(item);
Dashboard.getCurrentUser().done(function (user) {
2013-11-27 12:04:19 -07:00
var imageHref = user.Configuration.IsAdministrator ? "edititemimages.html?id=" + item.Id : "";
2013-11-28 11:27:29 -07:00
2013-11-27 12:04:19 -07:00
$('#itemImage', page).html(LibraryBrowser.getDetailImageHtml(item, imageHref));
setInitialCollapsibleState(page, item, context, user);
renderDetails(page, item, context);
LibraryBrowser.renderDetailPageBackdrop(page, item);
if (user.Configuration.IsAdministrator) {
$('#editButtonContainer', page).show();
} else {
$('#editButtonContainer', page).hide();
}
});
2013-02-20 18:33:05 -07:00
2013-07-29 08:05:09 -07:00
if (item.LocationType == "Offline") {
2013-07-29 08:05:09 -07:00
$('#offlineIndicator', page).show();
}
else {
2013-07-29 08:05:09 -07:00
$('#offlineIndicator', page).hide();
}
var isMissingEpisode = false;
if (item.LocationType == "Virtual" && item.Type == "Episode") {
try {
if (item.PremiereDate && (new Date().getTime() >= parseISO8601Date(item.PremiereDate, { toLocal: true }).getTime())) {
isMissingEpisode = true;
}
} catch (err) {
}
}
if (isMissingEpisode) {
$('#missingIndicator', page).show();
}
else {
$('#missingIndicator', page).hide();
}
if (MediaPlayer.canPlay(item) && item.LocationType !== "Offline" && item.LocationType !== "Virtual") {
var url = MediaPlayer.getPlayUrl(item);
if (url) {
$('#playExternalButtonContainer', page).show();
$('#playButtonContainer', page).hide();
} else {
$('#playButtonContainer', page).show();
$('#playExternalButtonContainer', page).hide();
}
$('#btnPlayExternal', page).attr('href', url || '#');
2013-04-10 14:14:25 -07:00
} else {
$('#playButtonContainer', page).hide();
$('#playExternalButtonContainer', page).hide();
2013-04-10 14:14:25 -07:00
}
2013-04-17 18:32:38 -07:00
2013-04-30 20:28:26 -07:00
$(".autoNumeric").autoNumeric('init');
setPeopleHeader(page, item);
2013-05-10 05:18:07 -07:00
if (ApiClient.isWebSocketOpen()) {
2013-05-21 20:59:55 -07:00
ApiClient.sendWebSocketMessage("Context", [item.Type, item.Id, item.Name, context].join('|'));
2013-05-10 05:18:07 -07:00
}
2013-04-10 14:14:25 -07:00
Dashboard.hideLoadingMsg();
});
}
2013-04-24 13:28:42 -07:00
function setPeopleHeader(page, item) {
if (item.Type == "Audio" || item.Type == "MusicAlbum" || item.MediaType == "Book" || item.MediaType == "Photo") {
$('#peopleHeader', page).html('People');
} else {
$('#peopleHeader', page).html('Cast & Crew');
}
}
2013-04-23 07:46:27 -07:00
function getContext(item) {
// should return either movies, tv, music or games
2013-04-24 13:28:42 -07:00
2013-04-23 07:46:27 -07:00
if (item.Type == "Episode" || item.Type == "Series" || item.Type == "Season") {
return "tv";
}
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "BoxSet") {
return "movies";
}
2013-11-21 13:48:26 -07:00
if (item.Type == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist" || item.Type == "MusicVideo") {
2013-04-23 07:46:27 -07:00
return "music";
}
if (item.MediaType == "Game") {
return "games";
}
return "";
}
2013-04-22 07:44:11 -07:00
function renderHeader(page, item) {
2013-04-28 11:47:19 -07:00
$('.itemTabs', page).hide();
2013-04-22 08:10:54 -07:00
if (item.Type == "MusicAlbum") {
$('#albumTabs', page).show();
}
if (item.Type == "MusicVideo") {
$('#musicVideoTabs', page).show();
}
2013-04-22 07:44:11 -07:00
if (item.Type == "Audio") {
$('#songTabs', page).show();
}
if (item.Type == "Movie") {
$('#movieTabs', page).show();
}
2013-04-24 13:28:42 -07:00
if (item.MediaType == "Game") {
$('#gameTabs', page).show();
2013-04-28 11:47:19 -07:00
}
2013-09-21 14:00:04 -07:00
if (item.Type == "GameSystem") {
2013-04-28 11:47:19 -07:00
$('#gameSystemTabs', page).show();
2013-04-24 13:28:42 -07:00
}
2013-04-22 07:44:11 -07:00
if (item.Type == "BoxSet") {
$('#boxsetTabs', page).show();
}
2013-04-28 11:47:19 -07:00
2013-04-22 07:44:11 -07:00
if (item.Type == "Trailer") {
$('#trailerTabs', page).show();
}
2013-04-28 11:47:19 -07:00
2013-04-22 07:44:11 -07:00
if (item.Type == "Episode" || item.Type == "Season" || item.Type == "Series") {
$('#tvShowsTabs', page).show();
}
}
function setInitialCollapsibleState(page, item, context, user) {
2013-04-14 08:14:10 -07:00
if (item.IsFolder) {
2013-05-18 15:48:19 -07:00
$('#childrenCollapsible', page).removeClass('hide');
renderChildren(page, item, user);
2013-04-22 20:56:11 -07:00
}
else {
2013-05-18 15:48:19 -07:00
$('#childrenCollapsible', page).addClass('hide');
2013-04-22 07:44:11 -07:00
}
2013-05-15 20:39:15 -07:00
if (item.MediaStreams && item.MediaStreams.length) {
2013-04-22 07:44:11 -07:00
renderMediaInfo(page, item);
2013-03-26 16:57:18 -07:00
}
if (!item.Chapters || !item.Chapters.length) {
2013-03-26 14:32:01 -07:00
$('#scenesCollapsible', page).hide();
} else {
2013-03-26 15:53:06 -07:00
$('#scenesCollapsible', page).show();
2013-05-11 23:05:51 -07:00
renderScenes(page, item, 6);
}
if (!item.LocalTrailerCount && !item.RemoteTrailers.length) {
2013-05-18 15:48:19 -07:00
$('#trailersCollapsible', page).addClass('hide');
2013-03-26 14:32:01 -07:00
} else {
2013-05-18 15:48:19 -07:00
$('#trailersCollapsible', page).removeClass('hide');
2013-04-22 07:44:11 -07:00
renderTrailers(page, item);
}
2013-09-05 05:48:14 -07:00
if (!item.SpecialFeatureCount || item.SpecialFeatureCount == 0 || item.Type == "Series") {
2013-05-18 15:48:19 -07:00
$('#specialsCollapsible', page).addClass('hide');
2013-03-26 14:32:01 -07:00
} else {
2013-05-18 15:48:19 -07:00
$('#specialsCollapsible', page).removeClass('hide');
2013-05-11 23:05:51 -07:00
renderSpecials(page, item, 6);
}
2013-03-26 22:20:46 -07:00
if (!item.People || !item.People.length) {
$('#castCollapsible', page).hide();
} else {
$('#castCollapsible', page).show();
renderCast(page, item, context, 8);
2013-03-26 22:20:46 -07:00
}
2013-04-24 09:03:10 -07:00
if (!item.PartCount || item.PartCount < 2) {
$('#additionalPartsCollapsible', page).addClass('hide');
} else {
$('#additionalPartsCollapsible', page).removeClass('hide');
renderAdditionalParts(page, item);
}
2013-04-24 09:03:10 -07:00
$('#themeSongsCollapsible', page).hide();
$('#themeVideosCollapsible', page).hide();
2013-04-24 09:03:10 -07:00
2013-07-16 09:03:28 -07:00
if (!item.SoundtrackIds || !item.SoundtrackIds.length) {
$('#soundtracksCollapsible', page).hide();
} else {
$('#soundtracksCollapsible', page).show();
renderSoundtracks(page, item);
}
2013-07-29 12:12:21 -07:00
if (item.Type == "MusicAlbum") {
renderMusicVideos(page, item);
} else {
$('#musicVideosCollapsible', page).hide();
2013-07-29 12:12:21 -07:00
}
renderThemeSongs(page, item);
renderThemeVideos(page, item);
2013-05-11 23:05:51 -07:00
renderCriticReviews(page, item, 1);
2013-04-10 14:14:25 -07:00
}
2013-04-23 07:46:27 -07:00
function renderDetails(page, item, context) {
2013-02-20 18:33:05 -07:00
renderSimilarItems(page, item);
renderSiblingLinks(page, item);
2013-02-20 18:33:05 -07:00
if (item.Taglines && item.Taglines.length) {
$('#itemTagline', page).html(item.Taglines[0]).show();
} else {
$('#itemTagline', page).hide();
}
LibraryBrowser.renderOverview($('.itemOverview', page), item);
2013-02-20 18:33:05 -07:00
2013-05-05 21:50:40 -07:00
if (item.CommunityRating || item.CriticRating) {
$('.itemCommunityRating', page).html(LibraryBrowser.getRatingHtml(item)).show();
2013-02-20 18:33:05 -07:00
} else {
$('.itemCommunityRating', page).hide();
2013-02-20 18:33:05 -07:00
}
if (item.Type != "Episode" && item.Type != "Movie" && item.Type != "Series") {
2013-05-04 12:53:13 -07:00
var premiereDateElem = $('#itemPremiereDate', page).show();
LibraryBrowser.renderPremiereDate(premiereDateElem, item);
} else {
$('#itemPremiereDate', page).hide();
}
2013-04-12 08:25:00 -07:00
LibraryBrowser.renderBudget($('#itemBudget', page), item);
2013-04-18 07:05:38 -07:00
LibraryBrowser.renderRevenue($('#itemRevenue', page), item);
2013-04-12 08:25:00 -07:00
$('.itemMiscInfo', page).html(LibraryBrowser.getMiscInfoHtml(item));
2013-02-20 18:33:05 -07:00
LibraryBrowser.renderGenres($('.itemGenres', page), item, context);
LibraryBrowser.renderStudios($('.itemStudios', page), item, context);
2013-04-10 14:14:25 -07:00
renderUserDataIcons(page, item);
LibraryBrowser.renderLinks($('.itemExternalLinks', page), item);
$('.criticRatingScore', page).html((item.CriticRating || '0') + '%');
2013-05-06 20:00:24 -07:00
2013-05-05 21:50:40 -07:00
if (item.CriticRatingSummary) {
$('#criticRatingSummary', page).show();
$('.criticRatingSummaryText', page).html(item.CriticRatingSummary);
2013-05-05 21:50:40 -07:00
} else {
$('#criticRatingSummary', page).hide();
}
2013-05-06 20:00:24 -07:00
renderTags(page, item);
2013-05-14 22:04:12 -07:00
renderSeriesAirTime(page, item, context);
2013-05-16 20:24:41 -07:00
if (item.Players) {
$('#players', page).show().html(item.Players + ' Player');
} else {
$('#players', page).hide();
}
if (item.Artists && item.Artists.length) {
$('#artist', page).show().html(getArtistLinksHtml(item.Artists)).trigger('create');
2013-05-16 20:24:41 -07:00
} else {
$('#artist', page).hide();
}
2013-05-28 13:01:33 -07:00
var detailsSection = $('#detailsSection', page);
var elem = $('.detailSectionContent', detailsSection)[0];
var text = elem.textContent || elem.innerText;
if (!text.trim()) {
detailsSection.addClass('hide');
} else {
detailsSection.removeClass('hide');
}
2013-05-15 06:57:13 -07:00
}
function getArtistLinksHtml(artists) {
var html = [];
for (var i = 0, length = artists.length; i < length; i++) {
var artist = artists[i];
2013-11-21 13:48:26 -07:00
html.push('<a class="textlink" href="itembynamedetails.html?context=music&musicartist=' + ApiClient.encodeName(artist) + '">' + artist + '</a>');
}
html = html.join(' / ');
if (artists.length == 1) {
return 'Artist:&nbsp;&nbsp;' + html;
}
if (artists.length > 1) {
return 'Artists:&nbsp;&nbsp;' + html;
}
return html;
}
2013-07-29 12:12:21 -07:00
2013-07-16 09:03:28 -07:00
function renderSoundtracks(page, item) {
2013-07-29 12:12:21 -07:00
2013-07-16 09:03:28 -07:00
if (item.Type == "MusicAlbum") {
$('#soundtracksHeader', page).html("This album is the soundtrack for ...");
} else {
$('#soundtracksHeader', page).html("Soundtrack(s)");
}
ApiClient.getItems(Dashboard.getCurrentUserId(), {
Ids: item.SoundtrackIds.join(","),
2013-09-17 19:43:34 -07:00
ItemFields: "PrimaryImageAspectRatio,ItemCounts,DateCreated,AudioInfo",
2013-07-16 09:03:28 -07:00
SortBy: "SortName"
}).done(function (result) {
var html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
useAverageAspectRatio: true,
showNewIndicator: true,
shape: item.Type == "MusicAlbum" ? "portrait" : "square"
});
$('#soundtracksContent', page).html(html);
});
}
2013-05-15 15:55:24 -07:00
function renderSiblingLinks(page, item) {
$('.lnkSibling', page).addClass('hide');
if ((item.Type != "Episode" && item.Type != "Season" && item.Type != "Audio") || item.IndexNumber == null) {
return;
}
var promise;
if (item.Type == "Season") {
promise = ApiClient.getSeasons(item.SeriesId, {
userId: Dashboard.getCurrentUserId(),
AdjacentTo: item.Id
});
}
else if (item.Type == "Episode") {
// Use dedicated episodes endpoint
promise = ApiClient.getEpisodes(item.SeriesId, {
seasonId: item.SeasonId,
userId: Dashboard.getCurrentUserId(),
AdjacentTo: item.Id
});
} else {
promise = ApiClient.getItems(Dashboard.getCurrentUserId(), {
AdjacentTo: item.Id,
ParentId: item.ParentId
});
}
promise.done(function (result) {
for (var i = 0, length = result.Items.length; i < length; i++) {
var curr = result.Items[i];
if (curr.IndexNumber == null) {
continue;
}
var friendlyTypeName = item.Type == "Audio" ? "song" : item.Type.toLowerCase();
if (curr.IndexNumber < item.IndexNumber) {
$('.lnkPreviousItem', page).removeClass('hide').attr('href', 'itemdetails.html?id=' + curr.Id).html('← Previous ' + friendlyTypeName);
}
else if (curr.IndexNumber > item.IndexNumber) {
$('.lnkNextItem', page).removeClass('hide').attr('href', 'itemdetails.html?id=' + curr.Id).html('Next ' + friendlyTypeName + ' →');
}
}
});
}
function renderSimilarItems(page, item) {
2013-05-15 15:55:24 -07:00
var promise;
2013-05-15 15:55:24 -07:00
var options = {
userId: Dashboard.getCurrentUserId(),
limit: item.Type == "MusicAlbum" ? 6 : 6,
2013-06-03 19:02:49 -07:00
fields: "PrimaryImageAspectRatio,DateCreated,UserData"
};
2013-05-28 13:01:33 -07:00
if (item.Type == "Movie") {
promise = ApiClient.getSimilarMovies(item.Id, options);
}
else if (item.Type == "Trailer") {
promise = ApiClient.getSimilarTrailers(item.Id, options);
}
else if (item.Type == "MusicAlbum") {
promise = ApiClient.getSimilarAlbums(item.Id, options);
}
else if (item.Type == "Series") {
promise = ApiClient.getSimilarShows(item.Id, options);
}
else if (item.MediaType == "Game") {
promise = ApiClient.getSimilarGames(item.Id, options);
} else {
2013-05-15 15:55:24 -07:00
$('#similarCollapsible', page).hide();
return;
}
promise.done(function (result) {
2013-05-15 15:55:24 -07:00
if (!result.Items.length) {
$('#similarCollapsible', page).hide();
return;
}
var elem = $('#similarCollapsible', page).show();
$('.detailSectionHeader', elem).html('If you like ' + item.Name + ', check these out...');
var html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
2013-05-16 13:46:18 -07:00
useAverageAspectRatio: item.MediaType != "Game",
2013-05-15 15:55:24 -07:00
showNewIndicator: true,
shape: item.Type == "MusicAlbum" ? "square" : "portrait"
});
$('#similarContent', page).html(html);
});
}
2013-05-15 06:57:13 -07:00
function renderSeriesAirTime(page, item, context) {
2013-05-15 15:55:24 -07:00
2013-05-15 06:57:13 -07:00
if (item.Type != "Series") {
$('#seriesAirTime', page).hide();
return;
}
2013-06-04 09:48:23 -07:00
var html = '';
2013-05-15 15:55:24 -07:00
if (item.AirDays && item.AirDays.length) {
2013-06-04 09:48:23 -07:00
html += item.AirDays.length == 7 ? 'daily' : item.AirDays.map(function (a) {
2013-05-15 06:57:13 -07:00
return a + "s";
}).join(',');
}
2013-05-15 15:55:24 -07:00
2013-05-15 06:57:13 -07:00
if (item.AirTime) {
html += ' at ' + item.AirTime;
}
if (item.Studios.length) {
html += ' on <a class="textlink" href="itembynamedetails.html?context=' + context + '&studio=' + ApiClient.encodeName(item.Studios[0].Name) + '">' + item.Studios[0].Name + '</a>';
}
2013-06-04 09:48:23 -07:00
if (html) {
html = (item.Status == 'Ended' ? 'Aired ' : 'Airs ') + html;
2013-06-04 09:48:23 -07:00
$('#seriesAirTime', page).show().html(html).trigger('create');
} else {
$('#seriesAirTime', page).hide();
}
2013-05-06 20:00:24 -07:00
}
function renderTags(page, item) {
if (item.Tags && item.Tags.length) {
var html = '';
for (var i = 0, length = item.Tags.length; i < length; i++) {
html += '<div class="itemTag">' + item.Tags[i] + '</div>';
}
$('.itemTags', page).show().html(html);
2013-05-06 20:00:24 -07:00
} else {
$('.itemTags', page).hide();
2013-05-06 20:00:24 -07:00
}
2013-04-10 14:14:25 -07:00
}
function renderChildren(page, item, user) {
2013-06-04 20:40:17 -07:00
var sortBy = item.Type == "BoxSet" ? "ProductionYear,SortName" : "SortName";
2013-05-15 15:55:24 -07:00
var query = {
ParentId: item.Id,
2013-05-15 06:57:13 -07:00
SortBy: sortBy,
Fields: "ItemCounts,DateCreated,AudioInfo"
};
2013-04-22 07:44:11 -07:00
var promise;
2013-11-28 11:27:29 -07:00
if (item.Type == "Series") {
2013-11-28 11:27:29 -07:00
promise = ApiClient.getSeasons(item.Id, {
2013-11-15 14:31:33 -07:00
userId: user.Id
});
2013-11-15 14:31:33 -07:00
}
2013-12-01 19:24:14 -07:00
else if (item.Type == "Season") {
2013-11-15 14:31:33 -07:00
// Use dedicated episodes endpoint
promise = ApiClient.getEpisodes(item.SeriesId, {
2013-11-28 11:27:29 -07:00
seasonId: item.Id,
userId: user.Id
});
}
promise = promise || ApiClient.getItems(Dashboard.getCurrentUserId(), query);
promise.done(function (result) {
2013-04-22 07:44:11 -07:00
2013-04-22 13:06:43 -07:00
if (item.Type == "MusicAlbum") {
2013-04-22 07:44:11 -07:00
$('#childrenContent', page).html(LibraryBrowser.getSongTableHtml(result.Items, { showArtist: true })).trigger('create');
2013-04-22 13:06:43 -07:00
} else {
2013-04-28 11:47:19 -07:00
2013-05-04 11:21:29 -07:00
var shape = "smallPoster";
2013-05-04 11:21:29 -07:00
if (item.Type == "Season") {
shape = "smallBackdrop";
}
2013-04-28 11:47:19 -07:00
2013-04-22 13:06:43 -07:00
var html = LibraryBrowser.getPosterDetailViewHtml({
items: result.Items,
2013-04-28 11:47:19 -07:00
useAverageAspectRatio: true,
shape: shape,
2013-11-15 14:31:33 -07:00
showParentName: false,
displayAsSpecial: item.Type == "Season" && item.IndexNumber
2013-04-22 13:06:43 -07:00
});
$('#childrenContent', page).html(html);
}
2013-04-22 07:44:11 -07:00
});
if (item.Type == "Season") {
$('#childrenTitle', page).html('Episodes');
2013-04-22 07:44:11 -07:00
}
else if (item.Type == "Series") {
$('#childrenTitle', page).html('Seasons');
2013-04-22 07:44:11 -07:00
}
else if (item.Type == "BoxSet") {
$('#childrenTitle', page).html('Movies');
2013-04-22 07:44:11 -07:00
}
2013-04-22 08:10:54 -07:00
else if (item.Type == "MusicAlbum") {
$('#childrenTitle', page).html('Tracks');
2013-04-22 08:10:54 -07:00
}
2013-09-21 14:00:04 -07:00
else if (item.Type == "GameSystem") {
$('#childrenTitle', page).html('Games');
2013-04-28 11:47:19 -07:00
}
2013-04-22 07:44:11 -07:00
else {
$('#childrenTitle', page).html('Items');
2013-04-22 07:44:11 -07:00
}
}
2013-04-10 14:14:25 -07:00
function renderUserDataIcons(page, item) {
$('.userDataIcons', page).html(LibraryBrowser.getUserDataIconsHtml(item));
2013-04-10 14:14:25 -07:00
}
2013-04-24 13:28:42 -07:00
2013-05-11 23:05:51 -07:00
function renderCriticReviews(page, item, limit) {
if (item.Type != "Movie" && item.Type != "Trailer" && item.Type != "MusicVideo") {
$('#criticReviewsCollapsible', page).hide();
return;
}
2013-05-11 23:05:51 -07:00
var options = {};
if (limit) {
options.limit = limit;
}
ApiClient.getCriticReviews(item.Id, options).done(function (result) {
if (result.TotalRecordCount || item.CriticRatingSummary) {
2013-05-11 23:05:51 -07:00
$('#criticReviewsCollapsible', page).show();
renderCriticReviewsContent(page, result, limit);
} else {
$('#criticReviewsCollapsible', page).hide();
}
});
}
function renderCriticReviewsContent(page, result, limit) {
var html = '';
2013-11-28 11:27:29 -07:00
var reviews = result.Items;
2013-05-11 23:05:51 -07:00
for (var i = 0, length = reviews.length; i < length; i++) {
var review = reviews[i];
html += '<div class="criticReview">';
html += '<div class="reviewScore">';
if (review.Score != null) {
html += review.Score;
}
else if (review.Likes != null) {
if (review.Likes) {
html += '<img src="css/images/fresh.png" />';
} else {
html += '<img src="css/images/rotten.png" />';
}
}
2013-05-11 23:05:51 -07:00
html += '</div>';
html += '<div class="reviewCaption">' + review.Caption + '</div>';
var vals = [];
if (review.ReviewerName) {
vals.push(review.ReviewerName);
}
if (review.Publisher) {
vals.push(review.Publisher);
}
html += '<div class="reviewerName">' + vals.join(', ') + '.';
if (review.Date) {
try {
var date = parseISO8601Date(review.Date, { toLocal: true }).toLocaleDateString();
2013-05-11 23:05:51 -07:00
html += '<span class="reviewDate">' + date + '</span>';
}
catch (error) {
}
}
html += '</div>';
if (review.Url) {
html += '<div class="reviewLink"><a class="textlink" href="' + review.Url + '" target="_blank">Full review</a></div>';
}
html += '</div>';
}
if (limit && result.TotalRecordCount > limit) {
html += '<p style="margin: .5em 0 0;padding-left: .5em;"><button class="moreCriticReviews" data-inline="true" data-mini="true">More ...</button></p>';
}
$('#criticReviewsContent', page).html(html).trigger('create');
}
function renderThemeSongs(page, item) {
2013-04-24 13:28:42 -07:00
ApiClient.getThemeSongs(Dashboard.getCurrentUserId(), item.Id).done(function (result) {
if (result.Items.length) {
2013-04-24 13:28:42 -07:00
$('#themeSongsCollapsible', page).show();
$('#themeSongsContent', page).html(LibraryBrowser.getSongTableHtml(result.Items, { showArtist: true, showAlbum: true })).trigger('create');
} else {
$('#themeSongsCollapsible', page).hide();
}
});
2013-04-24 09:03:10 -07:00
}
2013-02-20 18:33:05 -07:00
2013-07-29 12:12:21 -07:00
function renderMusicVideos(page, item) {
ApiClient.getItems(Dashboard.getCurrentUserId(), {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "MusicVideo",
Recursive: true,
Fields: "DateCreated",
Albums: item.Name
2013-07-29 12:12:21 -07:00
}).done(function (result) {
if (result.Items.length) {
$('#musicVideosCollapsible', page).show();
$('#musicVideosContent', page).html(getVideosHtml(result.Items)).trigger('create');
} else {
$('#musicVideosCollapsible', page).hide();
}
});
}
function renderThemeVideos(page, item) {
2013-04-28 10:21:56 -07:00
ApiClient.getThemeVideos(Dashboard.getCurrentUserId(), item.Id).done(function (result) {
if (result.Items.length) {
2013-04-28 10:21:56 -07:00
$('#themeVideosCollapsible', page).show();
$('#themeVideosContent', page).html(getVideosHtml(result.Items)).trigger('create');
} else {
$('#themeVideosCollapsible', page).hide();
}
});
2013-04-28 10:21:56 -07:00
}
function renderAdditionalParts(page, item) {
ApiClient.getAdditionalVideoParts(Dashboard.getCurrentUserId(), item.Id).done(function (result) {
if (result.Items.length) {
$('#additionalPartsCollapsible', page).show();
$('#additionalPartsContent', page).html(getVideosHtml(result.Items)).trigger('create');
} else {
$('#additionalPartsCollapsible', page).hide();
}
});
}
2013-05-11 23:05:51 -07:00
function renderScenes(page, item, limit) {
2013-02-20 18:33:05 -07:00
var html = '';
2013-04-10 14:14:25 -07:00
2013-05-11 23:05:51 -07:00
var chapters = item.Chapters || [];
2013-02-20 18:33:05 -07:00
for (var i = 0, length = chapters.length; i < length; i++) {
2013-05-11 23:05:51 -07:00
if (limit && i >= limit) {
break;
}
var chapter = chapters[i];
2013-04-10 10:11:23 -07:00
var chapterName = chapter.Name || "Chapter " + i;
2013-05-03 13:50:13 -07:00
html += '<a class="posterItem smallBackdropPosterItem" href="#play-Chapter-' + i + '" onclick="ItemDetailPage.play(' + chapter.StartPositionTicks + ');">';
var imgUrl;
if (chapter.ImageTag) {
2013-05-03 13:50:13 -07:00
imgUrl = ApiClient.getImageUrl(item.Id, {
maxwidth: 400,
tag: chapter.ImageTag,
type: "Chapter",
index: i
});
} else {
2013-05-03 13:50:13 -07:00
imgUrl = "css/images/items/list/chapter.png";
}
2013-02-20 18:33:05 -07:00
2013-05-03 13:50:13 -07:00
html += '<div class="posterItemImage" style="background-image:url(\'' + imgUrl + '\');"></div>';
html += '<div class="posterItemText">' + chapterName + '</div>';
html += '<div class="posterItemText">';
2013-02-20 18:33:05 -07:00
2013-06-07 10:29:33 -07:00
html += Dashboard.getDisplayTime(chapter.StartPositionTicks);
2013-03-26 15:53:06 -07:00
html += '</div>';
html += '</a>';
2013-02-20 18:33:05 -07:00
}
2013-05-11 23:05:51 -07:00
if (limit && chapters.length > limit) {
html += '<p style="margin: .5em 0 0;padding-left: .5em;"><button class="moreScenes" data-inline="true" data-mini="true">More ...</button></p>';
}
$('#scenesContent', page).html(html).trigger('create');
2013-04-10 14:14:25 -07:00
}
2013-03-06 16:28:43 -07:00
2013-04-10 14:14:25 -07:00
function renderMediaInfo(page, item) {
2013-03-26 14:32:01 -07:00
2013-03-26 16:57:18 -07:00
var html = '';
for (var i = 0, length = item.MediaStreams.length; i < length; i++) {
var stream = item.MediaStreams[i];
2013-04-09 11:01:39 -07:00
if (stream.Type == "Data") {
continue;
}
2013-04-09 11:38:58 -07:00
var type;
if (item.MediaType == "Audio" && stream.Type == "Video") {
type = "Embedded Image";
} else {
type = stream.Type;
}
2013-04-09 11:38:58 -07:00
html += '<div class="mediaInfoStream">';
2013-03-26 16:57:18 -07:00
2013-05-15 20:39:15 -07:00
html += '<span class="mediaInfoStreamType">' + type + ':</span>';
2013-04-09 19:28:24 -07:00
2013-05-15 20:39:15 -07:00
var attributes = [];
2013-04-09 19:28:24 -07:00
2013-11-12 09:08:23 -07:00
if (stream.Language) {
attributes.push('<span class="mediaInfoAttribute">' + stream.Language + '</span>');
}
2013-09-03 14:06:33 -07:00
if (stream.Codec && stream.Codec != "dca") {
2013-05-15 20:39:15 -07:00
attributes.push('<span class="mediaInfoAttribute">' + stream.Codec + '</span>');
2013-04-09 11:38:58 -07:00
}
2013-09-03 14:06:33 -07:00
if (stream.Profile && stream.Codec == "dca") {
2013-05-15 20:39:15 -07:00
attributes.push('<span class="mediaInfoAttribute">' + stream.Profile + '</span>');
2013-04-09 11:38:58 -07:00
}
2013-09-03 14:06:33 -07:00
if (stream.Width || stream.Height) {
attributes.push('<span class="mediaInfoAttribute">' + stream.Width + 'x' + stream.Height + '</span>');
2013-04-09 11:38:58 -07:00
}
2013-05-15 20:39:15 -07:00
if (stream.AspectRatio && stream.Codec != "mjpeg") {
2013-05-15 20:39:15 -07:00
attributes.push('<span class="mediaInfoAttribute">' + stream.AspectRatio + '</span>');
2013-04-09 11:38:58 -07:00
}
2013-05-15 20:39:15 -07:00
2013-11-12 09:08:23 -07:00
if (stream.ChannelLayout) {
attributes.push('<span class="mediaInfoAttribute">' + stream.ChannelLayout + '</span>');
}
2013-11-12 09:08:23 -07:00
else if (stream.Channels) {
2013-05-15 20:39:15 -07:00
attributes.push('<span class="mediaInfoAttribute">' + stream.Channels + ' ch</span>');
2013-03-26 16:57:18 -07:00
}
2013-05-15 20:39:15 -07:00
2013-11-12 09:08:23 -07:00
if (stream.BitRate && stream.Codec != "mjpeg") {
attributes.push('<span class="mediaInfoAttribute">' + (parseInt(stream.BitRate / 1000)) + ' kbps</span>');
}
2013-05-15 20:39:15 -07:00
if (stream.IsDefault) {
attributes.push('<span class="mediaInfoAttribute">Default</span>');
2013-04-09 11:38:58 -07:00
}
2013-05-15 20:39:15 -07:00
if (stream.IsForced) {
attributes.push('<span class="mediaInfoAttribute">Forced</span>');
}
if (stream.IsExternal) {
attributes.push('<span class="mediaInfoAttribute">External</span>');
2013-03-26 16:57:18 -07:00
}
2013-05-15 20:39:15 -07:00
html += attributes.join('&nbsp;&#149;&nbsp;');
2013-04-09 11:38:58 -07:00
html += '</div>';
2013-02-20 18:33:05 -07:00
}
2013-03-26 16:57:18 -07:00
$('#mediaInfoContent', page).html(html).trigger('create');
2013-04-10 14:14:25 -07:00
}
2013-05-11 23:05:51 -07:00
function getVideosHtml(items, limit, moreButtonClass) {
2013-04-28 10:21:56 -07:00
var html = '';
2013-04-28 10:21:56 -07:00
for (var i = 0, length = items.length; i < length; i++) {
2013-05-11 23:05:51 -07:00
if (limit && i >= limit) {
break;
}
2013-04-28 10:21:56 -07:00
var item = items[i];
2013-05-11 23:05:51 -07:00
var cssClass = "posterItem smallBackdropPosterItem";
2013-07-29 12:12:21 -07:00
var href = "itemdetails.html?id=" + item.Id;
html += '<a class="' + cssClass + '" href="' + href + '" onclick="MediaPlayer.playById(\'' + item.Id + '\'); return false;">';
2013-04-28 10:21:56 -07:00
var imageTags = item.ImageTags || {};
2013-04-28 10:39:16 -07:00
var imgUrl;
2013-04-28 10:21:56 -07:00
if (imageTags.Primary) {
2013-03-29 07:12:14 -07:00
2013-04-28 10:39:16 -07:00
imgUrl = ApiClient.getImageUrl(item.Id, {
2013-04-28 10:21:56 -07:00
maxwidth: 500,
tag: imageTags.Primary,
type: "primary"
});
2013-04-28 10:21:56 -07:00
} else {
2013-04-28 10:39:16 -07:00
imgUrl = "css/images/items/detail/video.png";
2013-04-28 10:21:56 -07:00
}
2013-04-28 10:39:16 -07:00
html += '<div class="posterItemImage" style="background-image:url(\'' + imgUrl + '\');"></div>';
html += '<div class="posterItemText">' + item.Name + '</div>';
html += '<div class="posterItemText">';
2013-04-28 10:21:56 -07:00
if (item.RunTimeTicks != "") {
2013-06-07 10:29:33 -07:00
html += Dashboard.getDisplayTime(item.RunTimeTicks);
2013-04-28 10:21:56 -07:00
}
else {
html += "&nbsp;";
}
html += '</div>';
2013-04-28 10:21:56 -07:00
html += '</a>';
2013-04-28 10:21:56 -07:00
}
2013-05-11 23:05:51 -07:00
if (limit && items.length > limit) {
html += '<p style="margin: .5em 0 0;padding-left: .5em;"><button class="' + moreButtonClass + '" data-inline="true" data-mini="true">More ...</button></p>';
}
2013-04-28 10:21:56 -07:00
return html;
}
2013-05-11 23:05:51 -07:00
function renderSpecials(page, item, limit) {
2013-04-28 10:21:56 -07:00
ApiClient.getSpecialFeatures(Dashboard.getCurrentUserId(), item.Id).done(function (specials) {
2013-05-11 23:05:51 -07:00
$('#specialsContent', page).html(getVideosHtml(specials, limit, "moreSpecials")).trigger('create');
});
2013-04-10 14:14:25 -07:00
}
2013-04-10 14:14:25 -07:00
function renderTrailers(page, item) {
if (item.Type == "Trailer") {
$('#trailerSectionHeader', page).html('More trailers');
} else {
$('#trailerSectionHeader', page).html('Trailers');
}
2013-09-03 14:06:33 -07:00
var remoteTrailersHtml = '';
for (var i = 0, length = item.RemoteTrailers.length; i < length; i++) {
var trailer = item.RemoteTrailers[i];
var id = getParameterByName('v', trailer.Url);
if (id) {
2013-09-03 14:06:33 -07:00
remoteTrailersHtml += '<iframe class="posterItem smallBackdropPosterItem" style="margin:0 3px;width:auto;" src="//www.youtube.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe>';
}
}
var elem = $('#trailersContent', page).html(remoteTrailersHtml);
if (item.LocalTrailerCount) {
ApiClient.getLocalTrailers(Dashboard.getCurrentUserId(), item.Id).done(function (trailers) {
elem.prepend(getVideosHtml(trailers));
});
}
2013-04-10 14:14:25 -07:00
}
2013-03-26 22:20:46 -07:00
2013-05-11 23:05:51 -07:00
function renderCast(page, item, context, limit) {
2013-03-26 22:20:46 -07:00
var html = '';
2013-04-10 14:14:25 -07:00
var casts = item.People || [];
2013-03-26 22:20:46 -07:00
for (var i = 0, length = casts.length; i < length; i++) {
2013-05-11 23:05:51 -07:00
if (limit && i >= limit) {
break;
}
2013-04-22 07:44:11 -07:00
var cast = casts[i];
2013-03-26 22:20:46 -07:00
2013-05-11 23:05:51 -07:00
html += '<a class="tileItem smallPosterTileItem" href="itembynamedetails.html?context=' + context + '&person=' + ApiClient.encodeName(cast.Name) + '">';
var imgUrl;
if (cast.PrimaryImageTag) {
imgUrl = ApiClient.getPersonImageUrl(cast.Name, {
width: 130,
tag: cast.PrimaryImageTag,
type: "primary"
});
} else {
imgUrl = "css/images/items/list/person.png";
}
html += '<div class="tileImage" style="background-image:url(\'' + imgUrl + '\');"></div>';
html += '<div class="tileContent">';
html += '<p>' + cast.Name + '</p>';
var role = cast.Role ? "as " + cast.Role : cast.Type;
if (role == "GuestStar") {
role = "Guest star";
}
2013-05-11 23:05:51 -07:00
role = role || "";
var maxlength = 40;
if (role.length > maxlength) {
role = role.substring(0, maxlength - 3) + '...';
}
html += '<p>' + role + '</p>';
2013-05-11 23:05:51 -07:00
html += '</div>';
html += '</a>';
2013-03-26 22:20:46 -07:00
}
2013-05-11 23:05:51 -07:00
if (limit && casts.length > limit) {
html += '<p style="margin: .5em 0 0;padding-left: .5em;"><button class="morePeople" data-inline="true" data-mini="true">More ...</button></p>';
}
$('#castContent', page).html(html).trigger('create');
2013-04-10 14:14:25 -07:00
}
2013-04-14 08:14:10 -07:00
2013-04-10 14:14:25 -07:00
function play(startPosition) {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
MediaPlayer.play([currentItem], startPosition);
}
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
$(document).on('pageinit', "#itemDetailPage", function () {
2013-03-29 07:12:14 -07:00
2013-04-10 14:14:25 -07:00
var page = this;
2013-04-04 10:27:36 -07:00
2013-04-10 14:14:25 -07:00
$('#btnPlay', page).on('click', function () {
var userdata = currentItem.UserData || {};
2013-08-08 07:53:25 -07:00
var mediaType = currentItem.MediaType;
2013-08-08 07:53:25 -07:00
if (currentItem.Type == "MusicArtist" || currentItem.Type == "MusicAlbum") {
mediaType = "Audio";
}
2013-08-08 07:53:25 -07:00
LibraryBrowser.showPlayMenu(this, currentItem.Id, currentItem.Type, mediaType, userdata.PlaybackPositionTicks);
2013-04-14 08:14:10 -07:00
});
$('#btnPlayExternal', page).on('click', function () {
ApiClient.markPlayed(Dashboard.getCurrentUserId(), currentItem.Id, new Date());
});
$('#btnEdit', page).on('click', function () {
2013-05-22 09:52:22 -07:00
Dashboard.navigate("edititemmetadata.html?id=" + currentItem.Id);
});
2013-05-28 18:45:39 -07:00
$('#btnRemote', page).on('click', function () {
2013-07-11 13:25:12 -07:00
RemoteControl.showMenuForItem({
2013-06-04 09:48:23 -07:00
2013-05-30 12:58:07 -07:00
item: currentItem,
context: getContext(currentItem),
2013-06-04 09:48:23 -07:00
2013-05-30 12:58:07 -07:00
themeSongs: $('#themeSongsCollapsible:visible', page).length > 0,
themeVideos: $('#themeVideosCollapsible:visible', page).length > 0
});
2013-05-28 18:45:39 -07:00
});
2013-04-10 14:14:25 -07:00
}).on('pageshow', "#itemDetailPage", function () {
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
var page = this;
2013-03-28 22:51:45 -07:00
2013-05-11 23:05:51 -07:00
$(page).on("click.moreScenes", ".moreScenes", function () {
renderScenes(page, currentItem);
}).on("click.morePeople", ".morePeople", function () {
renderCast(page, currentItem, getContext(currentItem));
}).on("click.moreSpecials", ".moreSpecials", function () {
renderSpecials(page, currentItem);
}).on("click.moreCriticReviews", ".moreCriticReviews", function () {
renderCriticReviews(page, currentItem);
});
2013-04-10 14:14:25 -07:00
reload(page);
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
}).on('pagehide', "#itemDetailPage", function () {
2013-04-10 14:14:25 -07:00
currentItem = null;
2013-05-11 23:05:51 -07:00
var page = this;
$(page).off("click.moreScenes").off("click.morePeople").off("click.moreSpecials").off("click.moreCriticReviews");
2013-04-10 14:14:25 -07:00
});
2013-04-14 08:14:10 -07:00
2013-04-10 14:14:25 -07:00
function itemDetailPage() {
2013-04-10 14:14:25 -07:00
var self = this;
2013-04-10 14:14:25 -07:00
self.play = play;
2013-04-09 11:38:58 -07:00
}
2013-03-28 22:51:45 -07:00
2013-04-10 14:14:25 -07:00
window.ItemDetailPage = new itemDetailPage();
2013-02-20 18:33:05 -07:00
2013-04-10 14:14:25 -07:00
})(jQuery, document, LibraryBrowser, window);