jellyfin-web/dashboard-ui/scripts/livetvschedule.js
2017-01-27 22:16:59 -05:00

1 line
2.7 KiB
JavaScript

define(["cardBuilder","apphost","imageLoader","scripts/livetvcomponents","emby-button","emby-itemscontainer"],function(cardBuilder,appHost,imageLoader){"use strict";function enableScrollX(){return browserInfo.mobile}function renderRecordings(elem,recordings,cardOptions){recordings.length?elem.classList.remove("hide"):elem.classList.add("hide");var recordingItems=elem.querySelector(".recordingItems");enableScrollX()?(recordingItems.classList.add("hiddenScrollX"),recordingItems.classList.remove("vertical-wrap")):(recordingItems.classList.remove("hiddenScrollX"),recordingItems.classList.add("vertical-wrap"));var supportsImageAnalysis=appHost.supports("imageanalysis"),cardLayout=appHost.preferVisualCards||supportsImageAnalysis;recordingItems.innerHTML=cardBuilder.getCardsHtml(Object.assign({items:recordings,shape:enableScrollX()?"autooverflow":"auto",showTitle:!0,showParentTitle:!0,coverImage:!0,cardLayout:cardLayout,centerText:!cardLayout,vibrant:supportsImageAnalysis,allowBottomPadding:!enableScrollX(),preferThumb:"auto"},cardOptions||{})),imageLoader.lazyChildren(recordingItems)}function getBackdropShape(){return enableScrollX()?"overflowBackdrop":"backdrop"}function renderActiveRecordings(context,promise){promise.then(function(result){result.Items.length&&"InProgress"!=result.Items[0].Status&&(result.Items=[]),renderRecordings(context.querySelector("#activeRecordings"),result.Items,{shape:getBackdropShape(),showParentTitle:!1,showTitle:!0,showAirTime:!0,showAirEndTime:!0,showChannelName:!0,preferThumb:!0,coverImage:!0,overlayText:!1})})}function renderTimers(context,timers,options){LiveTvHelpers.getTimersHtml(timers,options).then(function(html){var elem=context;html?elem.classList.remove("hide"):elem.classList.add("hide"),elem.querySelector(".recordingItems").innerHTML=html,imageLoader.lazyChildren(elem)})}function renderUpcomingRecordings(context,promise){promise.then(function(result){renderTimers(context.querySelector("#upcomingRecordings"),result.Items),Dashboard.hideLoadingMsg()})}return function(view,params,tabContent){var activeRecordingsPromise,upcomingRecordingsPromise,self=this;tabContent.querySelector("#upcomingRecordings .recordingItems").addEventListener("timercancelled",function(){self.preRender(),self.renderTab()}),self.preRender=function(){activeRecordingsPromise=ApiClient.getLiveTvRecordings({UserId:Dashboard.getCurrentUserId(),IsInProgress:!0,Fields:"CanDelete,PrimaryImageAspectRatio,BasicSyncInfo",EnableTotalRecordCount:!1,EnableImageTypes:"Primary,Thumb,Backdrop"}),upcomingRecordingsPromise=ApiClient.getLiveTvTimers({IsActive:!1,IsScheduled:!0})},self.renderTab=function(){Dashboard.showLoadingMsg(),renderActiveRecordings(tabContent,activeRecordingsPromise),renderUpcomingRecordings(tabContent,upcomingRecordingsPromise)}}});