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

551 lines
16 KiB
JavaScript
Raw Normal View History

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