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

1 line
2.4 KiB
JavaScript

define(["cardBuilder","imageLoader","emby-itemscontainer"],function(cardBuilder,imageLoader){"use strict";return function(view,params,tabContent){function getPageData(context){var key=getSavedQueryKey(context),pageData=data[key];return pageData||(pageData=data[key]={query:{StartIndex:0,Limit:LibraryBrowser.getDefaultPageSize(),Fields:"PrimaryImageAspectRatio"}},LibraryBrowser.loadSavedQueryValues(key,pageData.query)),pageData}function getQuery(context){return getPageData(context).query}function getSavedQueryKey(context){return context.savedQueryKey||(context.savedQueryKey=LibraryBrowser.getSavedQueryKey("channels")),context.savedQueryKey}function getChannelsHtml(channels){return cardBuilder.getCardsHtml({items:channels,shape:"square",showTitle:!0,lazy:!0,cardLayout:!0,showDetailsMenu:!0,showCurrentProgram:!0})}function renderChannels(context,result){function onNextPageClick(){query.StartIndex+=query.Limit,reloadItems(context)}function onPreviousPageClick(){query.StartIndex-=query.Limit,reloadItems(context)}var query=getQuery(context);context.querySelector(".paging").innerHTML=LibraryBrowser.getQueryPagingHtml({startIndex:query.StartIndex,limit:query.Limit,totalRecordCount:result.TotalRecordCount,showLimit:!1,updatePageSizeSetting:!1,filterButton:!1});var html=getChannelsHtml(result.Items),elem=context.querySelector("#items");elem.innerHTML=html,imageLoader.lazyChildren(elem);var i,length,elems;for(elems=context.querySelectorAll(".btnNextPage"),i=0,length=elems.length;i<length;i++)elems[i].addEventListener("click",onNextPageClick);for(elems=context.querySelectorAll(".btnPreviousPage"),i=0,length=elems.length;i<length;i++)elems[i].addEventListener("click",onPreviousPageClick);LibraryBrowser.saveQueryValues(getSavedQueryKey(context),query)}function showFilterMenu(context){require(["components/filterdialog/filterdialog"],function(filterDialogFactory){var filterDialog=new filterDialogFactory({query:getQuery(context),mode:"livetvchannels"});Events.on(filterDialog,"filterchange",function(){reloadItems(context)}),filterDialog.show()})}function reloadItems(context){Dashboard.showLoadingMsg();var query=getQuery(context);query.UserId=Dashboard.getCurrentUserId(),ApiClient.getLiveTvChannels(query).then(function(result){renderChannels(context,result),Dashboard.hideLoadingMsg()})}var self=this,data={};tabContent.querySelector(".btnFilter").addEventListener("click",function(){showFilterMenu(tabContent)}),self.renderTab=function(){reloadItems(tabContent)}}});