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 ) ;
2013-05-14 21:05:52 -07:00
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 ) ;
2013-10-25 08:52:10 -07:00
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 ) ) ;
2013-10-25 08:52:10 -07:00
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-10-17 13:59:46 -07:00
2013-07-29 08:05:09 -07:00
$ ( '#offlineIndicator' , page ) . show ( ) ;
2013-10-17 13:59:46 -07:00
}
else {
2013-07-29 08:05:09 -07:00
$ ( '#offlineIndicator' , page ) . hide ( ) ;
}
2013-10-17 13:59:46 -07:00
var isMissingEpisode = false ;
2013-10-25 08:52:10 -07:00
2013-10-17 13:59:46 -07:00
if ( item . LocationType == "Virtual" && item . Type == "Episode" ) {
try {
2013-10-25 07:18:53 -07:00
if ( item . PremiereDate && ( new Date ( ) . getTime ( ) >= parseISO8601Date ( item . PremiereDate , { toLocal : true } ) . getTime ( ) ) ) {
2013-10-17 13:59:46 -07:00
isMissingEpisode = true ;
}
} catch ( err ) {
}
}
2013-10-25 08:52:10 -07:00
2013-10-17 13:59:46 -07:00
if ( isMissingEpisode ) {
$ ( '#missingIndicator' , page ) . show ( ) ;
}
else {
$ ( '#missingIndicator' , page ) . hide ( ) ;
}
2013-10-16 16:35:11 -07:00
if ( MediaPlayer . canPlay ( item ) && item . LocationType !== "Offline" && item . LocationType !== "Virtual" ) {
2013-10-26 16:19:26 -07:00
var url = MediaPlayer . getPlayUrl ( item ) ;
if ( url ) {
$ ( '#playExternalButtonContainer' , page ) . show ( ) ;
$ ( '#playButtonContainer' , page ) . hide ( ) ;
} else {
$ ( '#playButtonContainer' , page ) . show ( ) ;
$ ( '#playExternalButtonContainer' , page ) . hide ( ) ;
}
2013-10-28 07:56:57 -07:00
2013-10-26 16:19:26 -07:00
$ ( '#btnPlayExternal' , page ) . attr ( 'href' , url || '#' ) ;
2013-04-10 14:14:25 -07:00
} else {
2013-05-04 14:20:27 -07:00
$ ( '#playButtonContainer' , page ) . hide ( ) ;
2013-10-26 16:19:26 -07:00
$ ( '#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' ) ;
2013-04-29 18:49:05 -07:00
2013-10-02 08:32:11 -07:00
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
2013-10-02 08:32:11 -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-03-25 21:44:12 -07:00
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 ( ) ;
}
2013-05-27 18:59:26 -07:00
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 ( ) ;
}
}
2013-10-25 08:52:10 -07:00
function setInitialCollapsibleState ( page , item , context , user ) {
2013-04-14 08:14:10 -07:00
2013-12-03 14:12:20 -07:00
if ( item . IsFolder ) {
2013-05-18 15:48:19 -07:00
$ ( '#childrenCollapsible' , page ) . removeClass ( 'hide' ) ;
2013-10-25 08:52:10 -07:00
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
}
2013-03-25 21:44:12 -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-12-22 14:11:32 -07:00
renderScenes ( page , item , 4 ) ;
2013-03-25 21:44:12 -07:00
}
2013-08-23 19:53:30 -07:00
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-03-26 11:51:52 -07:00
}
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 11:51:52 -07:00
}
2013-03-26 22:20:46 -07:00
if ( ! item . People || ! item . People . length ) {
$ ( '#castCollapsible' , page ) . hide ( ) ;
} else {
$ ( '#castCollapsible' , page ) . show ( ) ;
2013-09-04 10:31:18 -07:00
renderCast ( page , item , context , 8 ) ;
2013-03-26 22:20:46 -07:00
}
2013-04-24 09:03:10 -07:00
2013-06-12 14:46:50 -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 ( ) ;
2013-04-28 11:30:58 -07:00
$ ( '#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 {
2013-07-30 14:02:28 -07:00
$ ( '#musicVideosCollapsible' , page ) . hide ( ) ;
2013-07-29 12:12:21 -07:00
}
2013-05-19 10:35:00 -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-03-25 21:44:12 -07:00
2013-04-23 07:46:27 -07:00
function renderDetails ( page , item , context ) {
2013-02-20 18:33:05 -07:00
2013-05-19 10:35:00 -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 ( ) ;
}
2013-05-14 21:05:52 -07:00
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 ) {
2013-05-14 21:05:52 -07:00
$ ( '.itemCommunityRating' , page ) . html ( LibraryBrowser . getRatingHtml ( item ) ) . show ( ) ;
2013-02-20 18:33:05 -07:00
} else {
2013-05-14 21:05:52 -07:00
$ ( '.itemCommunityRating' , page ) . hide ( ) ;
2013-02-20 18:33:05 -07:00
}
2013-10-25 08:52:10 -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-05-04 14:20:27 -07:00
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
2013-05-14 21:05:52 -07:00
$ ( '.itemMiscInfo' , page ) . html ( LibraryBrowser . getMiscInfoHtml ( item ) ) ;
2013-02-20 18:33:05 -07:00
2013-05-14 21:05:52 -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 ) ;
2013-05-14 21:05:52 -07:00
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 ( ) ;
2013-05-14 21:05:52 -07:00
$ ( '.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
2013-05-19 10:35:00 -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 ( ) ;
}
2013-12-20 13:09:49 -07:00
if ( item . Artists && item . Artists . length && item . Type != "MusicAlbum" ) {
2013-09-05 12:00:50 -07:00
$ ( '#artist' , page ) . show ( ) . html ( getArtistLinksHtml ( item . Artists ) ) . trigger ( 'create' ) ;
2013-05-16 20:24:41 -07:00
} else {
$ ( '#artist' , page ) . hide ( ) ;
}
2013-05-19 10:35:00 -07:00
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
}
2013-10-02 08:32:11 -07:00
2013-09-05 12:00:50 -07:00
function getArtistLinksHtml ( artists ) {
2013-10-02 08:32:11 -07:00
2013-09-05 12:00:50 -07:00
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>' ) ;
2013-09-05 12:00:50 -07:00
}
html = html . join ( ' / ' ) ;
2013-10-02 08:32:11 -07:00
2013-09-05 12:00:50 -07:00
if ( artists . length == 1 ) {
return 'Artist: ' + html ;
}
if ( artists . length > 1 ) {
return 'Artists: ' + 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 ,
shape : item . Type == "MusicAlbum" ? "portrait" : "square"
} ) ;
$ ( '#soundtracksContent' , page ) . html ( html ) ;
} ) ;
}
2013-05-15 15:55:24 -07:00
2013-05-19 10:35:00 -07:00
function renderSiblingLinks ( page , item ) {
$ ( '.lnkSibling' , page ) . addClass ( 'hide' ) ;
if ( ( item . Type != "Episode" && item . Type != "Season" && item . Type != "Audio" ) || item . IndexNumber == null ) {
return ;
}
2013-12-03 21:18:50 -07:00
var promise ;
2013-05-19 10:35:00 -07:00
2013-12-03 21:18:50 -07:00
if ( item . Type == "Season" ) {
2013-05-19 10:35:00 -07:00
2013-12-03 21:18:50 -07:00
promise = ApiClient . getSeasons ( item . SeriesId , {
2013-05-19 10:35:00 -07:00
2013-12-03 21:18:50 -07:00
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 ) {
2013-05-19 10:35:00 -07:00
for ( var i = 0 , length = result . Items . length ; i < length ; i ++ ) {
var curr = result . Items [ i ] ;
if ( curr . IndexNumber == null ) {
continue ;
}
2013-12-03 21:18:50 -07:00
var friendlyTypeName = item . Type == "Audio" ? "song" : item . Type . toLowerCase ( ) ;
2013-05-19 10:35:00 -07:00
if ( curr . IndexNumber < item . IndexNumber ) {
2013-12-03 21:18:50 -07:00
$ ( '.lnkPreviousItem' , page ) . removeClass ( 'hide' ) . attr ( 'href' , 'itemdetails.html?id=' + curr . Id ) . html ( '← Previous ' + friendlyTypeName ) ;
2013-05-19 10:35:00 -07:00
}
else if ( curr . IndexNumber > item . IndexNumber ) {
2013-12-03 21:18:50 -07:00
$ ( '.lnkNextItem' , page ) . removeClass ( 'hide' ) . attr ( 'href' , 'itemdetails.html?id=' + curr . Id ) . html ( 'Next ' + friendlyTypeName + ' →' ) ;
2013-05-19 10:35:00 -07:00
}
}
} ) ;
}
function renderSimilarItems ( page , item ) {
2013-05-15 15:55:24 -07:00
2013-05-25 16:52:41 -07:00
var promise ;
2013-05-15 15:55:24 -07:00
2013-05-25 16:52:41 -07:00
var options = {
userId : Dashboard . getCurrentUserId ( ) ,
2013-12-22 14:11:32 -07:00
limit : item . Type == "MusicAlbum" ? 5 : 5 ,
2013-06-03 19:02:49 -07:00
fields : "PrimaryImageAspectRatio,DateCreated,UserData"
2013-05-25 16:52:41 -07:00
} ;
2013-05-28 13:01:33 -07:00
2013-05-25 16:52:41 -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 ;
}
2013-05-25 16:52:41 -07:00
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-12-29 11:53:56 -07:00
shape : item . Type == "MusicAlbum" ? "square" : "portrait" ,
showParentTitle : item . Type == "MusicAlbum" ,
showTitle : item . Type == "MusicAlbum" || item . Type == "Game" ,
borderless : item . Type == "Game"
2013-05-15 15:55:24 -07:00
} ) ;
$ ( '#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
2013-05-18 10:07:20 -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 ;
}
2013-10-25 08:52:10 -07:00
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-12 14:46:50 -07:00
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>' ;
}
2013-05-14 21:05:52 -07:00
$ ( '.itemTags' , page ) . show ( ) . html ( html ) ;
2013-05-06 20:00:24 -07:00
} else {
2013-05-14 21:05:52 -07:00
$ ( '.itemTags' , page ) . hide ( ) ;
2013-05-06 20:00:24 -07:00
}
2013-04-10 14:14:25 -07:00
}
2013-03-25 21:44:12 -07:00
2013-10-25 08:52:10 -07:00
function renderChildren ( page , item , user ) {
2013-06-12 14:46:50 -07:00
2013-12-29 11:53:56 -07:00
var fields = "ItemCounts,DateCreated,AudioInfo,PrimaryImageAspectRatio" ;
2013-10-25 08:52:10 -07:00
var query = {
2013-08-30 18:08:32 -07:00
ParentId : item . Id ,
2013-12-29 11:53:56 -07:00
Fields : fields
2013-10-25 08:52:10 -07:00
} ;
2014-01-01 20:53:27 -07:00
// Let the server pre-sort boxsets
if ( item . Type !== "BoxSet" ) {
query . SortBy = "SortName" ;
}
2013-04-22 07:44:11 -07:00
2013-11-22 08:33:14 -07:00
var promise ;
2013-11-28 11:27:29 -07:00
if ( item . Type == "Series" ) {
2013-11-22 08:33:14 -07:00
2013-11-28 11:27:29 -07:00
promise = ApiClient . getSeasons ( item . Id , {
2013-11-15 14:31:33 -07:00
2013-12-29 11:53:56 -07:00
userId : user . Id ,
Fields : fields
2013-11-22 08:33:14 -07:00
} ) ;
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
2013-12-03 21:18:50 -07:00
// Use dedicated episodes endpoint
promise = ApiClient . getEpisodes ( item . SeriesId , {
2013-11-28 11:27:29 -07:00
2013-12-03 21:18:50 -07:00
seasonId : item . Id ,
2013-12-29 11:53:56 -07:00
userId : user . Id ,
Fields : fields
2013-12-03 21:18:50 -07:00
} ) ;
2013-10-25 08:52:10 -07:00
}
2013-11-22 08:33:14 -07:00
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
2013-05-14 21:05:52 -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 14:20:27 -07:00
2013-05-04 11:21:29 -07:00
if ( item . Type == "Season" ) {
shape = "smallBackdrop" ;
}
2013-04-28 11:47:19 -07:00
2013-12-29 11:53:56 -07:00
var html ;
if ( item . Type == "Series" || item . Type == "BoxSet" ) {
html = LibraryBrowser . getPosterViewHtml ( {
items : result . Items ,
shape : "portrait" ,
useAverageAspectRatio : true ,
showTitle : true
} ) ;
}
else if ( item . Type == "Season" ) {
html = LibraryBrowser . getPosterViewHtml ( {
items : result . Items ,
shape : "smallBackdrop" ,
useAverageAspectRatio : true ,
showTitle : true ,
displayAsSpecial : item . Type == "Season" && item . IndexNumber
} ) ;
}
else {
html = LibraryBrowser . getPosterDetailViewHtml ( {
items : result . Items ,
useAverageAspectRatio : true ,
shape : shape ,
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" ) {
2013-11-08 08:35:36 -07:00
$ ( '#childrenTitle' , page ) . html ( 'Episodes' ) ;
2013-04-22 07:44:11 -07:00
}
else if ( item . Type == "Series" ) {
2013-11-08 08:35:36 -07:00
$ ( '#childrenTitle' , page ) . html ( 'Seasons' ) ;
2013-04-22 07:44:11 -07:00
}
else if ( item . Type == "BoxSet" ) {
2014-01-03 13:43:44 -07:00
$ ( '#childrenTitle' , page ) . html ( 'Titles' ) ;
2013-04-22 07:44:11 -07:00
}
2013-04-22 08:10:54 -07:00
else if ( item . Type == "MusicAlbum" ) {
2013-11-08 08:35:36 -07:00
$ ( '#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" ) {
2013-11-08 08:35:36 -07:00
$ ( '#childrenTitle' , page ) . html ( 'Games' ) ;
2013-04-28 11:47:19 -07:00
}
2013-04-22 07:44:11 -07:00
else {
2013-11-08 08:35:36 -07:00
$ ( '#childrenTitle' , page ) . html ( 'Items' ) ;
2013-04-22 07:44:11 -07:00
}
}
2013-04-10 14:14:25 -07:00
function renderUserDataIcons ( page , item ) {
2013-05-14 21:05:52 -07:00
$ ( '.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 ) {
2013-05-27 18:59:26 -07:00
if ( item . Type != "Movie" && item . Type != "Trailer" && item . Type != "MusicVideo" ) {
2013-05-19 10:35:00 -07:00
$ ( '#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 ) {
2013-05-14 21:05:52 -07:00
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-13 22:36:36 -07:00
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 {
2013-10-25 07:18:53 -07:00
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 ) {
2013-12-22 14:11:32 -07:00
html += '<p style="margin: 0;padding-left: .5em;"><button class="moreCriticReviews" data-inline="true" data-mini="true">More ...</button></p>' ;
2013-05-11 23:05:51 -07:00
}
$ ( '#criticReviewsContent' , page ) . html ( html ) . trigger ( 'create' ) ;
}
2013-05-19 10:35:00 -07:00
function renderThemeSongs ( page , item ) {
2013-04-24 13:28:42 -07:00
2013-05-19 10:35:00 -07:00
ApiClient . getThemeSongs ( Dashboard . getCurrentUserId ( ) , item . Id ) . done ( function ( result ) {
if ( result . Items . length ) {
2013-04-24 13:28:42 -07:00
2013-05-19 10:35:00 -07:00
$ ( '#themeSongsCollapsible' , page ) . show ( ) ;
$ ( '#themeSongsContent' , page ) . html ( LibraryBrowser . getSongTableHtml ( result . Items , { showArtist : true , showAlbum : true } ) ) . trigger ( 'create' ) ;
2013-05-19 19:45:04 -07:00
} else {
$ ( '#themeSongsCollapsible' , page ) . hide ( ) ;
2013-05-19 10:35:00 -07:00
}
} ) ;
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 ,
2013-09-23 07:26:20 -07:00
Fields : "DateCreated" ,
2013-08-08 05:19:11 -07:00
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 ( ) ;
}
} ) ;
}
2013-05-19 10:35:00 -07:00
function renderThemeVideos ( page , item ) {
2013-04-28 10:21:56 -07:00
2013-05-19 10:35:00 -07:00
ApiClient . getThemeVideos ( Dashboard . getCurrentUserId ( ) , item . Id ) . done ( function ( result ) {
if ( result . Items . length ) {
2013-04-28 10:21:56 -07:00
2013-05-19 10:35:00 -07:00
$ ( '#themeVideosCollapsible' , page ) . show ( ) ;
$ ( '#themeVideosContent' , page ) . html ( getVideosHtml ( result . Items ) ) . trigger ( 'create' ) ;
2013-05-19 19:45:04 -07:00
} else {
$ ( '#themeVideosCollapsible' , page ) . hide ( ) ;
2013-05-19 10:35:00 -07:00
}
} ) ;
2013-04-28 10:21:56 -07:00
}
2013-06-12 14:46:50 -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
2013-03-25 21:44:12 -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 ;
}
2013-03-25 21:44:12 -07:00
var chapter = chapters [ i ] ;
2013-04-10 10:11:23 -07:00
var chapterName = chapter . Name || "Chapter " + i ;
2013-03-25 21:44:12 -07:00
2013-05-03 13:50:13 -07:00
html += '<a class="posterItem smallBackdropPosterItem" href="#play-Chapter-' + i + '" onclick="ItemDetailPage.play(' + chapter . StartPositionTicks + ');">' ;
var imgUrl ;
2013-03-25 21:44:12 -07:00
if ( chapter . ImageTag ) {
2013-05-03 13:50:13 -07:00
imgUrl = ApiClient . getImageUrl ( item . Id , {
2013-11-07 08:57:12 -07:00
maxwidth : 400 ,
2013-03-25 21:44:12 -07:00
tag : chapter . ImageTag ,
type : "Chapter" ,
index : i
} ) ;
} else {
2013-05-03 13:50:13 -07:00
imgUrl = "css/images/items/list/chapter.png" ;
2013-03-25 21:44:12 -07:00
}
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>' ;
2013-12-22 14:11:32 -07:00
html += '<div class="posterItemTextOverlay">' ;
2013-05-03 13:50:13 -07:00
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
2013-12-22 14:11:32 -07:00
html += '</div>' ;
2013-03-25 21:44:12 -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 ) {
2013-12-22 14:11:32 -07:00
html += '<p style="margin: 0;padding-left: .5em;"><button class="moreScenes" data-inline="true" data-mini="true">More ...</button></p>' ;
2013-05-11 23:05:51 -07:00
}
$ ( '#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-03-27 12:23:42 -07:00
}
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
2013-10-13 10:52:57 -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
2013-10-13 10:52:57 -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-03-26 22:36:41 -07:00
}
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 ( ' • ' ) ;
2013-03-26 22:36:41 -07:00
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-03-26 11:51:52 -07:00
2013-05-11 23:05:51 -07:00
function getVideosHtml ( items , limit , moreButtonClass ) {
2013-04-28 10:21:56 -07:00
2013-03-26 11:51:52 -07:00
var html = '' ;
2013-04-28 10:21:56 -07:00
for ( var i = 0 , length = items . length ; i < length ; i ++ ) {
2013-03-26 11:51:52 -07:00
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-03-26 11:51:52 -07:00
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-03-26 11:51:52 -07:00
2013-04-28 10:21:56 -07:00
var imageTags = item . ImageTags || { } ;
2013-03-26 11:51:52 -07:00
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-03-26 11:51:52 -07:00
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-03-26 11:51:52 -07:00
2013-04-28 10:39:16 -07:00
html += '<div class="posterItemImage" style="background-image:url(\'' + imgUrl + '\');"></div>' ;
2013-12-22 14:11:32 -07:00
html += '<div class="posterItemTextOverlay">' ;
2013-04-28 10:39:16 -07:00
html += '<div class="posterItemText">' + item . Name + '</div>' ;
html += '<div class="posterItemText">' ;
2013-03-26 11:51:52 -07:00
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 += " " ;
}
html += '</div>' ;
2013-12-22 14:11:32 -07:00
html += '</div>' ;
2013-03-26 11:51:52 -07:00
2013-04-28 10:21:56 -07:00
html += '</a>' ;
2013-03-26 11:51:52 -07:00
2013-04-28 10:21:56 -07:00
}
2013-03-26 11:51:52 -07:00
2013-05-11 23:05:51 -07:00
if ( limit && items . length > limit ) {
2013-12-22 14:11:32 -07:00
html += '<p style="margin: 0;padding-left: .5em;"><button class="' + moreButtonClass + '" data-inline="true" data-mini="true">More ...</button></p>' ;
2013-05-11 23:05:51 -07:00
}
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-03-26 11:51:52 -07:00
2013-05-11 23:05:51 -07:00
$ ( '#specialsContent' , page ) . html ( getVideosHtml ( specials , limit , "moreSpecials" ) ) . trigger ( 'create' ) ;
2013-03-26 11:51:52 -07:00
} ) ;
2013-04-10 14:14:25 -07:00
}
2013-03-26 11:51:52 -07:00
2013-04-10 14:14:25 -07:00
function renderTrailers ( page , item ) {
2013-03-26 11:51:52 -07:00
2013-08-30 18:08:32 -07:00
if ( item . Type == "Trailer" ) {
$ ( '#trailerSectionHeader' , page ) . html ( 'More trailers' ) ;
} else {
$ ( '#trailerSectionHeader' , page ) . html ( 'Trailers' ) ;
}
2013-09-03 14:06:33 -07:00
2013-08-23 19:53:30 -07:00
var remoteTrailersHtml = '' ;
2013-03-26 11:51:52 -07:00
2013-08-23 19:53:30 -07:00
for ( var i = 0 , length = item . RemoteTrailers . length ; i < length ; i ++ ) {
2013-03-26 11:51:52 -07:00
2013-08-23 19:53:30 -07:00
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>' ;
2013-08-23 19:53:30 -07:00
}
}
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
2013-04-14 13:47:09 -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 ;
2013-05-19 10:35:00 -07:00
2013-05-18 10:07:20 -07:00
if ( role == "GuestStar" ) {
role = "Guest star" ;
}
2013-05-11 23:05:51 -07:00
2013-05-21 18:52:06 -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-23 19:53:30 -07:00
2013-08-08 07:53:25 -07:00
if ( currentItem . Type == "MusicArtist" || currentItem . Type == "MusicAlbum" ) {
mediaType = "Audio" ;
}
2013-08-23 19:53:30 -07:00
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
} ) ;
2013-04-10 22:42:34 -07:00
2013-10-28 07:56:57 -07:00
$ ( '#btnPlayExternal' , page ) . on ( 'click' , function ( ) {
ApiClient . markPlayed ( Dashboard . getCurrentUserId ( ) , currentItem . Id , new Date ( ) ) ;
} ) ;
2013-05-04 14:20:27 -07:00
$ ( '#btnEdit' , page ) . on ( 'click' , function ( ) {
2013-05-22 09:52:22 -07:00
Dashboard . navigate ( "edititemmetadata.html?id=" + currentItem . Id ) ;
2013-05-04 14:20:27 -07:00
} ) ;
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-01 13:26:13 -07:00
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-01 13:26:13 -07:00
2013-04-10 14:14:25 -07:00
var self = this ;
2013-04-01 13:26:13 -07:00
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 ) ;