2014-03-17 07:48:16 -07:00
( function ( $ , document , window ) {
var showOverlayTimeout ;
function onHoverOut ( ) {
if ( showOverlayTimeout ) {
clearTimeout ( showOverlayTimeout ) ;
showOverlayTimeout = null ;
}
$ ( '.posterItemOverlayTarget:visible' , this ) . each ( function ( ) {
var elem = this ;
$ ( this ) . animate ( { "height" : "0" } , "fast" , function ( ) {
$ ( elem ) . hide ( ) ;
} ) ;
} ) ;
$ ( '.posterItemOverlayTarget:visible' , this ) . stop ( ) . animate ( { "height" : "0" } , function ( ) {
$ ( this ) . hide ( ) ;
} ) ;
}
function getOverlayHtml ( item , currentUser , posterItem ) {
var html = '' ;
html += '<div class="posterItemOverlayInner">' ;
var isSmallItem = $ ( posterItem ) . hasClass ( 'smallBackdropPosterItem' ) ;
var isPortrait = $ ( posterItem ) . hasClass ( 'portraitPosterItem' ) ;
var isSquare = $ ( posterItem ) . hasClass ( 'squarePosterItem' ) ;
var parentName = isSmallItem || isPortrait ? null : item . SeriesName ;
var name = LibraryBrowser . getPosterViewDisplayName ( item , true ) ;
html += '<div style="font-weight:bold;margin-bottom:1em;">' ;
var logoHeight = isSmallItem ? 20 : 26 ;
var maxLogoWidth = isPortrait ? 100 : 200 ;
var imgUrl ;
if ( parentName && item . ParentLogoItemId ) {
imgUrl = ApiClient . getImageUrl ( item . ParentLogoItemId , {
height : logoHeight * 2 ,
type : 'logo' ,
tag : item . ParentLogoImageTag
} ) ;
html += '<img src="' + imgUrl + '" style="max-height:' + logoHeight + 'px;max-width:' + maxLogoWidth + 'px;" />' ;
}
else if ( item . ImageTags . Logo ) {
imgUrl = LibraryBrowser . getImageUrl ( item , 'Logo' , 0 , {
height : logoHeight * 2 ,
} ) ;
html += '<img src="' + imgUrl + '" style="max-height:' + logoHeight + 'px;max-width:' + maxLogoWidth + 'px;" />' ;
}
else {
html += parentName || name ;
}
html += '</div>' ;
if ( parentName ) {
html += '<p>' ;
html += name ;
html += '</p>' ;
} else if ( ! isSmallItem ) {
html += '<p class="itemMiscInfo" style="white-space:nowrap;">' ;
html += LibraryBrowser . getMiscInfoHtml ( item ) ;
html += '</p>' ;
}
html += '<div style="margin:1.25em 0;">' ;
html += '<span class="itemCommunityRating">' ;
html += LibraryBrowser . getRatingHtml ( item , false ) ;
html += '</span>' ;
if ( isPortrait ) {
html += '<span class="userDataIcons" style="display:block;margin:1.25em 0;">' ;
html += LibraryBrowser . getUserDataIconsHtml ( item ) ;
html += '</span>' ;
} else {
html += '<span class="userDataIcons">' ;
html += LibraryBrowser . getUserDataIconsHtml ( item ) ;
html += '</span>' ;
}
html += '</div>' ;
html += '<div>' ;
var buttonMargin = isPortrait || isSquare ? "margin:0 4px 0 0;" : "margin:0 10px 0 0;" ;
var buttonCount = 0 ;
2014-03-29 08:40:32 -07:00
if ( MediaController . canPlay ( item ) ) {
2014-03-17 07:48:16 -07:00
var resumePosition = ( item . UserData || { } ) . PlaybackPositionTicks || 0 ;
2014-03-29 08:40:32 -07:00
var onPlayClick = 'LibraryBrowser.showPlayMenu(this, \'' + item . Id + '\', \'' + item . Type + '\', ' + item . IsFolder + ', \'' + item . MediaType + '\', ' + resumePosition + ');return false;' ;
2014-03-17 07:48:16 -07:00
html += '<button type="button" data-mini="true" data-inline="true" data-icon="play" data-iconpos="notext" title="Play" onclick="' + onPlayClick + '" style="' + buttonMargin + '">Play</button>' ;
buttonCount ++ ;
if ( item . MediaType == "Audio" || item . Type == "MusicAlbum" ) {
2014-03-29 08:40:32 -07:00
html += '<button type="button" data-mini="true" data-inline="true" data-icon="plus" data-iconpos="notext" title="Queue" onclick="MediaController.queue(\'' + item . Id + '\');return false;" style="' + buttonMargin + '">Queue</button>' ;
2014-03-17 07:48:16 -07:00
buttonCount ++ ;
}
}
if ( item . LocalTrailerCount && item . PlayAccess == 'Full' ) {
html += '<button type="button" data-mini="true" data-inline="true" data-icon="video" data-iconpos="notext" class="btnPlayTrailer" data-itemid="' + item . Id + '" title="Play Trailer" style="' + buttonMargin + '">Play Trailer</button>' ;
buttonCount ++ ;
}
if ( currentUser . Configuration . IsAdministrator && item . Type != "Recording" && item . Type != "Program" ) {
html += '<button type="button" data-mini="true" data-inline="true" data-icon="edit" data-iconpos="notext" title="Edit" onclick="Dashboard.navigate(\'edititemmetadata.html?id=' + item . Id + '\');return false;" style="' + buttonMargin + '">Edit</button>' ;
buttonCount ++ ;
}
html += '</div>' ;
html += '</div>' ;
return html ;
}
function onTrailerButtonClick ( ) {
var id = this . getAttribute ( 'data-itemid' ) ;
ApiClient . getLocalTrailers ( Dashboard . getCurrentUserId ( ) , id ) . done ( function ( trailers ) {
2014-03-29 08:40:32 -07:00
MediaController . play ( { items : trailers } ) ;
2014-03-17 07:48:16 -07:00
} ) ;
return false ;
}
function onMenuCommand ( command , elem ) {
var id = elem . getAttribute ( 'data-itemid' ) ;
2014-03-18 18:35:40 -07:00
var page = $ ( elem ) . parents ( '.page' ) ;
if ( command == 'SplitVersions' ) {
splitVersions ( id , page ) ;
}
}
function splitVersions ( id , page ) {
2014-03-22 09:16:43 -07:00
Dashboard . confirm ( "Are you sure you wish to split the media sources into separate items?" , "Split Media Apart" , function ( confirmResult ) {
2014-03-18 18:35:40 -07:00
2014-03-18 21:59:45 -07:00
if ( confirmResult ) {
2014-03-18 18:35:40 -07:00
2014-03-18 21:59:45 -07:00
Dashboard . showLoadingMsg ( ) ;
2014-03-18 18:35:40 -07:00
2014-03-18 21:59:45 -07:00
$ . ajax ( {
type : "DELETE" ,
2014-03-22 09:16:43 -07:00
url : ApiClient . getUrl ( "Videos/" + id + "/AlternateSources" )
2014-03-18 18:35:40 -07:00
2014-03-18 21:59:45 -07:00
} ) . done ( function ( ) {
Dashboard . hideLoadingMsg ( ) ;
$ ( '.itemsContainer' , page ) . trigger ( 'needsrefresh' ) ;
} ) ;
}
2014-03-18 18:35:40 -07:00
} ) ;
2014-03-18 21:59:45 -07:00
2014-03-17 07:48:16 -07:00
}
2014-03-17 18:45:41 -07:00
function getContextMenuOptions ( elem ) {
2014-03-17 07:48:16 -07:00
var items = [ ] ;
var id = elem . getAttribute ( 'data-itemid' ) ;
items . push ( { type : 'header' , text : 'Edit' } ) ;
items . push ( { type : 'link' , text : 'Details' , url : 'edititemmetadata.html?id=' + id } ) ;
items . push ( { type : 'link' , text : 'Images' , url : 'edititemimages.html?id=' + id } ) ;
2014-03-22 09:16:43 -07:00
var versionCount = parseInt ( elem . getAttribute ( 'data-mediasourcecount' ) || '0' ) ;
2014-03-20 20:31:40 -07:00
if ( versionCount > 1 ) {
2014-03-17 07:48:16 -07:00
2014-03-18 18:35:40 -07:00
items . push ( { type : 'divider' } ) ;
items . push ( { type : 'header' , text : 'Manage' } ) ;
2014-03-18 21:59:45 -07:00
items . push ( { type : 'command' , text : 'Split Versions Apart' , name : 'SplitVersions' } ) ;
2014-03-18 18:35:40 -07:00
}
2014-03-17 07:48:16 -07:00
return items ;
}
$ . fn . createPosterItemMenus = function ( options ) {
options = options || { } ;
function onShowTimerExpired ( elem ) {
if ( $ ( elem ) . hasClass ( 'hasContextMenu' ) ) {
return ;
}
2014-03-18 21:59:45 -07:00
if ( $ ( '.itemSelectionPanel:visible' , elem ) . length ) {
2014-03-17 18:45:41 -07:00
return ;
}
2014-03-17 07:48:16 -07:00
var innerElem = $ ( '.posterItemOverlayTarget' , elem ) ;
var id = elem . getAttribute ( 'data-itemid' ) ;
var promise1 = ApiClient . getItem ( Dashboard . getCurrentUserId ( ) , id ) ;
var promise2 = Dashboard . getCurrentUser ( ) ;
$ . when ( promise1 , promise2 ) . done ( function ( response1 , response2 ) {
var item = response1 [ 0 ] ;
var user = response2 [ 0 ] ;
innerElem . html ( getOverlayHtml ( item , user , elem ) ) . trigger ( 'create' ) ;
$ ( '.btnPlayTrailer' , innerElem ) . on ( 'click' , onTrailerButtonClick ) ;
} ) ;
innerElem . show ( ) . each ( function ( ) {
this . style . height = 0 ;
} ) . animate ( { "height" : "100%" } , "fast" ) ;
}
function onHoverIn ( ) {
if ( showOverlayTimeout ) {
clearTimeout ( showOverlayTimeout ) ;
showOverlayTimeout = null ;
}
var elem = this ;
showOverlayTimeout = setTimeout ( function ( ) {
onShowTimerExpired ( elem ) ;
} , 1000 ) ;
}
// https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/
if ( ( 'ontouchstart' in window ) || ( navigator . maxTouchPoints > 0 ) || ( navigator . msMaxTouchPoints > 0 ) ) {
/ * b r o w s e r w i t h e i t h e r T o u c h E v e n t s o f P o i n t e r E v e n t s
running on touch - capable device * /
return this ;
}
var sequence = this ;
if ( options . contextMenu !== false ) {
Dashboard . getCurrentUser ( ) . done ( function ( user ) {
if ( user . Configuration . IsAdministrator ) {
2014-03-18 18:35:40 -07:00
sequence . createContextMenu ( {
getOptions : getContextMenuOptions ,
command : onMenuCommand ,
selector : '.posterItem'
} ) ;
2014-03-17 07:48:16 -07:00
}
} ) ;
}
2014-04-17 22:03:01 -07:00
return this . off ( '.posterItemHoverMenu' ) . on ( 'mouseenter.posterItemHoverMenu' , '.backdropPosterItem,.smallBackdropPosterItem,.portraitPosterItem,.squarePosterItem' , onHoverIn )
. on ( 'mouseleave.posterItemHoverMenu' , '.backdropPosterItem,.smallBackdropPosterItem,.portraitPosterItem,.squarePosterItem' , onHoverOut ) ;
2014-03-17 07:48:16 -07:00
} ;
2014-03-17 18:45:41 -07:00
function toggleSelections ( page ) {
Dashboard . showLoadingMsg ( ) ;
var selectionCommands = $ ( '.selectionCommands' , page ) ;
if ( selectionCommands . is ( ':visible' ) ) {
selectionCommands . hide ( ) ;
$ ( '.itemSelectionPanel' , page ) . hide ( ) ;
} else {
selectionCommands . show ( ) ;
$ ( '.itemSelectionPanel' , page ) . show ( ) ;
2014-03-18 18:35:40 -07:00
$ ( '.chkItemSelect:checked' , page ) . checked ( false ) . checkboxradio ( 'refresh' ) ;
2014-03-17 18:45:41 -07:00
}
Dashboard . hideLoadingMsg ( ) ;
}
function hideSelections ( page ) {
$ ( '.selectionCommands' , page ) . hide ( ) ;
$ ( '.itemSelectionPanel' , page ) . hide ( ) ;
}
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
function getSelectedItems ( page ) {
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
var selection = $ ( '.chkItemSelect:checked' , page ) ;
return selection . parents ( '.posterItem' )
2014-03-18 18:35:40 -07:00
. map ( function ( ) {
2014-03-17 18:45:41 -07:00
return this . getAttribute ( 'data-itemid' ) ;
} ) . get ( ) ;
}
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
function combineVersions ( page ) {
var selection = getSelectedItems ( page ) ;
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
if ( selection . length < 2 ) {
2014-03-18 18:35:40 -07:00
2014-03-17 18:45:41 -07:00
Dashboard . alert ( {
2014-03-20 08:55:22 -07:00
message : "Please select two or more items to group together." ,
2014-03-17 18:45:41 -07:00
title : "Error"
} ) ;
return ;
}
2014-03-18 18:35:40 -07:00
var names = $ ( '.chkItemSelect:checked' , page ) . parents ( '.posterItem' ) . get ( ) . reverse ( ) . map ( function ( e ) {
return $ ( '.posterItemText' , e ) . html ( ) ;
} ) . join ( '<br/>' ) ;
var msg = "The following titles will be grouped into one item:<br/><br/>" + names ;
2014-03-19 10:44:55 -07:00
msg += "<br/><br/>Media Browser clients will automatically choose the optimal version to play based on device and network performance. Are you sure you wish to continue?" ;
2014-03-18 18:35:40 -07:00
Dashboard . confirm ( msg , "Group Versions" , function ( confirmResult ) {
if ( confirmResult ) {
Dashboard . showLoadingMsg ( ) ;
$ . ajax ( {
type : "POST" ,
url : ApiClient . getUrl ( "Videos/MergeVersions" , { Ids : selection . join ( ',' ) } )
} ) . done ( function ( ) {
Dashboard . hideLoadingMsg ( ) ;
hideSelections ( ) ;
$ ( '.itemsContainer' , page ) . trigger ( 'needsrefresh' ) ;
} ) ;
}
} ) ;
2014-03-17 18:45:41 -07:00
}
$ ( document ) . on ( 'pageinit' , ".libraryPage" , function ( ) {
var page = this ;
$ ( '.btnToggleSelections' , page ) . on ( 'click' , function ( ) {
toggleSelections ( page ) ;
} ) ;
$ ( '.btnMergeVersions' , page ) . on ( 'click' , function ( ) {
combineVersions ( page ) ;
} ) ;
} ) ;
2014-03-17 07:48:16 -07:00
} ) ( jQuery , document , window ) ;