jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/search/searchresults.js
2017-05-01 16:03:02 -04:00

1 line
4.6 KiB
JavaScript

define(["layoutManager","globalize","require","events","connectionManager","cardBuilder","embyRouter","emby-scroller","emby-itemscontainer"],function(layoutManager,globalize,require,events,connectionManager,cardBuilder,embyRouter){"use strict";function loadSuggestions(instance,context,apiClient){var options={SortBy:"IsFavoriteOrLiked,Random",IncludeItemTypes:"Movie,Series,MusicArtist",Limit:20,Recursive:!0,ImageTypeLimit:0,EnableImages:!1,ParentId:instance.options.parentId};apiClient.getItems(apiClient.getCurrentUserId(),options).then(function(result){var html=result.Items.map(function(i){var href=embyRouter.getRouteUrl(i),itemHtml='<div><a style="display:inline-block;padding:.55em 1em;" href="'+href+'">';return itemHtml+=i.Name,itemHtml+="</a></div>"}).join(""),searchSuggestions=context.querySelector(".searchSuggestions");searchSuggestions.querySelector(".searchSuggestionsList").innerHTML=html,searchSuggestions.classList.remove("hide")})}function getSearchHints(apiClient,query){return query.searchTerm?apiClient.getSearchHints(query):Promise.resolve({SearchHints:[]})}function search(instance,apiClient,context,value){value||layoutManager.tv?context.querySelector(".searchSuggestions").classList.add("hide"):loadSuggestions(instance,context,apiClient),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!0,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1,IncludeItemTypes:"Movie"},context,".movieResults"),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!0,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1,IncludeItemTypes:"LiveTvProgram"},context,".programResults",{showTitle:!0,showParentTitle:!0,overlayText:!1,centerText:!0}),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!0,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1,IncludeItemTypes:"Series"},context,".seriesResults"),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!0,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1,IncludeItemTypes:"Episode"},context,".episodeResults",{coverImage:!0,showTitle:!0,showParentTitle:!0}),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!0,IncludeMedia:!1,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1},context,".peopleResults",{coverImage:!0,showTitle:!0}),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!1,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!0},context,".artistResults",{coverImage:!0,showTitle:!0}),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!0,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1,IncludeItemTypes:"MusicAlbum"},context,".albumResults"),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!0,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1,IncludeItemTypes:"Audio"},context,".songResults",{action:"play"}),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!0,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1,IncludeItemTypes:"Book"},context,".bookResults"),searchType(instance,apiClient,{searchTerm:value,IncludePeople:!1,IncludeMedia:!0,IncludeGenres:!1,IncludeStudios:!1,IncludeArtists:!1,IncludeItemTypes:"AudioBook"},context,".audioBookResults")}function searchType(instance,apiClient,query,context,section,cardOptions){query.UserId=apiClient.getCurrentUserId(),query.Limit=24,query.ParentId=instance.options.parentId,getSearchHints(apiClient,query).then(function(result){populateResults(result,context,section,cardOptions)})}function populateResults(result,context,section,cardOptions){section=context.querySelector(section);var items=result.SearchHints,itemsContainer=section.querySelector(".itemsContainer");cardBuilder.buildCards(items,Object.assign({itemsContainer:itemsContainer,parentContainer:section,shape:"autooverflow",scalable:!0,overlayText:!0,widths:{portrait:340,thumb:500,square:340}},cardOptions||{})),section.querySelector(".emby-scroller").scrollToBeginning(!0)}function embed(elem,instance,options){require(["text!./searchresults.template.html"],function(template){var html=globalize.translateDocument(template,"sharedcomponents");elem.innerHTML=html,elem.classList.add("searchResults"),instance.search("")})}function SearchResults(options){this.options=options,embed(options.element,this,options)}return SearchResults.prototype.search=function(value){var apiClient=connectionManager.getApiClient(this.options.serverId);search(this,apiClient,this.options.element,value)},SearchResults.prototype.destroy=function(){var options=this.options;options&&options.element.classList.remove("searchFields"),this.options=null},SearchResults});