mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-18 03:18:19 -07:00
1 line
2.6 KiB
JavaScript
1 line
2.6 KiB
JavaScript
define(["libraryBrowser","cardBuilder","apphost","imageLoader"],function(libraryBrowser,cardBuilder,appHost,imageLoader){"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",Recursive:!0,Fields:"PrimaryImageAspectRatio,ItemCounts",StartIndex:0},view:libraryBrowser.getSavedView(key)||(appHost.preferVisualCards?"PosterCard":"Poster")},pageData.query.ParentId=params.topParentId,libraryBrowser.loadSavedQueryValues(key,pageData.query)),pageData}function getQuery(){return getPageData().query}function getSavedQueryKey(){return libraryBrowser.getSavedQueryKey("genres")}function getPromise(){Dashboard.showLoadingMsg();var query=getQuery();return ApiClient.getGenres(Dashboard.getCurrentUserId(),query)}function reloadItems(context,promise){var query=getQuery();promise.then(function(result){var html="",viewStyle=self.getCurrentViewStyle();"Thumb"==viewStyle?html=cardBuilder.getCardsHtml({items:result.Items,shape:"backdrop",preferThumb:!0,context:"music",centerText:!0,overlayMoreButton:!0,showTitle:!0}):"ThumbCard"==viewStyle?html=cardBuilder.getCardsHtml({items:result.Items,shape:"backdrop",preferThumb:!0,context:"music",cardLayout:!0,showTitle:!0,vibrant:!0}):"PosterCard"==viewStyle?html=cardBuilder.getCardsHtml({items:result.Items,shape:"auto",context:"music",cardLayout:!0,showTitle:!0,vibrant:!0}):"Poster"==viewStyle&&(html=cardBuilder.getCardsHtml({items:result.Items,shape:"auto",context:"music",centerText:!0,overlayMoreButton:!0,showTitle:!0}));var elem=context.querySelector("#items");elem.innerHTML=html,imageLoader.lazyChildren(elem),libraryBrowser.saveQueryValues(getSavedQueryKey(),query),Dashboard.hideLoadingMsg()})}function fullyReload(){self.preRender(),self.renderTab()}var self=this,data={};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)};var btnSelectView=tabContent.querySelector(".btnSelectView");btnSelectView.addEventListener("click",function(e){libraryBrowser.showLayoutMenu(e.target,self.getCurrentViewStyle(),self.getViewStyles())}),btnSelectView.addEventListener("layoutchange",function(e){self.setCurrentViewStyle(e.detail.viewStyle)})}}); |