2016-10-06 11:55:01 -07:00
define ( [ 'libraryBrowser' , 'cardBuilder' , 'appSettings' , 'components/groupedcards' , 'dom' , 'apphost' , 'scrollStyles' , 'emby-button' , 'paper-icon-button-light' , 'emby-itemscontainer' ] , function ( libraryBrowser , cardBuilder , appSettings , groupedcards , dom , appHost ) {
2016-10-22 22:11:46 -07:00
'use strict' ;
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
2016-09-02 08:56:19 -07:00
return result . Items ;
2015-06-12 21:14:48 -07:00
} ) ;
}
function enableScrollX ( ) {
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 ;
switch ( item . CollectionType ) {
case "movies" :
2016-07-23 11:43:07 -07:00
icon = "local_movies" ;
2015-06-12 21:14:48 -07:00
break ;
case "music" :
2016-07-23 11:43:07 -07:00
icon = "library_music" ;
2015-06-12 21:14:48 -07:00
break ;
case "photos" :
2015-08-28 08:02:22 -07:00
icon = "photo" ;
2015-06-12 21:14:48 -07:00
break ;
case "livetv" :
2016-07-23 11:43:07 -07:00
icon = "live_tv" ;
2015-06-12 21:14:48 -07:00
break ;
case "tvshows" :
2016-07-23 11:43:07 -07:00
icon = "live_tv" ;
2015-06-12 21:14:48 -07:00
break ;
case "games" :
2015-08-28 08:02:22 -07:00
icon = "folder" ;
2015-06-12 21:14:48 -07:00
break ;
case "trailers" :
2016-07-23 11:43:07 -07:00
icon = "local_movies" ;
2015-06-12 21:14:48 -07:00
break ;
case "homevideos" :
2016-07-23 11:43:07 -07:00
icon = "video_library" ;
2015-06-12 21:14:48 -07:00
break ;
case "musicvideos" :
2016-07-23 11:43:07 -07:00
icon = "video_library" ;
2015-06-12 21:14:48 -07:00
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
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' ;
}
2016-08-20 14:58:28 -07:00
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
2016-07-30 13:09:07 -07:00
html += '<a' + onclick + ' data-id="' + item . Id + '" class="' + cssClass + '" href="' + href + '" style="min-width:12.5%;">' ;
html += '<div class="cardBox ' + cardBuilder . getDefaultColorClass ( item . Name ) + '" style="margin:4px;">' ;
2015-06-12 21:14:48 -07:00
2016-07-30 13:09:07 -07:00
html += "<div class='cardText'>" ;
2016-07-23 11:43:07 -07:00
html += '<i class="md-icon">' + icon + '</i>' ;
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>' ;
}
2016-07-30 13:09:07 -07:00
html += '<div style="display:flex;flex-wrap:wrap;">' ;
2015-06-12 21:14:48 -07:00
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
2016-06-15 23:20:50 -07:00
if ( ! AppInfo . enableAppLayouts ) {
2016-06-14 13:59:30 -07:00
infos . push ( getUpgradeMobileLayoutsInfo ) ;
}
return infos [ getRandomInt ( 0 , infos . length - 1 ) ] ( ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
2016-06-14 13:59:30 -07:00
function getCard ( img , target , shape ) {
shape = shape || 'backdropCard' ;
2016-08-26 10:24:04 -07:00
var html = '<div class="card scalableCard ' + shape + ' ' + shape + '-scalable"><div class="cardBox"><div class="cardScalable"><div class="cardPadder cardPadder-backdrop"></div>' ;
2016-06-14 13:59:30 -07:00
if ( target ) {
html += '<a class="cardContent" href="' + target + '" target="_blank">' ;
} else {
html += '<div class="cardContent">' ;
}
html += '<div class="cardImage lazy" data-src="' + img + '"></div>' ;
2016-04-17 13:57:57 -07:00
2016-06-14 13:59:30 -07:00
if ( target ) {
html += '</a>' ;
} else {
html += '</div>' ;
}
html += '</div></div></div>' ;
return html ;
2016-04-17 13:57:57 -07:00
}
function getTheaterInfo ( ) {
var html = '' ;
html += '<div>' ;
2016-07-23 11:43:07 -07:00
html += '<h1>Try Emby Theater<button is="paper-icon-button-light" style="margin-left:1em;" onclick="this.parentNode.parentNode.remove();" class="autoSize"><i class="md-icon">close</i></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-07-30 13:09:07 -07:00
html += '<div class="itemsContainer vertical-wrap">' ;
2016-04-17 13:57:57 -07:00
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-07-23 11:43:07 -07:00
html += '<h1>Try Emby Premiere<button is="paper-icon-button-light" style="margin-left:1em;" onclick="this.parentNode.parentNode.remove();" class="autoSize"><i class="md-icon">close</i></button></h1>' ;
2016-05-04 13:50:47 -07:00
2016-06-14 13:59:30 -07:00
var cardTarget = AppInfo . isNativeApp ? '' : 'https://emby.media/premiere' ;
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-07-30 13:09:07 -07:00
html += '<div class="itemsContainer vertical-wrap">' ;
2016-06-14 13:59:30 -07:00
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater1.png' , cardTarget ) ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater2.png' , cardTarget ) ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater3.png' , cardTarget ) ;
html += '</div>' ;
html += '<br/>' ;
html += '</div>' ;
return html ;
}
function getUpgradeMobileLayoutsInfo ( ) {
var html = '' ;
html += '<div>' ;
2016-07-23 11:43:07 -07:00
html += '<h1>Unlock Improved Layouts with Emby Premiere<button is="paper-icon-button-light" style="margin-left:1em;" onclick="this.parentNode.parentNode.remove();" class="autoSize"><i class="md-icon">close</i></button></h1>' ;
2016-06-14 13:59:30 -07:00
var cardTarget = AppInfo . isNativeApp ? '' : 'https://emby.media/premiere' ;
var learnMoreText = AppInfo . isNativeApp ? '' : '<a href="https://emby.media/premiere" target="_blank">Learn more</a>' ;
html += '<p>Combined horizontal and vertical swiping, better detail layouts, and more. ' + learnMoreText + '</p>' ;
2016-07-30 13:09:07 -07:00
html += '<div class="itemsContainer vertical-wrap">' ;
2016-06-14 13:59:30 -07:00
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/ms1.png' , cardTarget , 'portraitCard' ) ;
html += getCard ( 'https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/ms2.png' , cardTarget , 'portraitCard' ) ;
2016-04-17 13:57:57 -07:00
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 ,
2016-08-15 23:13:54 -07:00
Fields : "PrimaryImageAspectRatio,BasicSyncInfo" ,
2015-06-12 21:14:48 -07:00
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>' ;
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2015-06-12 21:14:48 -07:00
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-06-12 21:14:48 -07:00
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 ;
2016-07-23 13:00:56 -07:00
elem . addEventListener ( 'click' , groupedcards . onItemsContainerClick ) ;
2015-06-28 08:43:49 -07:00
ImageLoader . lazyChildren ( 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 ,
2016-08-15 23:13:54 -07:00
Fields : "PrimaryImageAspectRatio,BasicSyncInfo" ,
2015-09-24 22:15:29 -07:00
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 ) {
2016-07-17 11:55:07 -07:00
html += '<div is="emby-itemscontainer" class="hiddenScrollX itemsContainer">' ;
2015-09-24 22:15:29 -07:00
} else {
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2015-09-24 22:15:29 -07:00
}
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-09-24 22:15:29 -07:00
items : items ,
shape : getPortraitShape ( ) ,
showUnplayedIndicator : false ,
showChildCountIndicator : true ,
lazy : true ,
context : 'home' ,
2016-02-01 19:41:14 -07:00
centerText : true ,
2016-09-01 09:36:11 -07:00
overlayPlayButton : true ,
allowBottomPadding : ! enableScrollX ( )
2015-09-24 22:15:29 -07:00
} ) ;
html += '</div>' ;
}
elem . innerHTML = html ;
ImageLoader . lazyChildren ( elem ) ;
} ) ;
}
function loadLatestEpisodes ( elem , user ) {
var options = {
Limit : 12 ,
2016-08-15 23:13:54 -07:00
Fields : "PrimaryImageAspectRatio,BasicSyncInfo" ,
2015-09-24 22:15:29 -07:00
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 ) {
2016-07-17 11:55:07 -07:00
html += '<div is="emby-itemscontainer" class="hiddenScrollX itemsContainer">' ;
2015-09-24 22:15:29 -07:00
} else {
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2015-09-24 22:15:29 -07:00
}
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-09-24 22:15:29 -07:00
items : items ,
preferThumb : true ,
shape : getThumbShape ( ) ,
showUnplayedIndicator : false ,
showChildCountIndicator : true ,
lazy : true ,
2016-02-01 19:41:14 -07:00
context : 'home' ,
2016-09-01 09:36:11 -07:00
overlayPlayButton : true ,
allowBottomPadding : ! enableScrollX ( )
2015-09-24 22:15:29 -07:00
} ) ;
html += '</div>' ;
}
elem . innerHTML = html ;
ImageLoader . lazyChildren ( elem ) ;
} ) ;
}
2015-06-12 21:14:48 -07:00
function loadLatestChannelMedia ( elem , userId ) {
2016-08-20 14:58:28 -07:00
var screenWidth = dom . getWindowSize ( ) . 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 ) ) ) ,
2016-08-15 23:13:54 -07:00
Fields : "PrimaryImageAspectRatio,BasicSyncInfo" ,
2015-06-12 21:14:48 -07:00
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>' ;
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-06-12 21:14:48 -07:00
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 ) ;
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 ) {
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>' ;
2016-09-12 11:10:09 -07:00
var scrollX = enableScrollX ( ) && dom . getWindowSize ( ) . innerWidth >= 600 ;
2015-10-10 17:39:30 -07:00
if ( scrollX ) {
2016-07-29 21:21:03 -07:00
html += '<div is="emby-itemscontainer" class="hiddenScrollX itemsContainer">' ;
2015-10-10 17:39:30 -07:00
} else {
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2015-10-10 17:39:30 -07:00
}
2016-10-06 11:55:01 -07:00
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-06-12 21:14:48 -07:00
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 ,
2016-09-05 13:07:36 -07:00
overlayText : false ,
2015-06-12 21:14:48 -07:00
lazy : true ,
2016-09-01 09:36:11 -07:00
transition : false ,
allowBottomPadding : ! enableScrollX ( )
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-12 21:14:48 -07:00
} ) ;
}
function loadResume ( elem , userId ) {
2016-08-20 14:58:28 -07:00
var screenWidth = dom . getWindowSize ( ) . 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 ,
2016-08-15 23:13:54 -07:00
Fields : "PrimaryImageAspectRatio,BasicSyncInfo" ,
2015-06-12 21:14:48 -07:00
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 ( ) ) {
2016-07-17 11:55:07 -07:00
html += '<div is="emby-itemscontainer" class="hiddenScrollX itemsContainer">' ;
2015-06-12 21:14:48 -07:00
} else {
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2015-06-12 21:14:48 -07:00
}
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-06-12 21:14:48 -07:00
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' ,
2016-09-01 09:36:11 -07:00
centerText : true ,
allowBottomPadding : ! enableScrollX ( )
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 ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
2015-09-24 22:15:29 -07:00
function loadNextUp ( elem , userId ) {
var query = {
Limit : 20 ,
2016-08-15 23:13:54 -07:00
Fields : "PrimaryImageAspectRatio,SeriesInfo,DateCreated,BasicSyncInfo" ,
2015-09-24 22:15:29 -07:00
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 ( ) ) {
2016-07-17 11:55:07 -07:00
html += '<div is="emby-itemscontainer" class="hiddenScrollX itemsContainer">' ;
2015-09-24 22:15:29 -07:00
} else {
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2015-09-24 22:15:29 -07:00
}
2016-10-06 11:55:01 -07:00
var supportsImageAnalysis = appHost . supports ( 'imageanalysis' ) ;
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-09-24 22:15:29 -07:00
items : result . Items ,
preferThumb : true ,
shape : getThumbShape ( ) ,
overlayText : false ,
showTitle : true ,
showParentTitle : true ,
lazy : true ,
overlayPlayButton : true ,
context : 'home' ,
2016-10-13 14:13:30 -07:00
centerText : ! supportsImageAnalysis ,
2016-10-06 11:55:01 -07:00
allowBottomPadding : ! enableScrollX ( ) ,
cardLayout : supportsImageAnalysis ,
2016-10-10 23:46:59 -07:00
vibrant : supportsImageAnalysis
2015-09-24 22:15:29 -07:00
} ) ;
html += '</div>' ;
}
elem . innerHTML = html ;
ImageLoader . lazyChildren ( elem ) ;
} ) ;
}
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-08-20 14:58:28 -07:00
var screenWidth = dom . getWindowSize ( ) . innerWidth ;
2015-06-12 21:14:48 -07:00
var options = {
Limit : screenWidth >= 1600 ? 10 : ( screenWidth >= 1440 ? 5 : ( screenWidth >= 800 ? 6 : 6 ) ) ,
2016-08-15 23:13:54 -07:00
Fields : "PrimaryImageAspectRatio,BasicSyncInfo" ,
2015-06-12 21:14:48 -07:00
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
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-07-20 11:32:55 -07:00
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 ) ;
2015-06-12 21:14:48 -07:00
} ) ;
}
2016-10-10 23:46:59 -07:00
function loadLatestLiveTvRecordings ( elem , userId ) {
2015-06-12 21:14:48 -07:00
return ApiClient . getLiveTvRecordings ( {
userId : userId ,
limit : 5 ,
2016-08-15 23:13:54 -07:00
Fields : "PrimaryImageAspectRatio,BasicSyncInfo" ,
2016-06-20 10:08:13 -07:00
IsInProgress : false ,
EnableTotalRecordCount : false
2015-06-12 21:14:48 -07:00
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 ) {
html += '<div>' ;
2016-10-10 23:46:59 -07:00
html += '<h1 style="display:inline-block; vertical-align:middle;" class="listHeader">' + 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 ( ) ) {
2016-07-17 11:55:07 -07:00
html += '<div is="emby-itemscontainer" class="hiddenScrollX itemsContainer">' ;
2015-09-25 19:31:13 -07:00
} else {
2016-07-29 22:25:07 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap">' ;
2015-09-25 19:31:13 -07:00
}
2016-10-06 11:55:01 -07:00
var supportsImageAnalysis = appHost . supports ( 'imageanalysis' ) ;
2016-07-29 13:06:58 -07:00
html += cardBuilder . getCardsHtml ( {
2015-06-12 21:14:48 -07:00
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-10-11 14:33:38 -07:00
centerText : ! supportsImageAnalysis ,
2016-10-02 23:28:45 -07:00
overlayText : false ,
2016-09-01 09:36:11 -07:00
overlayPlayButton : true ,
2016-10-02 23:28:45 -07:00
allowBottomPadding : ! enableScrollX ( ) ,
2016-10-06 11:55:01 -07:00
preferThumb : true ,
cardLayout : supportsImageAnalysis ,
2016-10-10 23:46:59 -07:00
vibrant : supportsImageAnalysis
2016-09-01 09:36:11 -07:00
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 ) ;
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 ;
} ) ;