(function ($, document, LibraryBrowser, window) { var currentItem; function reload(page) { var id = getParameterByName('id'); Dashboard.showLoadingMsg(); ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) { currentItem = item; renderHeader(page, item); LibraryBrowser.renderName(item, $('.itemName', page)); LibraryBrowser.renderParentName(item, $('.parentName', page)); var context = getContext(item); Dashboard.getCurrentUser().done(function (user) { var imageHref = user.Configuration.IsAdministrator ? "edititemimages.html?id=" + item.Id : ""; $('#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(); } }); if (item.LocationType == "Offline") { $('#offlineIndicator', page).show(); } else { $('#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 || '#'); } else { $('#playButtonContainer', page).hide(); $('#playExternalButtonContainer', page).hide(); } $(".autoNumeric").autoNumeric('init'); setPeopleHeader(page, item); if (ApiClient.isWebSocketOpen()) { ApiClient.sendWebSocketMessage("Context", [item.Type, item.Id, item.Name, context].join('|')); } Dashboard.hideLoadingMsg(); }); } 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'); } } function getContext(item) { // should return either movies, tv, music or games if (item.Type == "Episode" || item.Type == "Series" || item.Type == "Season") { return "tv"; } if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "BoxSet") { return "movies"; } if (item.Type == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist" || item.Type == "MusicVideo") { return "music"; } if (item.MediaType == "Game") { return "games"; } return ""; } function renderHeader(page, item) { $('.itemTabs', page).hide(); if (item.Type == "MusicAlbum") { $('#albumTabs', page).show(); } if (item.Type == "MusicVideo") { $('#musicVideoTabs', page).show(); } if (item.Type == "Audio") { $('#songTabs', page).show(); } if (item.Type == "Movie") { $('#movieTabs', page).show(); } if (item.MediaType == "Game") { $('#gameTabs', page).show(); } if (item.Type == "GameSystem") { $('#gameSystemTabs', page).show(); } if (item.Type == "BoxSet") { $('#boxsetTabs', page).show(); } if (item.Type == "Trailer") { $('#trailerTabs', page).show(); } if (item.Type == "Episode" || item.Type == "Season" || item.Type == "Series") { $('#tvShowsTabs', page).show(); } } function setInitialCollapsibleState(page, item, context, user) { if (item.IsFolder) { $('#childrenCollapsible', page).removeClass('hide'); renderChildren(page, item, user); } else { $('#childrenCollapsible', page).addClass('hide'); } if (item.MediaStreams && item.MediaStreams.length) { renderMediaInfo(page, item); } if (!item.Chapters || !item.Chapters.length) { $('#scenesCollapsible', page).hide(); } else { $('#scenesCollapsible', page).show(); renderScenes(page, item, 6); } if (!item.LocalTrailerCount && !item.RemoteTrailers.length) { $('#trailersCollapsible', page).addClass('hide'); } else { $('#trailersCollapsible', page).removeClass('hide'); renderTrailers(page, item); } if (!item.SpecialFeatureCount || item.SpecialFeatureCount == 0 || item.Type == "Series") { $('#specialsCollapsible', page).addClass('hide'); } else { $('#specialsCollapsible', page).removeClass('hide'); renderSpecials(page, item, 6); } if (!item.People || !item.People.length) { $('#castCollapsible', page).hide(); } else { $('#castCollapsible', page).show(); renderCast(page, item, context, 8); } if (!item.PartCount || item.PartCount < 2) { $('#additionalPartsCollapsible', page).addClass('hide'); } else { $('#additionalPartsCollapsible', page).removeClass('hide'); renderAdditionalParts(page, item); } $('#themeSongsCollapsible', page).hide(); $('#themeVideosCollapsible', page).hide(); if (!item.SoundtrackIds || !item.SoundtrackIds.length) { $('#soundtracksCollapsible', page).hide(); } else { $('#soundtracksCollapsible', page).show(); renderSoundtracks(page, item); } if (item.Type == "MusicAlbum") { renderMusicVideos(page, item); } else { $('#musicVideosCollapsible', page).hide(); } renderThemeSongs(page, item); renderThemeVideos(page, item); renderCriticReviews(page, item, 1); } function renderDetails(page, item, context) { renderSimilarItems(page, item); renderSiblingLinks(page, item); if (item.Taglines && item.Taglines.length) { $('#itemTagline', page).html(item.Taglines[0]).show(); } else { $('#itemTagline', page).hide(); } LibraryBrowser.renderOverview($('.itemOverview', page), item); if (item.CommunityRating || item.CriticRating) { $('.itemCommunityRating', page).html(LibraryBrowser.getRatingHtml(item)).show(); } else { $('.itemCommunityRating', page).hide(); } if (item.Type != "Episode" && item.Type != "Movie" && item.Type != "Series") { var premiereDateElem = $('#itemPremiereDate', page).show(); LibraryBrowser.renderPremiereDate(premiereDateElem, item); } else { $('#itemPremiereDate', page).hide(); } LibraryBrowser.renderBudget($('#itemBudget', page), item); LibraryBrowser.renderRevenue($('#itemRevenue', page), item); $('.itemMiscInfo', page).html(LibraryBrowser.getMiscInfoHtml(item)); LibraryBrowser.renderGenres($('.itemGenres', page), item, context); LibraryBrowser.renderStudios($('.itemStudios', page), item, context); renderUserDataIcons(page, item); LibraryBrowser.renderLinks($('.itemExternalLinks', page), item); $('.criticRatingScore', page).html((item.CriticRating || '0') + '%'); if (item.CriticRatingSummary) { $('#criticRatingSummary', page).show(); $('.criticRatingSummaryText', page).html(item.CriticRatingSummary); } else { $('#criticRatingSummary', page).hide(); } renderTags(page, item); renderSeriesAirTime(page, item, context); 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'); } else { $('#artist', page).hide(); } 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'); } } function getArtistLinksHtml(artists) { var html = []; for (var i = 0, length = artists.length; i < length; i++) { var artist = artists[i]; html.push('' + artist + ''); } html = html.join(' / '); if (artists.length == 1) { return 'Artist: ' + html; } if (artists.length > 1) { return 'Artists: ' + html; } return html; } function renderSoundtracks(page, item) { 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(","), ItemFields: "PrimaryImageAspectRatio,ItemCounts,DateCreated,AudioInfo", 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); }); } 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) { var promise; var options = { userId: Dashboard.getCurrentUserId(), limit: item.Type == "MusicAlbum" ? 6 : 6, fields: "PrimaryImageAspectRatio,DateCreated,UserData" }; 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 { $('#similarCollapsible', page).hide(); return; } promise.done(function (result) { 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, useAverageAspectRatio: item.MediaType != "Game", showNewIndicator: true, shape: item.Type == "MusicAlbum" ? "square" : "portrait" }); $('#similarContent', page).html(html); }); } function renderSeriesAirTime(page, item, context) { if (item.Type != "Series") { $('#seriesAirTime', page).hide(); return; } var html = ''; if (item.AirDays && item.AirDays.length) { html += item.AirDays.length == 7 ? 'daily' : item.AirDays.map(function (a) { return a + "s"; }).join(','); } if (item.AirTime) { html += ' at ' + item.AirTime; } if (item.Studios.length) { html += ' on ' + item.Studios[0].Name + ''; } if (html) { html = (item.Status == 'Ended' ? 'Aired ' : 'Airs ') + html; $('#seriesAirTime', page).show().html(html).trigger('create'); } else { $('#seriesAirTime', page).hide(); } } function renderTags(page, item) { if (item.Tags && item.Tags.length) { var html = ''; for (var i = 0, length = item.Tags.length; i < length; i++) { html += '
' + cast.Name + '
'; var role = cast.Role ? "as " + cast.Role : cast.Type; if (role == "GuestStar") { role = "Guest star"; } role = role || ""; var maxlength = 40; if (role.length > maxlength) { role = role.substring(0, maxlength - 3) + '...'; } html += '' + role + '
'; html += '