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

277 lines
8.6 KiB
JavaScript
Raw Normal View History

2016-11-24 23:58:38 -07:00
define(['libraryBrowser', 'listView', 'cardBuilder', 'imageLoader', 'emby-itemscontainer'], function (libraryBrowser, listView, cardBuilder, imageLoader) {
2016-10-22 22:11:46 -07:00
'use strict';
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-11-25 11:25:01 -07:00
if (params.parentId) {
query.ParentId = params.parentId;
}
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',
2016-08-01 22:55:52 -07:00
Fields: "PrimaryImageAspectRatio,SortName,BasicSyncInfo",
2016-03-18 12:43:17 -07:00
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-06-18 11:26:21 -07:00
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
2016-03-18 12:43:17 -07:00
function onListItemClick(e) {
2015-08-18 21:08:03 -07:00
2016-06-18 11:26:21 -07:00
var mediaItem = parentWithClass(e.target, 'mediaItem');
if (mediaItem) {
var info = libraryBrowser.getListItemInfo(mediaItem);
2015-08-18 21:08:03 -07:00
2016-06-18 11:26:21 -07:00
if (info.mediaType == 'Photo') {
var query = getQuery();
2015-08-18 21:08:03 -07:00
2016-06-18 11:26:21 -07:00
require(['scripts/photos'], function () {
Photos.startSlideshow(view, query, info.id);
});
return false;
}
2016-03-18 12:43:17 -07:00
}
}
2015-08-18 21:08:03 -07:00
2016-07-29 22:42:58 -07:00
function onViewStyleChange(parentItem) {
2016-12-14 23:41:10 -07:00
2016-07-29 22:42:58 -07:00
var query = getQuery(parentItem);
var itemsContainer = view.querySelector('#items');
if (query.IncludeItemTypes == "Audio") {
itemsContainer.classList.add('vertical-list');
itemsContainer.classList.remove('vertical-wrap');
} else {
itemsContainer.classList.remove('vertical-list');
itemsContainer.classList.add('vertical-wrap');
}
}
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
});
2016-12-14 23:41:10 -07:00
var i, length;
var elems;
elems = view.querySelectorAll('.paging');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].innerHTML = pagingHtml;
}
2016-03-18 12:43:17 -07:00
2016-07-29 22:42:58 -07:00
var itemsContainer = view.querySelector('#items');
2016-03-18 12:43:17 -07:00
if (query.IncludeItemTypes == "Audio") {
2016-07-29 22:42:58 -07:00
html = listView.getListViewHtml({
2016-03-18 12:43:17 -07:00
items: result.Items,
playFromHere: true,
2016-07-15 22:05:40 -07:00
action: 'playallfromhere',
2016-03-18 12:43:17 -07:00
smallIcon: true
2016-07-29 22:42:58 -07:00
});
2016-03-18 12:43:17 -07:00
} else {
2016-07-29 22:42:58 -07:00
2016-03-18 12:43:17 -07:00
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
2016-07-29 13:06:58 -07:00
html = cardBuilder.getCardsHtml(posterOptions);
2015-08-18 21:08:03 -07:00
}
2015-07-08 22:52:25 -07:00
2016-12-14 23:41:10 -07:00
itemsContainer.innerHTML = html;
2016-11-24 23:58:38 -07:00
imageLoader.lazyChildren(itemsContainer);
2015-07-08 22:52:25 -07:00
2016-06-18 11:26:21 -07:00
function onNextPageClick() {
2016-03-18 12:43:17 -07:00
query.StartIndex += query.Limit;
2016-06-18 11:26:21 -07:00
reloadItems(view);
}
2015-07-08 22:52:25 -07:00
2016-06-18 11:26:21 -07:00
function onPreviousPageClick() {
2016-03-18 12:43:17 -07:00
query.StartIndex -= query.Limit;
2016-06-18 11:26:21 -07:00
reloadItems(view);
}
elems = view.querySelectorAll('.btnNextPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onNextPageClick);
}
elems = view.querySelectorAll('.btnPreviousPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onPreviousPageClick);
}
2016-03-18 12:43:17 -07:00
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-06-18 11:26:21 -07:00
view.addEventListener('click', onListItemClick);
2015-07-08 22:52:25 -07:00
function getItemPromise() {
2016-12-06 01:24:29 -07:00
var id = params.genreId || params.studioId || params.artistId || params.personId || params.parentId;
if (id) {
return ApiClient.getItem(Dashboard.getCurrentUserId(), id);
}
var name = params.genre;
if (name) {
return ApiClient.getGenre(name, Dashboard.getCurrentUserId());
}
name = params.musicgenre;
if (name) {
return ApiClient.getMusicGenre(name, Dashboard.getCurrentUserId());
}
name = params.gamegenre;
if (name) {
return ApiClient.getGameGenre(name, Dashboard.getCurrentUserId());
}
return null;
}
2016-03-18 12:43:17 -07:00
view.addEventListener('viewbeforeshow', function (e) {
2016-11-25 11:25:01 -07:00
var parentPromise = getItemPromise();
2016-11-25 11:25:01 -07:00
if (parentPromise) {
parentPromise.then(function (parent) {
2016-03-18 12:43:17 -07:00
LibraryMenu.setTitle(parent.Name);
2015-07-08 22:52:25 -07:00
2016-07-29 22:42:58 -07:00
onViewStyleChange(parent);
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-07-29 22:42:58 -07:00
onViewStyleChange();
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
});