2016-06-04 20:50:07 -07:00
define ( [ 'libraryBrowser' , 'appSettings' , 'scrollStyles' , 'emby-button' , 'paper-icon-button-light' ] , function ( LibraryBrowser , appSettings ) {
2015-06-12 21:14:48 -07:00
function getUserViews ( userId ) {
2015-12-30 13:25:17 -07:00
return ApiClient . getUserViews ( { } , userId ) . then ( function ( result ) {
2015-06-12 21:14:48 -07:00
var items = result . Items ;
2015-08-28 08:02:22 -07:00
var list = [ ] ;
for ( var i = 0 , length = items . length ; i < length ; i ++ ) {
var view = items [ i ] ;
2015-12-14 08:43:03 -07:00
if ( AppInfo . isNativeApp && browserInfo . safari && view . CollectionType == 'livetv' ) {
continue ;
}
2015-08-28 08:02:22 -07:00
list . push ( view ) ;
}
2015-12-30 13:25:17 -07:00
return list ;
2015-06-12 21:14:48 -07:00
} ) ;
}
function enableScrollX ( ) {
2015-09-24 22:15:29 -07:00
2015-12-14 08:43:03 -07:00
return browserInfo . mobile && AppInfo . enableAppLayouts ;
2015-06-12 21:14:48 -07:00
}
function getThumbShape ( ) {
return enableScrollX ( ) ? 'overflowBackdrop' : 'backdrop' ;
}
2015-09-24 22:15:29 -07:00
function getPortraitShape ( ) {
return enableScrollX ( ) ? 'overflowPortrait' : 'portrait' ;
}
2015-06-12 21:14:48 -07:00
function getLibraryButtonsHtml ( items ) {
var html = "" ;
// "My Library" backgrounds
for ( var i = 0 , length = items . length ; i < length ; i ++ ) {
var item = items [ i ] ;
var icon ;
var backgroundColor = 'rgba(82, 181, 75, 0.9)' ;
switch ( item . CollectionType ) {
case "movies" :
2015-08-28 08:02:22 -07:00
icon = "local-movies" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(176, 94, 81, 0.9)' ;
break ;
case "music" :
2015-08-28 08:02:22 -07:00
icon = "library-music" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(217, 145, 67, 0.9)' ;
break ;
case "photos" :
2015-08-28 08:02:22 -07:00
icon = "photo" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(127, 0, 0, 0.9)' ;
break ;
case "livetv" :
2015-08-28 08:02:22 -07:00
icon = "live-tv" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(217, 145, 67, 0.9)' ;
break ;
case "tvshows" :
2015-08-28 08:02:22 -07:00
icon = "live-tv" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(77, 88, 164, 0.9)' ;
break ;
case "games" :
2015-08-28 08:02:22 -07:00
icon = "folder" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(183, 202, 72, 0.9)' ;
break ;
case "trailers" :
2015-08-28 08:02:22 -07:00
icon = "local-movies" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(176, 94, 81, 0.9)' ;
break ;
case "homevideos" :
2015-08-28 08:02:22 -07:00
icon = "video-library" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(110, 52, 32, 0.9)' ;
break ;
case "musicvideos" :
2015-08-28 08:02:22 -07:00
icon = "video-library" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(143, 54, 168, 0.9)' ;
break ;
case "books" :
2015-08-28 08:02:22 -07:00
icon = "folder" ;
2015-06-12 21:14:48 -07:00
break ;
case "channels" :
2015-08-28 08:02:22 -07:00
icon = "folder" ;
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(51, 136, 204, 0.9)' ;
break ;
case "playlists" :
2015-08-28 08:02:22 -07:00
icon = "folder" ;
2015-06-12 21:14:48 -07:00
break ;
default :
2015-08-28 08:02:22 -07:00
icon = "folder" ;
2015-06-12 21:14:48 -07:00
break ;
}
var cssClass = 'card smallBackdropCard buttonCard' ;
if ( item . CollectionType ) {
cssClass += ' ' + item . CollectionType + 'buttonCard' ;
}
var href = item . url || LibraryBrowser . getHref ( item ) ;
2015-08-28 08:02:22 -07:00
var onclick = item . onclick ? ' onclick="' + item . onclick + '"' : '' ;
icon = item . icon || icon ;
2015-06-12 21:14:48 -07:00
2015-08-28 08:02:22 -07:00
html += '<a' + onclick + ' data-itemid="' + item . Id + '" class="' + cssClass + '" href="' + href + '">' ;
2015-06-12 21:14:48 -07:00
html += '<div class="cardBox" style="background-color:' + backgroundColor + ';margin:4px;border-radius:4px;">' ;
2016-02-11 21:33:14 -07:00
html += "<div class='cardText' style='padding:8px 10px;color:#fff;'>" ;
2015-08-28 08:02:22 -07:00
html += '<iron-icon icon="' + icon + '"></iron-icon>' ;
2015-06-12 21:14:48 -07:00
html += '<span style="margin-left:.7em;">' + item . Name + '</span>' ;
html += "</div>" ;
html += "</div>" ;
html += "</a>" ;
}
return html ;
}
function loadlibraryButtons ( elem , userId , index ) {
2015-12-14 08:43:03 -07:00
return getUserViews ( userId ) . then ( function ( items ) {
2015-06-12 21:14:48 -07:00
var html = '<br/>' ;
if ( index ) {
html += '<h1 class="listHeader">' + Globalize . translate ( 'HeaderMyMedia' ) + '</h1>' ;
}
html += '<div>' ;
html += getLibraryButtonsHtml ( items ) ;
html += '</div>' ;
2016-04-11 21:03:07 -07:00
return getAppInfo ( ) . then ( function ( infoHtml ) {
elem . innerHTML = html + infoHtml ;
} ) ;
} ) ;
}
2016-04-17 13:57:57 -07:00
/ * *
* Returns a random integer between min ( inclusive ) and max ( inclusive )
* Using Math . round ( ) will give you a non - uniform distribution !
* /
function getRandomInt ( min , max ) {
return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
}
2016-04-11 21:03:07 -07:00
function getAppInfo ( ) {
2016-05-04 13:50:47 -07:00
var frequency = 86400000 ;
if ( AppInfo . isNativeApp ) {
2016-05-17 10:44:17 -07:00
frequency = 172800000 ;
2016-04-11 21:03:07 -07:00
}
var cacheKey = 'lastappinfopresent5' ;
2016-05-07 14:01:21 -07:00
var lastDatePresented = parseInt ( appSettings . get ( cacheKey ) || '0' ) ;
// Don't show the first time, right after installation
if ( ! lastDatePresented ) {
appSettings . set ( cacheKey , new Date ( ) . getTime ( ) ) ;
return Promise . resolve ( '' ) ;
}
if ( ( new Date ( ) . getTime ( ) - lastDatePresented ) < frequency ) {
2016-04-11 21:03:07 -07:00
return Promise . resolve ( '' ) ;
}
return Dashboard . getPluginSecurityInfo ( ) . then ( function ( pluginSecurityInfo ) {
appSettings . set ( cacheKey , new Date ( ) . getTime ( ) ) ;
if ( pluginSecurityInfo . IsMBSupporter ) {
return '' ;
}
2016-05-04 13:50:47 -07:00
var infos = [ getPremiereInfo ] ;
if ( ! browserInfo . safari || ! AppInfo . isNativeApp ) {
infos . push ( getTheaterInfo ) ;
}
2016-04-11 21:03:07 -07:00
appSettings . set ( cacheKey , new Date ( ) . getTime ( ) ) ;
2016-04-17 13:57:57 -07:00
return infos [ getRandomInt ( 0 , 1 ) ] ( ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
2016-04-17 13:57:57 -07:00
function getCard ( img , target ) {
return '<div class="card backdropCard"><div class="cardBox"><div class="cardScalable"><div class="cardPadder"></div><a class="cardContent" href="' + target + '" target="_blank"><div class="cardImage lazy" data-src="' + img + '"></div></a></div></div></div>' ;
}
function getTheaterInfo ( ) {
var html = '' ;
html += '<div>' ;
2016-06-07 22:24:25 -07:00
html += '<h1>Try Emby Theater<button is="paper-icon-button-light" style="margin-left:1em;" onclick="this.parentNode.parentNode.remove();"><iron-icon icon="close"></iron-icon></button></h1>' ;
2016-05-04 13:50:47 -07:00
var nameText = AppInfo . isNativeApp ? 'Emby Theater' : '<a href="https://emby.media/download" target="_blank">Emby Theater</a>' ;
html += '<p>A beautiful app for your TV and large screen tablet. ' + nameText + ' runs on Windows, Xbox One, Google Chrome, FireFox, Microsoft Edge and Opera.</p>' ;
2016-04-17 13:57:57 -07:00
html += '<div class="itemsContainer">' ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater1.png' , 'https://emby.media/download' ) ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater2.png' , 'https://emby.media/download' ) ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater3.png' , 'https://emby.media/download' ) ;
html += '</div>' ;
html += '<br/>' ;
html += '</div>' ;
return html ;
}
function getPremiereInfo ( ) {
var html = '' ;
html += '<div>' ;
2016-06-07 22:24:25 -07:00
html += '<h1>Try Emby Premiere<button is="paper-icon-button-light" style="margin-left:1em;" onclick="this.parentNode.parentNode.remove();"><iron-icon icon="close"></iron-icon></button></h1>' ;
2016-05-04 13:50:47 -07:00
var learnMoreText = AppInfo . isNativeApp ? '' : '<a href="https://emby.media/premiere" target="_blank">Learn more</a>' ;
html += '<p>Design beautiful Cover Art, enjoy free access to Emby apps, and more. ' + learnMoreText + '</p>' ;
2016-04-17 13:57:57 -07:00
html += '<div class="itemsContainer">' ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater1.png' , 'https://emby.media/premiere' ) ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater2.png' , 'https://emby.media/premiere' ) ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater3.png' , 'https://emby.media/premiere' ) ;
html += '</div>' ;
html += '<br/>' ;
html += '</div>' ;
return html ;
}
2015-07-26 22:03:34 -07:00
function loadRecentlyAdded ( elem , user ) {
2015-06-12 21:14:48 -07:00
var options = {
2016-05-16 10:11:49 -07:00
Limit : 20 ,
2015-06-12 21:14:48 -07:00
Fields : "PrimaryImageAspectRatio,SyncInfo" ,
ImageTypeLimit : 1 ,
2015-09-24 22:15:29 -07:00
EnableImageTypes : "Primary,Backdrop,Thumb"
2015-06-12 21:14:48 -07:00
} ;
2015-12-14 08:43:03 -07:00
return ApiClient . getJSON ( ApiClient . getUrl ( 'Users/' + user . Id + '/Items/Latest' , options ) ) . then ( function ( items ) {
2015-06-12 21:14:48 -07:00
var html = '' ;
var cardLayout = false ;
if ( items . length ) {
html += '<div>' ;
2015-07-08 09:10:34 -07:00
html += '<h1 class="listHeader">' + Globalize . translate ( 'HeaderLatestMedia' ) + '</h1>' ;
2015-06-12 21:14:48 -07:00
html += '</div>' ;
html += '<div class="itemsContainer">' ;
html += LibraryBrowser . getPosterViewHtml ( {
items : items ,
preferThumb : true ,
shape : 'backdrop' ,
showUnplayedIndicator : false ,
showChildCountIndicator : true ,
lazy : true ,
cardLayout : cardLayout ,
showTitle : cardLayout ,
showYear : cardLayout ,
2015-07-27 09:21:18 -07:00
showDetailsMenu : true ,
context : 'home'
2015-06-12 21:14:48 -07:00
} ) ;
html += '</div>' ;
}
2015-06-28 07:45:21 -07:00
elem . innerHTML = html ;
2015-06-28 08:43:49 -07:00
ImageLoader . lazyChildren ( elem ) ;
2016-03-15 22:33:31 -07:00
LibraryBrowser . createCardMenus ( elem ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
2015-09-24 22:15:29 -07:00
function loadLatestMovies ( elem , user ) {
var options = {
Limit : 12 ,
Fields : "PrimaryImageAspectRatio,SyncInfo" ,
ImageTypeLimit : 1 ,
EnableImageTypes : "Primary,Backdrop,Thumb" ,
IncludeItemTypes : "Movie"
} ;
2015-12-14 08:43:03 -07:00
return ApiClient . getJSON ( ApiClient . getUrl ( 'Users/' + user . Id + '/Items/Latest' , options ) ) . then ( function ( items ) {
2015-09-24 22:15:29 -07:00
var html = '' ;
var scrollX = enableScrollX ( ) ;
if ( items . length ) {
html += '<h1 class="listHeader">' + Globalize . translate ( 'HeaderLatestMovies' ) + '</h1>' ;
if ( scrollX ) {
html += '<div class="hiddenScrollX itemsContainer">' ;
} else {
html += '<div class="itemsContainer">' ;
}
html += LibraryBrowser . getPosterViewHtml ( {
items : items ,
shape : getPortraitShape ( ) ,
showUnplayedIndicator : false ,
showChildCountIndicator : true ,
lazy : true ,
context : 'home' ,
2016-02-01 19:41:14 -07:00
centerText : true ,
overlayPlayButton : true
2015-09-24 22:15:29 -07:00
} ) ;
html += '</div>' ;
}
elem . innerHTML = html ;
ImageLoader . lazyChildren ( elem ) ;
2016-03-15 22:33:31 -07:00
LibraryBrowser . createCardMenus ( elem ) ;
2015-09-24 22:15:29 -07:00
} ) ;
}
function loadLatestEpisodes ( elem , user ) {
var options = {
Limit : 12 ,
Fields : "PrimaryImageAspectRatio,SyncInfo" ,
ImageTypeLimit : 1 ,
EnableImageTypes : "Primary,Backdrop,Thumb" ,
IncludeItemTypes : "Episode"
} ;
2015-12-14 08:43:03 -07:00
return ApiClient . getJSON ( ApiClient . getUrl ( 'Users/' + user . Id + '/Items/Latest' , options ) ) . then ( function ( items ) {
2015-09-24 22:15:29 -07:00
var html = '' ;
var scrollX = enableScrollX ( ) ;
if ( items . length ) {
html += '<h1 class="listHeader">' + Globalize . translate ( 'HeaderLatestEpisodes' ) + '</h1>' ;
if ( scrollX ) {
html += '<div class="hiddenScrollX itemsContainer">' ;
} else {
html += '<div class="itemsContainer">' ;
}
html += LibraryBrowser . getPosterViewHtml ( {
items : items ,
preferThumb : true ,
shape : getThumbShape ( ) ,
showUnplayedIndicator : false ,
showChildCountIndicator : true ,
lazy : true ,
2016-02-01 19:41:14 -07:00
context : 'home' ,
overlayPlayButton : true
2015-09-24 22:15:29 -07:00
} ) ;
html += '</div>' ;
}
elem . innerHTML = html ;
ImageLoader . lazyChildren ( elem ) ;
2016-03-15 22:33:31 -07:00
LibraryBrowser . createCardMenus ( elem ) ;
2015-09-24 22:15:29 -07:00
} ) ;
}
2015-06-12 21:14:48 -07:00
function loadLatestChannelMedia ( elem , userId ) {
2016-05-28 14:48:34 -07:00
var screenWidth = window . innerWidth ;
2015-06-12 21:14:48 -07:00
var options = {
Limit : screenWidth >= 2400 ? 10 : ( screenWidth >= 1600 ? 10 : ( screenWidth >= 1440 ? 8 : ( screenWidth >= 800 ? 7 : 6 ) ) ) ,
Fields : "PrimaryImageAspectRatio,SyncInfo" ,
Filters : "IsUnplayed" ,
UserId : userId
} ;
2015-12-14 08:43:03 -07:00
return ApiClient . getJSON ( ApiClient . getUrl ( "Channels/Items/Latest" , options ) ) . then ( function ( result ) {
2015-06-12 21:14:48 -07:00
var html = '' ;
if ( result . Items . length ) {
html += '<h1 class="listHeader">' + Globalize . translate ( 'HeaderLatestChannelMedia' ) + '</h1>' ;
html += '<div class="itemsContainer">' ;
html += LibraryBrowser . getPosterViewHtml ( {
items : result . Items ,
shape : 'auto' ,
showTitle : true ,
centerText : true ,
lazy : true ,
2016-02-01 19:41:14 -07:00
showDetailsMenu : true ,
overlayPlayButton : true
2015-06-12 21:14:48 -07:00
} ) ;
html += '</div>' ;
}
2015-06-28 07:45:21 -07:00
elem . innerHTML = html ;
2015-06-28 08:43:49 -07:00
ImageLoader . lazyChildren ( elem ) ;
2016-03-15 22:33:31 -07:00
LibraryBrowser . createCardMenus ( elem ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
function loadLibraryTiles ( elem , user , shape , index , autoHideOnMobile , showTitles ) {
2015-12-14 08:43:03 -07:00
return getUserViews ( user . Id ) . then ( function ( items ) {
2015-06-12 21:14:48 -07:00
var html = '' ;
if ( autoHideOnMobile ) {
html += '<div class="hiddenSectionOnMobile">' ;
} else {
html += '<div>' ;
}
if ( items . length ) {
2016-05-28 14:48:34 -07:00
var screenWidth = window . innerWidth ;
2015-06-12 21:14:48 -07:00
html += '<div>' ;
2015-10-10 17:39:30 -07:00
html += '<h1 class="listHeader">' + Globalize . translate ( 'HeaderMyMedia' ) + '</h1>' ;
2015-06-12 21:14:48 -07:00
html += '</div>' ;
2015-12-14 08:43:03 -07:00
var scrollX = enableScrollX ( ) && browserInfo . safari && screenWidth > 800 ;
2015-10-10 17:39:30 -07:00
if ( scrollX ) {
html += '<div class="hiddenScrollX itemsContainer homeTopViews">' ;
} else {
html += '<div class="itemsContainer homeTopViews">' ;
}
2015-06-12 21:14:48 -07:00
html += LibraryBrowser . getPosterViewHtml ( {
items : items ,
2015-10-10 17:39:30 -07:00
shape : scrollX ? 'overflowBackdrop' : shape ,
2015-06-12 21:14:48 -07:00
showTitle : showTitles ,
centerText : true ,
lazy : true ,
2015-06-17 18:41:22 -07:00
autoThumb : true ,
transition : false
2015-06-12 21:14:48 -07:00
} ) ;
html += '</div>' ;
}
html += '</div>' ;
if ( autoHideOnMobile ) {
html += '<div class="hiddenSectionOnNonMobile" style="margin-top:1em;">' ;
html += getLibraryButtonsHtml ( items ) ;
html += '</div>' ;
}
2016-04-11 21:03:07 -07:00
return getAppInfo ( ) . then ( function ( infoHtml ) {
elem . innerHTML = html + infoHtml ;
ImageLoader . lazyChildren ( elem ) ;
2015-06-28 08:43:49 -07:00
2016-04-11 21:03:07 -07:00
LibraryBrowser . createCardMenus ( elem , { showDetailsMenu : false } ) ;
} ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
function loadResume ( elem , userId ) {
2016-05-28 14:48:34 -07:00
var screenWidth = window . innerWidth ;
2015-06-12 21:14:48 -07:00
var options = {
SortBy : "DatePlayed" ,
SortOrder : "Descending" ,
MediaTypes : "Video" ,
Filters : "IsResumable" ,
2016-03-08 11:47:36 -07:00
Limit : screenWidth >= 1920 ? 8 : ( screenWidth >= 1600 ? 8 : ( screenWidth >= 1200 ? 9 : 6 ) ) ,
2015-06-12 21:14:48 -07:00
Recursive : true ,
Fields : "PrimaryImageAspectRatio,SyncInfo" ,
CollapseBoxSetItems : false ,
ExcludeLocationTypes : "Virtual" ,
ImageTypeLimit : 1 ,
2016-05-08 20:13:38 -07:00
EnableImageTypes : "Primary,Backdrop,Banner,Thumb" ,
2016-05-19 10:27:39 -07:00
EnableTotalRecordCount : false
2015-06-12 21:14:48 -07:00
} ;
2015-12-14 08:43:03 -07:00
return ApiClient . getItems ( userId , options ) . then ( function ( result ) {
2015-06-12 21:14:48 -07:00
var html = '' ;
if ( result . Items . length ) {
html += '<h1 class="listHeader">' + Globalize . translate ( 'HeaderResume' ) + '</h1>' ;
if ( enableScrollX ( ) ) {
2015-07-13 14:26:11 -07:00
html += '<div class="hiddenScrollX itemsContainer">' ;
2015-06-12 21:14:48 -07:00
} else {
html += '<div class="itemsContainer">' ;
}
html += LibraryBrowser . getPosterViewHtml ( {
items : result . Items ,
preferThumb : true ,
shape : getThumbShape ( ) ,
2015-09-23 09:16:06 -07:00
overlayText : false ,
2015-06-12 21:14:48 -07:00
showTitle : true ,
showParentTitle : true ,
lazy : true ,
2015-07-17 15:32:00 -07:00
showDetailsMenu : true ,
2015-07-27 09:21:18 -07:00
overlayPlayButton : true ,
2015-09-23 09:16:06 -07:00
context : 'home' ,
centerText : true
2015-06-12 21:14:48 -07:00
} ) ;
html += '</div>' ;
}
2015-06-28 07:45:21 -07:00
elem . innerHTML = html ;
2015-06-28 08:43:49 -07:00
ImageLoader . lazyChildren ( elem ) ;
2016-03-15 22:33:31 -07:00
LibraryBrowser . createCardMenus ( elem ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
2015-09-24 22:15:29 -07:00
function loadNextUp ( elem , userId ) {
var query = {
Limit : 20 ,
Fields : "PrimaryImageAspectRatio,SeriesInfo,DateCreated,SyncInfo" ,
UserId : userId ,
ImageTypeLimit : 1 ,
EnableImageTypes : "Primary,Backdrop,Banner,Thumb"
} ;
2015-12-14 08:43:03 -07:00
ApiClient . getNextUpEpisodes ( query ) . then ( function ( result ) {
2015-09-24 22:15:29 -07:00
var html = '' ;
if ( result . Items . length ) {
html += '<h1 class="listHeader">' + Globalize . translate ( 'HeaderNextUp' ) + '</h1>' ;
if ( enableScrollX ( ) ) {
html += '<div class="hiddenScrollX itemsContainer">' ;
} else {
html += '<div class="itemsContainer">' ;
}
html += LibraryBrowser . getPosterViewHtml ( {
items : result . Items ,
preferThumb : true ,
shape : getThumbShape ( ) ,
overlayText : false ,
showTitle : true ,
showParentTitle : true ,
lazy : true ,
overlayPlayButton : true ,
context : 'home' ,
centerText : true
} ) ;
html += '</div>' ;
}
elem . innerHTML = html ;
ImageLoader . lazyChildren ( elem ) ;
2016-03-15 22:33:31 -07:00
LibraryBrowser . createCardMenus ( elem ) ;
2015-09-24 22:15:29 -07:00
} ) ;
}
2015-06-12 21:14:48 -07:00
function loadLatestChannelItems ( elem , userId , options ) {
2016-05-28 14:48:34 -07:00
options = Object . assign ( options || { } , {
2015-06-12 21:14:48 -07:00
UserId : userId ,
SupportsLatestItems : true
} ) ;
2015-12-14 08:43:03 -07:00
return ApiClient . getJSON ( ApiClient . getUrl ( "Channels" , options ) ) . then ( function ( result ) {
2015-06-12 21:14:48 -07:00
var channels = result . Items ;
var channelsHtml = channels . map ( function ( c ) {
return '<div id="channel' + c . Id + '"></div>' ;
} ) . join ( '' ) ;
2015-06-28 07:45:21 -07:00
elem . innerHTML = channelsHtml ;
2015-06-12 21:14:48 -07:00
for ( var i = 0 , length = channels . length ; i < length ; i ++ ) {
var channel = channels [ i ] ;
loadLatestChannelItemsFromChannel ( elem , channel , i ) ;
}
} ) ;
}
function loadLatestChannelItemsFromChannel ( page , channel , index ) {
2016-05-28 14:48:34 -07:00
var screenWidth = window . innerWidth ;
2015-06-12 21:14:48 -07:00
var options = {
Limit : screenWidth >= 1600 ? 10 : ( screenWidth >= 1440 ? 5 : ( screenWidth >= 800 ? 6 : 6 ) ) ,
Fields : "PrimaryImageAspectRatio,SyncInfo" ,
Filters : "IsUnplayed" ,
UserId : Dashboard . getCurrentUserId ( ) ,
ChannelIds : channel . Id
} ;
2015-12-14 08:43:03 -07:00
ApiClient . getJSON ( ApiClient . getUrl ( "Channels/Items/Latest" , options ) ) . then ( function ( result ) {
2015-06-12 21:14:48 -07:00
var html = '' ;
if ( result . Items . length ) {
2015-07-20 11:32:55 -07:00
html += '<div class="homePageSection">' ;
2015-06-12 21:14:48 -07:00
html += '<div>' ;
var text = Globalize . translate ( 'HeaderLatestFromChannel' ) . replace ( '{0}' , channel . Name ) ;
2015-07-20 11:32:55 -07:00
html += '<h1 style="display:inline-block; vertical-align:middle;" class="listHeader">' + text + '</h1>' ;
2016-06-04 20:50:07 -07:00
html += '<a href="channelitems.html?id=' + channel . Id + '" class="clearLink" style="margin-left:2em;"><button is="emby-button" type="button" class="raised more mini"><span>' + Globalize . translate ( 'ButtonMore' ) + '</span></button></a>' ;
2015-06-12 21:14:48 -07:00
html += '</div>' ;
2015-07-20 11:32:55 -07:00
html += '<div class="itemsContainer">' ;
html += LibraryBrowser . getPosterViewHtml ( {
items : result . Items ,
shape : 'autohome' ,
defaultShape : 'square' ,
showTitle : true ,
centerText : true ,
lazy : true ,
2015-07-24 08:20:11 -07:00
showDetailsMenu : true ,
overlayPlayButton : true
2015-07-20 11:32:55 -07:00
} ) ;
html += '</div>' ;
html += '</div>' ;
2015-06-12 21:14:48 -07:00
}
2015-06-28 07:45:21 -07:00
var elem = page . querySelector ( '#channel' + channel . Id + '' ) ;
elem . innerHTML = html ;
2015-06-28 08:43:49 -07:00
ImageLoader . lazyChildren ( elem ) ;
2016-03-15 22:33:31 -07:00
LibraryBrowser . createCardMenus ( elem ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
function loadLatestLiveTvRecordings ( elem , userId , index ) {
return ApiClient . getLiveTvRecordings ( {
userId : userId ,
limit : 5 ,
2016-05-19 10:27:39 -07:00
Fields : "PrimaryImageAspectRatio,SyncInfo" ,
2015-06-12 21:14:48 -07:00
IsInProgress : false
2015-12-14 08:43:03 -07:00
} ) . then ( function ( result ) {
2015-06-12 21:14:48 -07:00
var html = '' ;
if ( result . Items . length ) {
2015-06-15 21:52:01 -07:00
var cssClass = index !== 0 ? 'listHeader' : 'listHeader' ;
2015-06-12 21:14:48 -07:00
html += '<div>' ;
html += '<h1 style="display:inline-block; vertical-align:middle;" class="' + cssClass + '">' + Globalize . translate ( 'HeaderLatestTvRecordings' ) + '</h1>' ;
2016-06-04 20:50:07 -07:00
html += '<a href="livetv.html?tab=3" onclick="LibraryBrowser.showTab(\'livetv.html\',3);" class="clearLink" style="margin-left:2em;"><button is="emby-button" type="button" class="raised more mini"><span>' + Globalize . translate ( 'ButtonMore' ) + '</span></button></a>' ;
2015-06-12 21:14:48 -07:00
html += '</div>' ;
}
2015-09-25 19:31:13 -07:00
if ( enableScrollX ( ) ) {
html += '<div class="hiddenScrollX itemsContainer">' ;
} else {
html += '<div class="itemsContainer">' ;
}
2015-06-12 21:14:48 -07:00
html += LibraryBrowser . getPosterViewHtml ( {
items : result . Items ,
2016-05-19 22:36:57 -07:00
shape : enableScrollX ( ) ? 'autooverflow' : 'auto' ,
2015-06-12 21:14:48 -07:00
showTitle : true ,
showParentTitle : true ,
coverImage : true ,
lazy : true ,
2015-08-22 08:54:29 -07:00
showDetailsMenu : true ,
2016-02-12 13:26:03 -07:00
centerText : true ,
overlayPlayButton : true
2015-06-12 21:14:48 -07:00
} ) ;
2015-09-25 19:31:13 -07:00
html += '</div>' ;
2015-06-12 21:14:48 -07:00
2015-06-28 07:45:21 -07:00
elem . innerHTML = html ;
2015-06-28 08:43:49 -07:00
ImageLoader . lazyChildren ( elem ) ;
2016-03-15 22:33:31 -07:00
LibraryBrowser . createCardMenus ( elem ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
window . Sections = {
loadRecentlyAdded : loadRecentlyAdded ,
loadLatestChannelMedia : loadLatestChannelMedia ,
loadLibraryTiles : loadLibraryTiles ,
loadResume : loadResume ,
2015-09-24 22:15:29 -07:00
loadNextUp : loadNextUp ,
2015-06-12 21:14:48 -07:00
loadLatestChannelItems : loadLatestChannelItems ,
loadLatestLiveTvRecordings : loadLatestLiveTvRecordings ,
2015-09-24 22:15:29 -07:00
loadlibraryButtons : loadlibraryButtons ,
loadLatestMovies : loadLatestMovies ,
loadLatestEpisodes : loadLatestEpisodes
2015-06-12 21:14:48 -07:00
} ;
2016-03-15 22:33:31 -07:00
return window . Sections ;
} ) ;