1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/scripts/itembynamedetailpage.js

551 lines
16 KiB
JavaScript
Raw Normal View History

2013-04-10 13:36:34 -04:00
(function ($, document, LibraryBrowser) {
2013-03-27 18:29:37 -04:00
2013-04-18 00:45:00 -04:00
var currentItem;
2013-04-24 10:05:47 -04:00
var shape;
2014-08-21 11:55:35 -04:00
var currentItemsQuery;
2013-04-18 00:45:00 -04:00
2013-05-31 21:48:41 -04:00
function getPromise() {
2013-04-10 13:36:34 -04:00
2014-06-28 15:35:30 -04:00
var id = getParameterByName('id');
if (id) {
return ApiClient.getItem(Dashboard.getCurrentUserId(), id);
}
2014-08-18 21:42:53 -04:00
var name = getParameterByName('genre');
2013-04-17 01:36:56 -04:00
2013-05-31 21:48:41 -04:00
if (name) {
return ApiClient.getGenre(name, Dashboard.getCurrentUserId());
}
2013-04-25 23:31:10 -04:00
2013-06-10 23:31:00 -04:00
name = getParameterByName('musicgenre');
if (name) {
return ApiClient.getMusicGenre(name, Dashboard.getCurrentUserId());
}
2013-07-01 13:17:33 -04:00
name = getParameterByName('gamegenre');
if (name) {
return ApiClient.getGameGenre(name, Dashboard.getCurrentUserId());
}
2013-11-21 15:48:26 -05:00
name = getParameterByName('musicartist');
2013-04-22 00:38:03 -04:00
2013-05-31 21:48:41 -04:00
if (name) {
return ApiClient.getArtist(name, Dashboard.getCurrentUserId());
2013-03-27 18:29:37 -04:00
}
2013-05-31 21:48:41 -04:00
else {
throw new Error('Invalid request');
}
}
function reload(page) {
Dashboard.showLoadingMsg();
2013-03-27 18:29:37 -04:00
2013-05-31 21:48:41 -04:00
getPromise().done(function (item) {
2013-04-17 01:36:56 -04:00
2014-06-20 11:10:40 -04:00
var context = getParameterByName('context');
var editQuery = '?id=' + item.Id;
if (context) {
editQuery += '&context=' + context;
}
2013-04-18 00:45:00 -04:00
currentItem = item;
2014-08-17 01:38:13 -04:00
Backdrops.setBackdrops(page, [item]);
2014-06-28 15:35:30 -04:00
renderHeader(page, item, context);
2013-04-23 10:46:27 -04:00
2013-07-29 11:05:09 -04:00
var name = item.Name;
2013-03-27 21:27:15 -07:00
2013-04-10 13:36:34 -04:00
Dashboard.setPageTitle(name);
$('.itemName', page).html(name);
2013-03-27 21:27:15 -07:00
2014-06-28 15:35:30 -04:00
renderDetails(page, item, context);
renderTabs(page, item, context);
2013-03-27 21:27:15 -07:00
2014-04-13 13:27:13 -04:00
$(page).trigger('displayingitem', [{
2013-05-10 08:18:07 -04:00
2014-04-13 13:27:13 -04:00
item: item,
2014-06-20 11:10:40 -04:00
context: context
2014-04-13 13:27:13 -04:00
}]);
2013-05-10 08:18:07 -04:00
2013-06-27 09:31:49 -04:00
Dashboard.getCurrentUser().done(function (user) {
2014-03-29 11:40:32 -04:00
if (MediaController.canPlay(item)) {
$('.btnPlay', page).show();
} else {
$('.btnPlay', page).hide();
}
2014-06-20 11:10:40 -04:00
var editImagesHref = user.Configuration.IsAdministrator ? 'edititemimages.html' + editQuery : null;
2014-08-17 01:38:13 -04:00
$('#itemImage', page).html(LibraryBrowser.getDetailImageHtml(item, editImagesHref, true));
2014-08-21 22:24:38 -04:00
if (LibraryBrowser.getMoreCommands(item, user).length) {
$('.btnMoreCommands', page).show();
2013-06-27 09:31:49 -04:00
} else {
2014-08-21 22:24:38 -04:00
$('.btnMoreCommands', page).show();
2013-06-27 09:31:49 -04:00
}
});
2013-04-10 13:36:34 -04:00
Dashboard.hideLoadingMsg();
});
}
2013-03-27 21:27:15 -07:00
2014-06-28 15:35:30 -04:00
function renderHeader(page, item, context) {
2013-04-25 23:31:10 -04:00
2013-04-23 10:46:27 -04:00
$('.itemTabs', page).hide();
if (context == "movies" && item.Type == "Genre") {
$('#movieGenreTabs', page).show();
}
if (context == "movies" && item.Type == "Person") {
$('#moviePeopleTabs', page).show();
}
if (context == "movies" && item.Type == "Studio") {
$('#movieStudioTabs', page).show();
}
if (context == "tv" && item.Type == "Studio") {
$('#tvStudioTabs', page).show();
}
if (context == "tv" && item.Type == "Genre") {
$('#tvGenreTabs', page).show();
}
if (context == "tv" && item.Type == "Person") {
$('#tvPeopleTabs', page).show();
}
2013-06-10 23:31:00 -04:00
if (context == "music" && item.Type == "MusicGenre") {
2013-04-23 10:46:27 -04:00
$('#musicGenreTabs', page).show();
}
2013-11-21 15:48:26 -05:00
if (context == "music" && item.Type == "MusicArtist") {
2013-04-23 22:50:43 -04:00
$('#artistTabs', page).show();
}
2013-07-01 13:17:33 -04:00
if (context == "games" && item.Type == "GameGenre") {
2013-04-28 14:39:38 -04:00
$('#gameGenreTabs', page).show();
}
if (context == "games" && item.Type == "Studio") {
$('#gameStudioTabs', page).show();
}
2013-04-23 10:46:27 -04:00
}
2014-06-28 15:35:30 -04:00
function renderTabs(page, item, context) {
2013-04-17 01:36:56 -04:00
var html = '<fieldset data-role="controlgroup" data-type="horizontal" class="libraryTabs">';
2013-04-18 00:45:00 -04:00
html += '<legend></legend>';
2013-04-17 01:36:56 -04:00
if (item.MovieCount) {
2013-04-17 01:36:56 -04:00
html += '<input type="radio" name="ibnItems" id="radioMovies" class="context-movies" value="on">';
2014-08-24 11:48:06 -04:00
html += '<label for="radioMovies">'+Globalize.translate('TabMovies')+'</label>';
}
2013-04-17 01:36:56 -04:00
if (item.SeriesCount) {
2013-04-17 01:36:56 -04:00
html += '<input type="radio" name="ibnItems" id="radioShows" class="context-tv" value="on">';
2014-08-24 11:48:06 -04:00
html += '<label for="radioShows">'+Globalize.translate('TabSeries')+'</label>';
}
2013-04-17 01:36:56 -04:00
if (item.EpisodeCount) {
2013-04-17 01:36:56 -04:00
html += '<input type="radio" name="ibnItems" id="radioEpisodes" class="context-tv" value="on">';
2014-08-24 11:48:06 -04:00
html += '<label for="radioEpisodes">'+Globalize.translate('TabEpisodes')+'</label>';
}
2013-04-18 00:45:00 -04:00
if (item.TrailerCount) {
2013-04-17 01:36:56 -04:00
html += '<input type="radio" name="ibnItems" id="radioTrailers" class="context-movies" value="on">';
2014-08-24 11:48:06 -04:00
html += '<label for="radioTrailers">'+Globalize.translate('TabTrailers')+'</label>';
}
2013-04-17 01:36:56 -04:00
if (item.GameCount) {
html += '<input type="radio" name="ibnItems" id="radioGames" class="context-games" value="on">';
2014-08-24 11:48:06 -04:00
html += '<label for="radioGames">'+Globalize.translate('TabGames')+'</label>';
}
2013-04-17 01:36:56 -04:00
if (item.AlbumCount) {
2013-04-17 01:36:56 -04:00
html += '<input type="radio" name="ibnItems" id="radioAlbums" class="context-music" value="on">';
2014-08-24 11:48:06 -04:00
html += '<label for="radioAlbums">'+Globalize.translate('TabAlbums')+'</label>';
}
if (item.SongCount) {
html += '<input type="radio" name="ibnItems" id="radioSongs" class="context-music" value="on">';
2014-08-24 11:48:06 -04:00
html += '<label for="radioSongs">'+Globalize.translate('TabSongs')+'</label>';
}
if (item.MusicVideoCount) {
html += '<input type="radio" name="ibnItems" id="radioMusicVideos" class="context-music" value="on">';
2014-08-24 11:48:06 -04:00
html += '<label for="radioMusicVideos">'+Globalize.translate('TabMusicVideos')+'</label>';
}
html += '</fieldset>';
var elem = $('#itemTabs', page).html(html).trigger('create');
2013-04-17 01:36:56 -04:00
bindRadioEvents(page);
2013-04-18 00:45:00 -04:00
var selectedRadio = null;
2013-04-18 00:45:00 -04:00
if (context) {
selectedRadio = $('.context-' + context + ':first', elem);
}
if (selectedRadio && selectedRadio.length) {
selectedRadio.attr("checked", "checked").checkboxradio("refresh").trigger('click');
} else {
$('input:first', elem).attr("checked", "checked").checkboxradio("refresh").trigger('click');
}
2013-04-18 00:45:00 -04:00
}
function bindRadioEvents(page) {
$("#radioMusicVideos", page).on("click", function () {
shape = "poster";
loadItems(page, {
MediaTypes: "",
IncludeItemTypes: "MusicVideo",
PersonTypes: "",
Artists: ""
});
});
2013-04-18 00:45:00 -04:00
$("#radioMovies", page).on("click", function () {
2013-05-05 22:23:19 -04:00
shape = "poster";
2013-04-24 10:05:47 -04:00
loadItems(page, {
2013-04-24 16:28:42 -04:00
MediaTypes: "",
2013-04-24 10:05:47 -04:00
IncludeItemTypes: "Movie",
PersonTypes: "",
Artists: ""
});
2013-04-18 00:45:00 -04:00
});
$("#radioShows", page).on("click", function () {
2013-04-17 01:36:56 -04:00
2013-05-05 22:23:19 -04:00
shape = "poster";
2013-04-24 10:05:47 -04:00
loadItems(page, {
2013-04-24 16:28:42 -04:00
MediaTypes: "",
2013-04-24 10:05:47 -04:00
IncludeItemTypes: "Series",
PersonTypes: "",
Artists: ""
});
2013-04-18 00:45:00 -04:00
});
$("#radioTrailers", page).on("click", function () {
2013-04-24 10:05:47 -04:00
shape = "poster";
loadItems(page, {
2013-04-24 16:28:42 -04:00
MediaTypes: "",
2013-04-24 10:05:47 -04:00
IncludeItemTypes: "Trailer",
PersonTypes: "",
Artists: ""
});
2013-04-18 00:45:00 -04:00
});
$("#radioGames", page).on("click", function () {
2013-04-24 10:05:47 -04:00
shape = "poster";
loadItems(page, {
2013-04-24 16:28:42 -04:00
IncludeItemTypes: "",
MediaTypes: "Game",
2013-04-24 10:05:47 -04:00
PersonTypes: "",
Artists: ""
});
2013-04-18 00:45:00 -04:00
});
2013-05-04 00:38:38 -04:00
$("#radioEpisodes", page).on("click", function () {
2013-04-18 00:45:00 -04:00
2013-04-24 10:05:47 -04:00
shape = "backdrop";
loadItems(page, {
2013-04-24 16:28:42 -04:00
MediaTypes: "",
2013-04-24 10:05:47 -04:00
IncludeItemTypes: "Episode",
2013-05-04 00:38:38 -04:00
PersonTypes: "",
2013-04-24 10:05:47 -04:00
Artists: ""
});
2013-04-17 01:36:56 -04:00
});
2013-04-19 19:57:23 -04:00
$("#radioAlbums", page).on("click", function () {
2013-04-25 21:17:22 -04:00
shape = "square";
2013-04-24 10:05:47 -04:00
loadItems(page, {
2013-04-24 16:28:42 -04:00
MediaTypes: "",
2013-04-24 10:05:47 -04:00
IncludeItemTypes: "MusicAlbum",
2013-04-25 19:28:01 -04:00
PersonTypes: "",
2013-04-24 10:05:47 -04:00
Artists: ""
});
2013-04-19 19:57:23 -04:00
});
2013-04-19 20:44:35 -04:00
$("#radioSongs", page).on("click", function () {
2013-04-24 10:05:47 -04:00
loadItems(page, {
2013-04-24 16:28:42 -04:00
MediaTypes: "",
2013-04-24 10:05:47 -04:00
IncludeItemTypes: "Audio",
2013-04-25 19:28:01 -04:00
PersonTypes: "",
2013-04-24 10:05:47 -04:00
Artists: ""
});
2013-04-19 20:44:35 -04:00
});
2013-04-17 01:36:56 -04:00
}
2014-06-28 15:35:30 -04:00
function renderDetails(page, item, context) {
2013-03-27 21:27:15 -07:00
2014-08-17 01:38:13 -04:00
//LibraryBrowser.renderDetailPageBackdrop(page, item);
LibraryBrowser.renderOverview($('.itemOverview', page), item);
2013-03-27 21:27:15 -07:00
2013-04-10 13:36:34 -04:00
renderUserDataIcons(page, item);
2013-04-14 11:14:10 -04:00
LibraryBrowser.renderLinks($('#itemLinks', page), item);
2013-04-12 14:22:40 -04:00
2014-06-28 15:35:30 -04:00
LibraryBrowser.renderGenres($('.itemGenres', page), item, context);
2013-06-10 21:28:41 -04:00
2013-04-12 14:22:40 -04:00
if (item.Type == "Person" && item.PremiereDate) {
2013-04-19 01:08:18 -04:00
try {
var birthday = parseISO8601Date(item.PremiereDate, { toLocal: true }).toDateString();
2013-04-12 14:22:40 -04:00
2014-08-24 11:48:06 -04:00
$('#itemBirthday', page).show().html(Globalize.translate('BirthDateValue').replace('{0}', birthday));
2013-04-19 01:08:18 -04:00
}
2013-04-19 20:44:35 -04:00
catch (err) {
2013-04-19 01:08:18 -04:00
$('#itemBirthday', page).hide();
}
2013-04-12 14:22:40 -04:00
} else {
$('#itemBirthday', page).hide();
}
if (item.Type == "Person" && item.EndDate) {
2013-04-19 01:08:18 -04:00
try {
var deathday = parseISO8601Date(item.EndDate, { toLocal: true }).toDateString();
2013-04-12 14:22:40 -04:00
2014-08-24 11:48:06 -04:00
$('#itemDeathDate', page).show().html(Globalize.translate('DeathDateValue').replace('{0}', deathday));
2013-04-19 01:08:18 -04:00
}
catch (err) {
$('#itemBirthday', page).hide();
}
2013-04-12 14:22:40 -04:00
} else {
}
if (item.Type == "Person" && item.ProductionLocations && item.ProductionLocations.length) {
2013-05-12 16:30:23 -04:00
var gmap = '<a class="textlink" target="_blank" href="https://maps.google.com/maps?q=' + item.ProductionLocations[0] + '">' + item.ProductionLocations[0] + '</a>';
2013-04-12 14:22:40 -04:00
2014-08-24 11:48:06 -04:00
$('#itemBirthLocation', page).show().html(Globalize.translate('BirthPlaceValue').replace('{0}', gmap)).trigger('create');
2013-04-12 14:22:40 -04:00
} else {
$('#itemBirthLocation', page).hide();
}
2013-04-10 13:36:34 -04:00
}
2013-04-02 13:02:23 -07:00
2013-04-10 13:36:34 -04:00
function renderUserDataIcons(page, item) {
$('.userDataIcons', page).html(LibraryBrowser.getUserDataIconsHtml(item));
2013-04-10 13:36:34 -04:00
}
2013-04-02 13:02:23 -07:00
2013-04-18 00:45:00 -04:00
function addCurrentItemToQuery(query) {
if (currentItem.Type == "Person") {
query.Person = currentItem.Name;
}
else if (currentItem.Type == "Genre") {
query.Genres = currentItem.Name;
}
2013-06-10 23:31:00 -04:00
else if (currentItem.Type == "MusicGenre") {
query.Genres = currentItem.Name;
}
2013-07-01 13:17:33 -04:00
else if (currentItem.Type == "GameGenre") {
query.Genres = currentItem.Name;
}
2013-04-18 00:45:00 -04:00
else if (currentItem.Type == "Studio") {
query.Studios = currentItem.Name;
}
2013-11-21 15:48:26 -05:00
else if (currentItem.Type == "MusicArtist") {
2013-04-24 10:05:47 -04:00
query.Artists = currentItem.Name;
}
2013-04-25 23:31:10 -04:00
}
2013-04-18 00:45:00 -04:00
function loadItems(page, options) {
Dashboard.showLoadingMsg();
2013-04-18 00:45:00 -04:00
var query = {
SortBy: "SortName",
SortOrder: "Ascending",
2013-04-24 16:28:42 -04:00
IncludeItemTypes: "",
2013-04-18 00:45:00 -04:00
Recursive: true,
Fields: "AudioInfo,SeriesInfo,ParentId,PrimaryImageAspectRatio",
2013-05-03 15:34:25 -04:00
Limit: LibraryBrowser.getDefaultPageSize(),
StartIndex: 0,
CollapseBoxSetItems: false
2013-04-18 00:45:00 -04:00
};
query = $.extend(query, options || {});
2014-04-13 13:27:13 -04:00
2014-01-08 15:29:09 -05:00
if (query.IncludeItemTypes == "Audio") {
2014-08-22 13:26:58 -04:00
query.SortBy = "AlbumArtist,Album,SortName";
2014-01-08 15:29:09 -05:00
}
2013-04-18 00:45:00 -04:00
addCurrentItemToQuery(query);
2014-08-21 11:55:35 -04:00
currentItemsQuery = query;
2013-04-18 00:45:00 -04:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
2013-04-18 00:45:00 -04:00
var html = '';
2013-04-19 20:44:35 -04:00
if (result.TotalRecordCount > query.Limit) {
$('.listTopPaging', page).html(LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, true)).trigger('create');
$('.viewSettings', page).show();
} else {
$('.listTopPaging', page).html('');
$('.viewSettings', page).hide();
}
2013-04-18 00:45:00 -04:00
2014-05-09 15:43:06 -04:00
var screenWidth = $(window).width();
2013-05-12 21:54:06 -04:00
if (query.IncludeItemTypes == "Audio") {
2014-08-15 12:35:41 -04:00
html = LibraryBrowser.getListViewHtml({
items: result.Items,
2014-08-21 11:55:35 -04:00
smallIcon: true,
2014-08-30 10:26:29 -04:00
playFromHere: true,
defaultAction: 'playallfromhere'
2013-05-12 21:54:06 -04:00
});
}
else if (query.IncludeItemTypes == "Movie" || query.IncludeItemTypes == "Trailer") {
2013-05-12 21:54:06 -04:00
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'movies',
2014-01-15 00:01:58 -05:00
showTitle: true,
centerText: true
});
}
else if (query.IncludeItemTypes == "Episode") {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
showParentTitle: true,
2014-05-09 15:43:06 -04:00
overlayText: screenWidth >= 600
});
}
else if (query.IncludeItemTypes == "Series") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'tv'
});
}
else if (query.IncludeItemTypes == "MusicAlbum") {
2014-08-21 22:24:38 -04:00
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
2014-08-21 22:24:38 -04:00
shape: "square",
context: 'music',
2014-08-22 13:26:58 -04:00
playFromHere: true,
showTitle: true,
showParentTitle: true
});
}
else {
2014-08-17 01:38:13 -04:00
html = LibraryBrowser.getListViewHtml({
2013-05-12 21:54:06 -04:00
items: result.Items,
2014-08-17 01:38:13 -04:00
smallIcon: true
2013-05-12 21:54:06 -04:00
});
}
2013-04-18 00:45:00 -04:00
2013-04-19 12:28:06 -04:00
html += LibraryBrowser.getPagingHtml(query, result.TotalRecordCount);
2013-04-18 00:45:00 -04:00
2014-08-01 22:34:45 -04:00
$('#items', page).html(html).trigger('create').createCardMenus();
2013-04-18 00:45:00 -04:00
2013-04-19 01:08:18 -04:00
$('.btnNextPage', page).on('click', function () {
2013-04-18 00:45:00 -04:00
query.StartIndex = query.StartIndex + query.Limit;
loadItems(page, query);
});
2013-04-19 01:08:18 -04:00
$('.btnPreviousPage', page).on('click', function () {
2013-04-18 00:45:00 -04:00
query.StartIndex = query.StartIndex - query.Limit;
loadItems(page, query);
});
2013-04-27 18:52:41 -04:00
$('.selectPageSize', page).on('change', function () {
query.Limit = parseInt(this.value);
query.StartIndex = 0;
2013-07-04 12:10:05 -04:00
loadItems(page, query);
2013-04-27 18:52:41 -04:00
});
Dashboard.hideLoadingMsg();
2013-04-18 00:45:00 -04:00
});
}
2013-05-29 00:00:24 -04:00
$(document).on('pageinit', "#itemByNameDetailPage", function () {
var page = this;
$('.btnPlay', page).on('click', function () {
2013-08-08 10:53:25 -04:00
var userdata = currentItem.UserData || {};
2014-03-29 11:40:32 -04:00
LibraryBrowser.showPlayMenu(this, currentItem.Id, currentItem.Type, false, "Audio", userdata.PlaybackPositionTicks);
2013-05-29 00:00:24 -04:00
});
2014-08-21 11:55:35 -04:00
$('.itemsContainer', page).on('playallfromhere', function (e, index) {
LibraryBrowser.playAllFromHere(currentItemsQuery, index);
}).on('queueallfromhere', function (e, index) {
LibraryBrowser.queueAllFromHere(currentItemsQuery, index);
});
2014-08-21 22:24:38 -04:00
$('.btnMoreCommands', page).on('click', function () {
var button = this;
Dashboard.getCurrentUser().done(function (user) {
LibraryBrowser.showMoreCommands(button, currentItem.Id, LibraryBrowser.getMoreCommands(currentItem, user));
});
});
2013-05-29 00:00:24 -04:00
}).on('pageshow', "#itemByNameDetailPage", function () {
2013-04-18 00:45:00 -04:00
var page = this;
reload(page);
}).on('pagehide', "#itemByNameDetailPage", function () {
currentItem = null;
2013-04-10 13:36:34 -04:00
});
2013-03-27 21:27:15 -07:00
2013-03-27 18:29:37 -04:00
2013-04-10 13:36:34 -04:00
})(jQuery, document, LibraryBrowser);