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

396 lines
12 KiB
JavaScript
Raw Normal View History

2016-07-29 23:23:56 -07:00
define(['listView', 'cardBuilder', 'emby-itemscontainer'], function (listView, cardBuilder) {
2016-10-22 22:11:46 -07:00
'use strict';
2013-03-27 15:29:37 -07:00
2015-08-18 21:08:03 -07:00
function renderItems(page, item) {
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
var sections = [];
2013-04-16 22:36:56 -07:00
2016-08-13 13:54:29 -07:00
if (item.ArtistCount) {
sections.push({
name: Globalize.translate('TabArtists'),
type: 'MusicArtist'
});
}
2016-09-16 05:21:22 -07:00
if (item.ProgramCount && item.Type == 'Person') {
2016-08-13 13:54:29 -07:00
2016-09-14 09:20:03 -07:00
sections.push({
name: Globalize.translate('HeaderUpcomingOnTV'),
type: 'Program'
});
}
if (item.MovieCount) {
2013-04-16 22:36:56 -07:00
2015-08-18 21:08:03 -07:00
sections.push({
name: Globalize.translate('TabMovies'),
type: 'Movie'
});
}
2013-04-16 22:36:56 -07:00
if (item.SeriesCount) {
2013-04-16 22:36:56 -07:00
2015-08-18 21:08:03 -07:00
sections.push({
name: Globalize.translate('TabSeries'),
type: 'Series'
});
}
2013-04-16 22:36:56 -07:00
if (item.EpisodeCount) {
2013-04-16 22:36:56 -07:00
2015-08-18 21:08:03 -07:00
sections.push({
name: Globalize.translate('TabEpisodes'),
type: 'Episode'
});
}
2013-04-17 21:45:00 -07:00
if (item.TrailerCount) {
2016-03-19 20:38:02 -07:00
sections.push({
name: Globalize.translate('TabTrailers'),
type: 'Trailer'
});
}
2013-04-16 22:36:56 -07:00
if (item.GameCount) {
2015-08-18 21:08:03 -07:00
sections.push({
name: Globalize.translate('TabGames'),
type: 'Game'
});
}
2013-04-16 22:36:56 -07:00
if (item.AlbumCount) {
2013-04-16 22:36:56 -07:00
2015-08-18 21:08:03 -07:00
sections.push({
name: Globalize.translate('TabAlbums'),
type: 'MusicAlbum'
});
}
if (item.SongCount) {
2015-08-18 21:08:03 -07:00
sections.push({
name: Globalize.translate('TabSongs'),
type: 'Audio'
});
}
if (item.MusicVideoCount) {
2015-08-18 21:08:03 -07:00
sections.push({
name: Globalize.translate('TabMusicVideos'),
type: 'MusicVideo'
});
2015-08-18 21:08:03 -07:00
}
2015-08-18 21:08:03 -07:00
var elem = page.querySelector('#childrenContent');
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
elem.innerHTML = sections.map(function (section) {
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
var html = '';
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
html += '<div class="homePageSection" data-type="' + section.type + '">';
2013-04-16 22:36:56 -07:00
2015-08-18 21:08:03 -07:00
html += '<div>';
html += '<h1 class="listHeader" style="display:inline-block;vertical-align:middle;">';
html += section.name;
html += '</h1>';
2016-06-04 20:50:07 -07:00
html += '<a href="#" class="clearLink hide" style="margin-left:1em;vertical-align:middle;"><button is="emby-button" type="button" class="raised more mini noIcon">' + Globalize.translate('ButtonMore') + '</button></a>';
2015-08-18 21:08:03 -07:00
html += '</div>';
2013-04-17 21:45:00 -07:00
2016-07-16 11:02:39 -07:00
html += '<div is="emby-itemscontainer" class="itemsContainer">';
2015-08-18 21:08:03 -07:00
html += '</div>';
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
html += '</div>';
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
return html;
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
}).join('');
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
var sectionElems = elem.querySelectorAll('.homePageSection');
for (var i = 0, length = sectionElems.length; i < length; i++) {
renderSection(page, item, sectionElems[i], sectionElems[i].getAttribute('data-type'));
}
}
2013-04-19 16:57:23 -07:00
2015-08-18 21:08:03 -07:00
function renderSection(page, item, element, type) {
2013-04-19 16:57:23 -07:00
2015-08-18 21:08:03 -07:00
switch (type) {
2013-04-19 17:44:35 -07:00
2016-09-14 09:20:03 -07:00
case 'Program':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "Program",
PersonTypes: "",
ArtistIds: "",
Limit: 10
}, {
shape: "backdrop",
showTitle: true,
centerText: true,
overlayMoreButton: true,
preferThumb: true,
overlayText: false,
2016-09-30 11:43:59 -07:00
showAirTime: true,
showAirDateTime: true,
showChannelName: true
2016-09-14 09:20:03 -07:00
});
break;
2015-08-18 21:08:03 -07:00
case 'Movie':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "Movie",
PersonTypes: "",
ArtistIds: "",
Limit: 10
}, {
2016-07-29 23:41:51 -07:00
shape: "portrait",
2015-08-18 21:08:03 -07:00
showTitle: true,
centerText: true,
2016-09-14 09:20:03 -07:00
overlayMoreButton: true,
overlayText: false
2015-08-18 21:08:03 -07:00
});
break;
case 'MusicVideo':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "MusicVideo",
PersonTypes: "",
ArtistIds: "",
Limit: 10
}, {
2016-07-29 23:41:51 -07:00
shape: "portrait",
2015-08-18 21:08:03 -07:00
showTitle: true,
centerText: true,
overlayPlayButton: true
});
break;
case 'Game':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "Game",
PersonTypes: "",
ArtistIds: "",
Limit: 10
}, {
2016-07-29 23:41:51 -07:00
shape: "portrait",
2015-08-18 21:08:03 -07:00
showTitle: true,
2015-08-18 23:12:58 -07:00
centerText: true,
overlayMoreButton: true
2015-08-18 21:08:03 -07:00
});
break;
case 'Trailer':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "Trailer",
PersonTypes: "",
ArtistIds: "",
Limit: 10
}, {
2016-07-29 23:41:51 -07:00
shape: "portrait",
2015-08-18 21:08:03 -07:00
showTitle: true,
centerText: true,
overlayPlayButton: true
});
break;
case 'Series':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "Series",
PersonTypes: "",
ArtistIds: "",
Limit: 10
}, {
2016-07-29 23:41:51 -07:00
shape: "portrait",
2015-08-18 21:08:03 -07:00
showTitle: true,
2015-08-18 23:12:58 -07:00
centerText: true,
overlayMoreButton: true
2015-08-18 21:08:03 -07:00
});
break;
case 'MusicAlbum':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "MusicAlbum",
PersonTypes: "",
ArtistIds: "",
Limit: 8
}, {
2016-07-29 23:41:51 -07:00
shape: "square",
2015-08-18 21:08:03 -07:00
playFromHere: true,
showTitle: true,
showParentTitle: true,
2016-08-13 13:54:29 -07:00
coverImage: true,
2016-08-13 17:52:02 -07:00
centerText: true,
overlayPlayButton: true
2016-08-13 13:54:29 -07:00
});
break;
case 'MusicArtist':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "MusicArtist",
PersonTypes: "",
ArtistIds: "",
Limit: 8
}, {
shape: "square",
playFromHere: true,
showTitle: true,
showParentTitle: true,
coverImage: true,
2016-08-13 17:52:02 -07:00
centerText: true,
overlayPlayButton: true
2015-08-18 21:08:03 -07:00
});
break;
case 'Episode':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "Episode",
PersonTypes: "",
ArtistIds: "",
Limit: 6
}, {
2016-07-29 23:41:51 -07:00
shape: "backdrop",
2015-08-18 21:08:03 -07:00
showTitle: true,
showParentTitle: true,
centerText: true,
overlayPlayButton: true
});
break;
case 'Audio':
loadItems(element, item, type, {
MediaTypes: "",
IncludeItemTypes: "Audio",
PersonTypes: "",
ArtistIds: "",
2015-08-20 20:21:27 -07:00
Limit: 30
2015-08-18 21:08:03 -07:00
}, {
playFromHere: true,
2016-07-15 22:05:40 -07:00
action: 'playallfromhere',
2015-08-18 21:08:03 -07:00
smallIcon: true
});
break;
2013-04-19 17:44:35 -07:00
2015-08-18 21:08:03 -07:00
default:
break;
}
2013-04-16 22:36:56 -07:00
}
2015-08-18 21:08:03 -07:00
function loadItems(element, item, type, query, listOptions) {
2013-03-27 21:27:15 -07:00
2015-08-18 21:08:03 -07:00
query = getQuery(query, item);
2013-03-27 21:27:15 -07:00
2015-12-14 08:43:03 -07:00
getItemsFunction(query, item)(query.StartIndex, query.Limit, query.Fields).then(function (result) {
2013-04-12 11:22:40 -07:00
2015-08-18 21:08:03 -07:00
var html = '';
2013-04-12 11:22:40 -07:00
2015-08-18 21:08:03 -07:00
if (query.Limit && result.TotalRecordCount > query.Limit) {
// Add more button
var link = element.querySelector('a');
link.classList.remove('hide');
link.setAttribute('href', getMoreItemsHref(item, type));
} else {
element.querySelector('a').classList.add('hide');
2013-04-18 22:08:18 -07:00
}
2013-04-12 11:22:40 -07:00
2015-08-18 21:08:03 -07:00
listOptions.items = result.Items;
2016-07-29 23:23:56 -07:00
var itemsContainer = element.querySelector('.itemsContainer');
2013-04-12 11:22:40 -07:00
2015-08-18 21:08:03 -07:00
if (type == 'Audio') {
2016-07-15 22:05:40 -07:00
html = listView.getListViewHtml(listOptions);
2016-07-29 23:23:56 -07:00
itemsContainer.classList.remove('vertical-wrap');
itemsContainer.classList.add('vertical-list');
2015-08-18 21:08:03 -07:00
} else {
2016-07-29 23:23:56 -07:00
html = cardBuilder.getCardsHtml(listOptions);
itemsContainer.classList.add('vertical-wrap');
itemsContainer.classList.remove('vertical-list');
2013-04-18 22:08:18 -07:00
}
2013-04-12 11:22:40 -07:00
2015-08-18 21:08:03 -07:00
itemsContainer.innerHTML = html;
2013-04-12 11:22:40 -07:00
2015-08-18 21:08:03 -07:00
ImageLoader.lazyChildren(itemsContainer);
});
2013-04-10 10:36:34 -07:00
}
2013-04-02 13:02:23 -07:00
2015-08-18 21:08:03 -07:00
function getMoreItemsHref(item, type) {
2016-03-18 12:43:17 -07:00
return 'secondaryitems.html?type=' + type + '&parentId=' + item.Id;
2013-04-10 10:36:34 -07:00
}
2013-04-02 13:02:23 -07:00
2015-08-18 21:08:03 -07:00
function addCurrentItemToQuery(query, item) {
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
if (item.Type == "Person") {
query.PersonIds = item.Id;
2013-04-17 21:45:00 -07:00
}
2015-08-18 21:08:03 -07:00
else if (item.Type == "Genre") {
query.Genres = item.Name;
2013-04-17 21:45:00 -07:00
}
2015-08-18 21:08:03 -07:00
else if (item.Type == "MusicGenre") {
query.Genres = item.Name;
2013-06-10 20:31:00 -07:00
}
2015-08-18 21:08:03 -07:00
else if (item.Type == "GameGenre") {
query.Genres = item.Name;
2013-07-01 10:17:33 -07:00
}
2015-08-18 21:08:03 -07:00
else if (item.Type == "Studio") {
query.StudioIds = item.Id;
2013-04-17 21:45:00 -07:00
}
2015-08-18 21:08:03 -07:00
else if (item.Type == "MusicArtist") {
query.ArtistIds = item.Id;
2013-04-24 07:05:47 -07:00
}
2013-04-25 20:31:10 -07:00
}
2013-04-17 21:45:00 -07:00
2015-08-18 21:08:03 -07:00
function getQuery(options, item) {
2015-02-02 11:14:02 -07:00
var query = {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "",
Recursive: true,
2016-08-01 22:55:52 -07:00
Fields: "AudioInfo,SeriesInfo,ParentId,PrimaryImageAspectRatio,BasicSyncInfo",
2015-02-02 11:14:02 -07:00
Limit: LibraryBrowser.getDefaultPageSize(),
StartIndex: 0,
CollapseBoxSetItems: false
};
2016-06-02 10:43:29 -07:00
query = Object.assign(query, options || {});
2015-02-02 11:14:02 -07:00
if (query.IncludeItemTypes == "Audio") {
query.SortBy = "AlbumArtist,Album,SortName";
}
2015-08-18 21:08:03 -07:00
addCurrentItemToQuery(query, item);
2015-02-02 11:14:02 -07:00
2015-04-25 20:25:07 -07:00
return query;
}
2015-08-18 21:08:03 -07:00
function getItemsFunction(options, item) {
2015-04-25 20:25:07 -07:00
2015-08-18 21:08:03 -07:00
var query = getQuery(options, item);
2015-04-25 20:25:07 -07:00
2015-02-02 11:14:02 -07:00
return function (index, limit, fields) {
query.StartIndex = index;
query.Limit = limit;
2015-07-15 10:20:08 -07:00
if (fields) {
query.Fields += "," + fields;
}
2015-02-02 11:14:02 -07:00
return ApiClient.getItems(Dashboard.getCurrentUserId(), query);
};
}
2015-08-18 21:08:03 -07:00
window.ItemsByName = {
renderItems: renderItems
};
2013-03-27 15:29:37 -07:00
});