2016-07-29 21:53:19 -07:00
|
|
|
|
define(['libraryBrowser', 'focusManager', 'embyRouter', 'cardBuilder', 'emby-input', 'paper-icon-button-light', 'material-icons', 'emby-itemscontainer'], function (libraryBrowser, focusManager, embyRouter, cardBuilder) {
|
2015-09-23 19:31:40 -07:00
|
|
|
|
|
|
|
|
|
function loadSuggestions(page) {
|
|
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
|
|
2015-09-24 10:08:10 -07:00
|
|
|
|
SortBy: "IsFavoriteOrLiked,Random",
|
2015-09-23 19:31:40 -07:00
|
|
|
|
IncludeItemTypes: "Movie,Series,MusicArtist",
|
|
|
|
|
Limit: 20,
|
|
|
|
|
Recursive: true,
|
|
|
|
|
ImageTypeLimit: 0,
|
|
|
|
|
EnableImages: false
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), options).then(function (result) {
|
2015-09-23 19:31:40 -07:00
|
|
|
|
|
|
|
|
|
var html = result.Items.map(function (i) {
|
|
|
|
|
|
|
|
|
|
var href = LibraryBrowser.getHref(i);
|
|
|
|
|
|
2015-09-24 10:08:10 -07:00
|
|
|
|
var itemHtml = '<div><a style="display:inline-block;padding:.55em 1em;" href="' + href + '">';
|
2015-09-23 19:31:40 -07:00
|
|
|
|
itemHtml += i.Name;
|
2015-09-24 10:08:10 -07:00
|
|
|
|
itemHtml += '</a></div>';
|
2015-09-23 19:31:40 -07:00
|
|
|
|
return itemHtml;
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
page.querySelector('.searchSuggestions').innerHTML = html;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 10:28:36 -07:00
|
|
|
|
return function (view, params) {
|
2015-09-23 19:31:40 -07:00
|
|
|
|
|
2016-06-27 10:28:36 -07:00
|
|
|
|
var textSuggestions = view.querySelector('.textSuggestions');
|
|
|
|
|
var searchResults = view.querySelector('.searchResults');
|
|
|
|
|
var searchHintTimeout;
|
2015-09-23 19:31:40 -07:00
|
|
|
|
|
2016-06-27 10:28:36 -07:00
|
|
|
|
function clearSearchHintTimeout() {
|
2015-09-23 19:31:40 -07:00
|
|
|
|
|
2016-06-27 10:28:36 -07:00
|
|
|
|
if (searchHintTimeout) {
|
2015-09-23 19:31:40 -07:00
|
|
|
|
|
2016-06-27 10:28:36 -07:00
|
|
|
|
clearTimeout(searchHintTimeout);
|
|
|
|
|
searchHintTimeout = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showTextSuggestions() {
|
|
|
|
|
if (AppInfo.enableAppLayouts) {
|
|
|
|
|
textSuggestions.classList.remove('hide');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getAdditionalTextLines(hint) {
|
|
|
|
|
|
|
|
|
|
if (hint.Type == "Audio") {
|
|
|
|
|
|
|
|
|
|
return [[hint.AlbumArtist, hint.Album].join(" - ")];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicAlbum") {
|
|
|
|
|
|
|
|
|
|
return [hint.AlbumArtist];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicArtist") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelArtist')];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Movie") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelMovie')];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "MusicVideo") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelMusicVideo')];
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Episode") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelEpisode')];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "Series") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('Series')];
|
|
|
|
|
}
|
|
|
|
|
else if (hint.Type == "BoxSet") {
|
|
|
|
|
|
|
|
|
|
return [Globalize.translate('LabelCollection')];
|
|
|
|
|
}
|
|
|
|
|
else if (hint.ChannelName) {
|
|
|
|
|
|
|
|
|
|
return [hint.ChannelName];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [hint.Type];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderSearchResultsInOverlay(hints) {
|
|
|
|
|
|
|
|
|
|
// Massage the objects to look like regular items
|
|
|
|
|
hints = hints.map(function (i) {
|
|
|
|
|
|
|
|
|
|
i.Id = i.ItemId;
|
|
|
|
|
i.ImageTags = {};
|
|
|
|
|
i.UserData = {};
|
|
|
|
|
|
|
|
|
|
if (i.PrimaryImageTag) {
|
|
|
|
|
i.ImageTags.Primary = i.PrimaryImageTag;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-29 21:53:19 -07:00
|
|
|
|
var html = cardBuilder.getCardsHtml({
|
2016-06-27 10:28:36 -07:00
|
|
|
|
items: hints,
|
|
|
|
|
shape: "auto",
|
|
|
|
|
lazy: true,
|
|
|
|
|
overlayText: false,
|
|
|
|
|
showTitle: true,
|
|
|
|
|
centerImage: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
textLines: getAdditionalTextLines,
|
2016-08-04 09:39:19 -07:00
|
|
|
|
overlayMoreButton: true,
|
2016-07-17 11:55:07 -07:00
|
|
|
|
serverId: ApiClient.serverInfo().Id
|
2016-06-27 10:28:36 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-07-24 09:46:17 -07:00
|
|
|
|
if (!hints.length) {
|
|
|
|
|
html = '<p style="text-align:center;margin-top:2em;">' + Globalize.translate('NoResultsFound') + '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 10:28:36 -07:00
|
|
|
|
var itemsContainer = searchResults;
|
|
|
|
|
itemsContainer.innerHTML = html;
|
|
|
|
|
searchResults.classList.remove('hide');
|
|
|
|
|
textSuggestions.classList.add('hide');
|
|
|
|
|
ImageLoader.lazyChildren(itemsContainer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function requestSearchHintsForOverlay(searchTerm) {
|
|
|
|
|
|
|
|
|
|
var currentTimeout = searchHintTimeout;
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.getSearchHints({
|
|
|
|
|
|
|
|
|
|
userId: Dashboard.getCurrentUserId(),
|
|
|
|
|
searchTerm: (searchTerm || '').trim(),
|
|
|
|
|
limit: 30
|
|
|
|
|
|
|
|
|
|
}).then(function (result) {
|
|
|
|
|
|
|
|
|
|
if (currentTimeout == searchHintTimeout) {
|
|
|
|
|
renderSearchResultsInOverlay(result.SearchHints);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
}, function () {
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onSearchChange(val) {
|
|
|
|
|
|
|
|
|
|
if (!val) {
|
|
|
|
|
clearSearchHintTimeout();
|
|
|
|
|
searchResults.classList.add('hide');
|
|
|
|
|
searchResults.innerHTML = '';
|
|
|
|
|
showTextSuggestions();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearSearchHintTimeout();
|
|
|
|
|
|
|
|
|
|
searchHintTimeout = setTimeout(function () {
|
|
|
|
|
requestSearchHintsForOverlay(val);
|
|
|
|
|
}, 300);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (AppInfo.enableAppLayouts) {
|
|
|
|
|
showTextSuggestions();
|
|
|
|
|
loadSuggestions(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
view.querySelector('.txtSearch').addEventListener('input', function () {
|
|
|
|
|
onSearchChange(this.value);
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-27 15:53:42 -07:00
|
|
|
|
view.querySelector('.btnBack').addEventListener('click', function () {
|
|
|
|
|
embyRouter.back();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
view.addEventListener('viewbeforeshow', function (e) {
|
2016-07-04 22:40:18 -07:00
|
|
|
|
document.body.classList.add('hiddenViewMenuBar');
|
2016-06-27 15:53:42 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
view.addEventListener('viewbeforehide', function (e) {
|
2016-07-04 22:40:18 -07:00
|
|
|
|
|
|
|
|
|
document.body.classList.remove('hiddenViewMenuBar');
|
2016-06-27 15:53:42 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-06-27 10:28:36 -07:00
|
|
|
|
};
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|