jellyfin-web/dashboard-ui/scripts/moviegenres.js
2017-03-02 14:05:43 -05:00

1 line
4.5 KiB
JavaScript

define(["libraryBrowser","cardBuilder","lazyLoader","apphost","globalize","dom"],function(libraryBrowser,cardBuilder,lazyLoader,appHost,globalize,dom){"use strict";return function(view,params,tabContent){function getPageData(){var key=getSavedQueryKey(),pageData=data[key];return pageData||(pageData=data[key]={query:{SortBy:"SortName",SortOrder:"Ascending",IncludeItemTypes:"Movie",Recursive:!0,EnableTotalRecordCount:!1},view:"Poster"},pageData.query.ParentId=params.topParentId,libraryBrowser.loadSavedQueryValues(key,pageData.query)),pageData}function getQuery(){return getPageData().query}function getSavedQueryKey(){return libraryBrowser.getSavedQueryKey("moviegenres")}function getPromise(){Dashboard.showLoadingMsg();var query=getQuery();return ApiClient.getGenres(Dashboard.getCurrentUserId(),query)}function enableScrollX(){return browserInfo.mobile}function getThumbShape(){return enableScrollX()?"overflowBackdrop":"backdrop"}function getPortraitShape(){return enableScrollX()?"overflowPortrait":"portrait"}function getMoreItemsHref(itemId,type){return"secondaryitems.html?type="+type+"&genreId="+itemId+"&parentId="+params.topParentId}function fillItemsContainer(elem){var id=elem.getAttribute("data-id"),viewStyle=self.getCurrentViewStyle(),limit="Thumb"==viewStyle||"ThumbCard"==viewStyle?5:8;enableScrollX()&&(limit=10);var enableImageTypes="Thumb"==viewStyle||"ThumbCard"==viewStyle?"Primary,Backdrop,Thumb":"Primary",query={SortBy:"SortName",SortOrder:"Ascending",IncludeItemTypes:"Movie",Recursive:!0,Fields:"PrimaryImageAspectRatio,MediaSourceCount,BasicSyncInfo",ImageTypeLimit:1,EnableImageTypes:enableImageTypes,Limit:limit,GenreIds:id,EnableTotalRecordCount:!1,ParentId:params.topParentId};ApiClient.getItems(Dashboard.getCurrentUserId(),query).then(function(result){var supportsImageAnalysis=appHost.supports("imageanalysis");"Thumb"==viewStyle?cardBuilder.buildCards(result.Items,{itemsContainer:elem,shape:getThumbShape(),preferThumb:!0,showTitle:!0,scalable:!0,centerText:!0,overlayMoreButton:!0,allowBottomPadding:!1}):"ThumbCard"==viewStyle?cardBuilder.buildCards(result.Items,{itemsContainer:elem,shape:getThumbShape(),preferThumb:!0,showTitle:!0,scalable:!0,centerText:!1,cardLayout:!0,vibrant:supportsImageAnalysis,showYear:!0}):"PosterCard"==viewStyle?cardBuilder.buildCards(result.Items,{itemsContainer:elem,shape:getPortraitShape(),showTitle:!0,scalable:!0,centerText:!1,cardLayout:!0,vibrant:supportsImageAnalysis,showYear:!0}):"Poster"==viewStyle&&cardBuilder.buildCards(result.Items,{itemsContainer:elem,shape:getPortraitShape(),scalable:!0,overlayMoreButton:!0,allowBottomPadding:!1}),result.Items.length>=query.Limit&&tabContent.querySelector(".btnMoreFromGenre"+id).classList.remove("hide")})}function reloadItems(context,promise){var query=getQuery();promise.then(function(result){for(var elem=context.querySelector("#items"),html="",items=result.Items,i=0,length=items.length;i<length;i++){var item=items[i];html+='<div class="homePageSection">',html+='<div style="display:flex;align-items:center;">',html+='<h1 class="listHeader">',html+=item.Name,html+="</h1>",html+='<button is="emby-button" type="button" class="raised more mini hide btnMoreFromGenre btnMoreFromGenre'+item.Id+'" data-id="'+item.Id+'">',html+="<span>"+globalize.translate("ButtonMore")+"</span>",html+="</button>",html+="</div>",html+=enableScrollX()?'<div is="emby-itemscontainer" class="itemsContainer hiddenScrollX lazy" data-id="'+item.Id+'">':'<div is="emby-itemscontainer" class="itemsContainer vertical-wrap lazy" data-id="'+item.Id+'">',html+="</div>",html+="</div>"}elem.innerHTML=html,lazyLoader.lazyChildren(elem,fillItemsContainer),libraryBrowser.saveQueryValues(getSavedQueryKey(),query),Dashboard.hideLoadingMsg()})}function fullyReload(){self.preRender(),self.renderTab()}var self=this,data={};dom.addEventListener(tabContent,"click",function(e){var btnMoreFromGenre=dom.parentWithClass(e.target,"btnMoreFromGenre");if(btnMoreFromGenre){var id=btnMoreFromGenre.getAttribute("data-id");Dashboard.navigate(getMoreItemsHref(id,"Movie"))}},{passive:!0}),self.getViewStyles=function(){return"Poster,PosterCard,Thumb,ThumbCard".split(",")},self.getCurrentViewStyle=function(){return getPageData(tabContent).view},self.setCurrentViewStyle=function(viewStyle){getPageData(tabContent).view=viewStyle,libraryBrowser.saveViewSetting(getSavedQueryKey(tabContent),viewStyle),fullyReload()},self.enableViewSelection=!0;var promise;self.preRender=function(){promise=getPromise()},self.renderTab=function(){reloadItems(tabContent,promise)}}});