jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/shortcuts.js

1 line
8.0 KiB
JavaScript
Raw Normal View History

2017-07-19 12:53:26 -07:00
define(["playbackManager","inputManager","connectionManager","appRouter","globalize","loading","dom","recordingHelper"],function(playbackManager,inputManager,connectionManager,appRouter,globalize,loading,dom,recordingHelper){"use strict";function playAllFromHere(card,serverId,queue){for(var parent=card.parentNode,className=card.classList.length?"."+card.classList[0]:"",cards=parent.querySelectorAll(className+"[data-id]"),ids=[],foundCard=!1,i=0,length=cards.length;i<length;i++)cards[i]===card&&(foundCard=!0),foundCard&&ids.push(cards[i].getAttribute("data-id"));ids.length&&(queue?playbackManager.queue({ids:ids,serverId:serverId}):playbackManager.play({ids:ids,serverId:serverId}))}function showProgramDialog(item){require(["recordingCreator"],function(recordingCreator){recordingCreator.show(item.Id,item.ServerId)})}function getItem(button){button=dom.parentWithAttribute(button,"data-id");var serverId=button.getAttribute("data-serverid"),id=button.getAttribute("data-id"),type=button.getAttribute("data-type"),apiClient=connectionManager.getApiClient(serverId);return"Timer"===type?apiClient.getLiveTvTimer(id):"SeriesTimer"===type?apiClient.getLiveTvSeriesTimer(id):apiClient.getItem(apiClient.getCurrentUserId(),id)}function showContextMenu(card,options){getItem(card).then(function(item){var playlistId=card.getAttribute("data-playlistid"),collectionId=card.getAttribute("data-collectionid");if(playlistId){var elem=dom.parentWithAttribute(card,"data-playlistitemid");item.PlaylistItemId=elem?elem.getAttribute("data-playlistitemid"):null}require(["itemContextMenu"],function(itemContextMenu){connectionManager.getApiClient(item.ServerId).getCurrentUser().then(function(user){itemContextMenu.show(Object.assign({item:item,play:!0,queue:!0,playAllFromHere:!item.IsFolder,queueAllFromHere:!item.IsFolder,playlistId:playlistId,collectionId:collectionId,user:user},options||{})).then(function(result){var itemsContainer;"playallfromhere"===result.command||"queueallfromhere"===result.command?executeAction(card,options.positionTo,result.command):"removefromplaylist"===result.command||"removefromcollection"===result.command?(itemsContainer=options.itemsContainer||dom.parentWithAttribute(card,"is","emby-itemscontainer"),itemsContainer&&itemsContainer.dispatchEvent(new CustomEvent("needsrefresh",{detail:{},cancelable:!1,bubbles:!0}))):"canceltimer"===result.command&&(itemsContainer=options.itemsContainer||dom.parentWithAttribute(card,"is","emby-itemscontainer"),itemsContainer&&itemsContainer.dispatchEvent(new CustomEvent("timercancelled",{detail:{},cancelable:!1,bubbles:!0})))})})})})}function getItemInfoFromCard(card){return{Type:card.getAttribute("data-type"),Id:card.getAttribute("data-id"),TimerId:card.getAttribute("data-timerid"),CollectionType:card.getAttribute("data-collectiontype"),ChannelId:card.getAttribute("data-channelid"),SeriesId:card.getAttribute("data-seriesid"),ServerId:card.getAttribute("data-serverid"),MediaType:card.getAttribute("data-mediatype"),IsFolder:"true"===card.getAttribute("data-isfolder"),UserData:{PlaybackPositionTicks:parseInt(card.getAttribute("data-positionticks")||"0")}}}function showPlayMenu(card,target){var item=getItemInfoFromCard(card);require(["playMenu"],function(playMenu){playMenu.show({item:item,positionTo:target})})}function sendToast(text){require(["toast"],function(toast){toast(text)})}function executeAction(card,target,action){target=target||card;var id=card.getAttribute("data-id");id||(card=dom.parentWithAttribute(card,"data-id"),id=card.getAttribute("data-id"));var item=getItemInfoFromCard(card),serverId=item.ServerId,type=item.Type,playableItemId="Program"===type?item.ChannelId:item.Id;if("Photo"===item.MediaType&&"link"===action&&(action="play"),"link"===action)appRouter.showItem(item,{context:card.getAttribute("data-context"),parentId:card.getAttribute("data-parentid")});else if("programdialog"===action)showProgramDialog(item);else if("instantmix"===action)playbackManager.instantMix({Id:playableItemId,ServerId:serverId});else if("play"===action||"resume"===action){var startPositionTicks=parseInt(ca