2015-07-08 22:52:25 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
|
|
|
|
var data = {};
|
|
|
|
|
|
2015-08-18 21:08:03 -07:00
|
|
|
|
function addCurrentItemToQuery(query, item) {
|
|
|
|
|
|
|
|
|
|
if (item.Type == "Person") {
|
|
|
|
|
query.PersonIds = item.Id;
|
|
|
|
|
}
|
|
|
|
|
else if (item.Type == "Genre") {
|
|
|
|
|
query.Genres = item.Name;
|
|
|
|
|
}
|
|
|
|
|
else if (item.Type == "MusicGenre") {
|
|
|
|
|
query.Genres = item.Name;
|
|
|
|
|
}
|
|
|
|
|
else if (item.Type == "GameGenre") {
|
|
|
|
|
query.Genres = item.Name;
|
|
|
|
|
}
|
|
|
|
|
else if (item.Type == "Studio") {
|
|
|
|
|
query.StudioIds = item.Id;
|
|
|
|
|
}
|
|
|
|
|
else if (item.Type == "MusicArtist") {
|
|
|
|
|
query.ArtistIds = item.Id;
|
|
|
|
|
} else {
|
|
|
|
|
query.ParentId = item.Id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQuery(parentItem) {
|
2015-07-08 22:52:25 -07:00
|
|
|
|
|
|
|
|
|
var key = getSavedQueryKey();
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
2015-08-26 11:17:38 -07:00
|
|
|
|
Recursive: getParameterByName('recursive') !== 'false',
|
2015-07-08 22:52:25 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var type = getParameterByName('type');
|
|
|
|
|
if (type) {
|
|
|
|
|
pageData.query.IncludeItemTypes = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filters = getParameterByName('filters');
|
|
|
|
|
if (type) {
|
|
|
|
|
pageData.query.Filters = filters;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 21:08:03 -07:00
|
|
|
|
if (parentItem) {
|
|
|
|
|
addCurrentItemToQuery(pageData.query, parentItem);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 22:52:25 -07:00
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData.query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSavedQueryKey() {
|
|
|
|
|
|
2015-10-14 21:32:10 -07:00
|
|
|
|
return LibraryBrowser.getSavedQueryKey();
|
2015-07-08 22:52:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 12:33:00 -07:00
|
|
|
|
function onListItemClick(e) {
|
|
|
|
|
|
|
|
|
|
var page = $(this).parents('.page')[0];
|
|
|
|
|
var info = LibraryBrowser.getListItemInfo(this);
|
|
|
|
|
|
|
|
|
|
if (info.mediaType == 'Photo') {
|
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
|
|
|
|
require(['scripts/photos'], function () {
|
|
|
|
|
Photos.startSlideshow(page, query, info.id);
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 21:08:03 -07:00
|
|
|
|
function reloadItems(page, parentItem) {
|
2015-07-08 22:52:25 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2015-08-18 21:08:03 -07:00
|
|
|
|
var query = getQuery(parentItem);
|
2015-07-08 22:52:25 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
|
2015-07-08 22:52:25 -07:00
|
|
|
|
|
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
|
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
showLimit: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
|
2015-08-18 21:08:03 -07:00
|
|
|
|
|
|
|
|
|
if (query.IncludeItemTypes == "Audio") {
|
|
|
|
|
|
|
|
|
|
html = '<div style="max-width:1000px;margin:auto;">' + LibraryBrowser.getListViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
playFromHere: true,
|
|
|
|
|
defaultAction: 'playallfromhere',
|
|
|
|
|
smallIcon: true
|
|
|
|
|
}) + '</div>';
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
var posterOptions = {
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "auto",
|
|
|
|
|
centerText: true,
|
2015-08-23 19:08:20 -07:00
|
|
|
|
lazy: true
|
2015-08-18 21:08:03 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (query.IncludeItemTypes == "MusicAlbum") {
|
|
|
|
|
posterOptions.overlayText = false;
|
|
|
|
|
posterOptions.showParentTitle = true;
|
|
|
|
|
posterOptions.overlayPlayButton = true;
|
|
|
|
|
}
|
|
|
|
|
else if (query.IncludeItemTypes == "MusicArtist") {
|
|
|
|
|
posterOptions.overlayText = false;
|
|
|
|
|
posterOptions.overlayPlayButton = true;
|
|
|
|
|
}
|
|
|
|
|
else if (query.IncludeItemTypes == "Episode") {
|
|
|
|
|
posterOptions.overlayText = false;
|
|
|
|
|
posterOptions.showParentTitle = true;
|
2015-08-25 07:33:21 -07:00
|
|
|
|
posterOptions.showTitle = true;
|
2015-08-18 21:08:03 -07:00
|
|
|
|
posterOptions.overlayPlayButton = true;
|
|
|
|
|
}
|
2015-07-08 22:52:25 -07:00
|
|
|
|
|
2015-08-18 21:08:03 -07:00
|
|
|
|
// Poster
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml(posterOptions);
|
2015-07-08 22:52:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var elem = page.querySelector('#items');
|
|
|
|
|
elem.innerHTML = html + pagingHtml;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
|
|
|
|
|
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
2015-08-18 21:08:03 -07:00
|
|
|
|
reloadItems(page, parentItem);
|
2015-07-08 22:52:25 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
2015-08-18 21:08:03 -07:00
|
|
|
|
reloadItems(page, parentItem);
|
2015-07-08 22:52:25 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.setLastRefreshed(page);
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
pageIdOn('pageinit', "secondaryItemsPage", function () {
|
2015-07-12 12:33:00 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$(page).on('click', '.mediaItem', onListItemClick);
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
pageIdOn('pagebeforeshow', "secondaryItemsPage", function () {
|
2015-07-08 22:52:25 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2015-07-12 12:33:00 -07:00
|
|
|
|
if (getParameterByName('parentid')) {
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), getParameterByName('parentid')).then(function (parent) {
|
2015-07-12 12:33:00 -07:00
|
|
|
|
LibraryMenu.setTitle(parent.Name);
|
2015-08-18 21:08:03 -07:00
|
|
|
|
|
|
|
|
|
if (LibraryBrowser.needsRefresh(page)) {
|
|
|
|
|
reloadItems(page, parent);
|
|
|
|
|
}
|
2015-07-12 12:33:00 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 21:08:03 -07:00
|
|
|
|
else if (LibraryBrowser.needsRefresh(page)) {
|
2015-07-08 22:52:25 -07:00
|
|
|
|
reloadItems(page);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(jQuery, document);
|