jellyfin-web/dashboard-ui/scripts/secondaryitems.js

186 lines
6.1 KiB
JavaScript
Raw Normal View History

2016-03-18 12:43:17 -07:00
define(['libraryBrowser', 'jQuery'], function (libraryBrowser, $) {
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
return function (view, params) {
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
var data = {};
2015-08-18 21:08:03 -07:00
2016-03-18 12:43:17 -07:00
function addCurrentItemToQuery(query, item) {
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
if (item.Type == "Person") {
query.PersonIds = item.Id;
2015-07-08 22:52:25 -07:00
}
2016-03-18 12:43:17 -07:00
else if (item.Type == "Genre") {
query.Genres = item.Name;
2015-07-08 22:52:25 -07:00
}
2016-03-18 12:43:17 -07:00
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;
2015-08-18 21:08:03 -07:00
}
2015-07-08 22:52:25 -07:00
}
2016-03-18 12:43:17 -07:00
function getQuery(parentItem) {
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
Recursive: params.recursive !== 'false',
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: libraryBrowser.getDefaultPageSize()
}
};
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
var type = params.type;
if (type) {
pageData.query.IncludeItemTypes = type;
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
if (type == 'Audio') {
pageData.query.SortBy = 'Album,SortName';
}
}
2015-07-12 12:33:00 -07:00
2016-03-18 12:43:17 -07:00
var filters = params.filters;
if (type) {
pageData.query.Filters = filters;
}
2015-07-12 12:33:00 -07:00
2016-03-18 12:43:17 -07:00
if (parentItem) {
addCurrentItemToQuery(pageData.query, parentItem);
}
2015-07-12 12:33:00 -07:00
2016-03-18 12:43:17 -07:00
libraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData.query;
2015-07-12 12:33:00 -07:00
}
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
function getSavedQueryKey() {
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
return libraryBrowser.getSavedQueryKey();
}
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
function onListItemClick(e) {
2015-08-18 21:08:03 -07:00
2016-03-18 12:43:17 -07:00
var info = libraryBrowser.getListItemInfo(this);
2015-08-18 21:08:03 -07:00
2016-03-18 12:43:17 -07:00
if (info.mediaType == 'Photo') {
var query = getQuery();
2015-08-18 21:08:03 -07:00
2016-03-18 12:43:17 -07:00
require(['scripts/photos'], function () {
Photos.startSlideshow(view, query, info.id);
});
return false;
}
}
2015-08-18 21:08:03 -07:00
2016-03-18 12:43:17 -07:00
function reloadItems(parentItem) {
Dashboard.showLoadingMsg();
var query = getQuery(parentItem);
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
// 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
});
view.querySelector('.listTopPaging').innerHTML = pagingHtml;
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,
lazy: true
};
if (query.IncludeItemTypes == "MusicAlbum") {
posterOptions.overlayText = false;
posterOptions.showParentTitle = true;
2016-03-29 20:10:01 -07:00
posterOptions.showTitle = true;
2016-03-18 12:43:17 -07:00
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;
posterOptions.showTitle = true;
posterOptions.overlayPlayButton = true;
}
// Poster
html = libraryBrowser.getPosterViewHtml(posterOptions);
2015-08-18 21:08:03 -07:00
}
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
var elem = view.querySelector('#items');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
$('.btnNextPage', view).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(parentItem);
});
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
$('.btnPreviousPage', view).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(parentItem);
});
Dashboard.hideLoadingMsg();
2015-07-08 22:52:25 -07:00
});
2016-03-18 12:43:17 -07:00
}
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
$(view).on('click', '.mediaItem', onListItemClick);
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
view.addEventListener('viewbeforeshow', function (e) {
if (params.parentId) {
ApiClient.getItem(Dashboard.getCurrentUserId(), params.parentId).then(function (parent) {
LibraryMenu.setTitle(parent.Name);
2015-07-08 22:52:25 -07:00
2016-05-12 12:21:43 -07:00
reloadItems(parent);
2016-03-18 12:43:17 -07:00
});
}
2015-08-18 21:08:03 -07:00
2016-05-12 12:21:43 -07:00
else {
2016-03-18 12:43:17 -07:00
reloadItems();
}
});
};
2015-07-12 12:33:00 -07:00
2015-07-08 22:52:25 -07:00
2016-03-18 12:43:17 -07:00
});