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

379 lines
11 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-10 10:36:34 -07:00
function reload(page) {
2013-03-27 15:29:37 -07:00
Dashboard.showLoadingMsg();
2013-04-10 10:36:34 -07:00
var getItemPromise;
2013-04-16 22:36:56 -07:00
var name = getParameterByName('person');
2013-03-27 15:29:37 -07:00
if (name) {
2013-04-21 21:38:03 -07:00
getItemPromise = ApiClient.getPerson(name, Dashboard.getCurrentUserId());
2013-04-10 10:36:34 -07:00
} else {
2013-04-16 22:36:56 -07:00
name = getParameterByName('studio');
if (name) {
2013-04-16 22:36:56 -07:00
2013-04-21 21:38:03 -07:00
getItemPromise = ApiClient.getStudio(name, Dashboard.getCurrentUserId());
2013-04-16 22:36:56 -07:00
} else {
2013-04-16 22:36:56 -07:00
name = getParameterByName('genre');
if (name) {
2013-04-21 21:38:03 -07:00
getItemPromise = ApiClient.getGenre(name, Dashboard.getCurrentUserId());
}
else {
2013-04-21 21:38:03 -07:00
name = getParameterByName('artist');
if (name) {
getItemPromise = ApiClient.getArtist(name, Dashboard.getCurrentUserId());
}
else {
throw new Error('Invalid request');
}
}
}
2013-03-27 15:29:37 -07:00
}
2013-04-21 21:38:03 -07:00
getItemPromise.done(function (item) {
2013-04-16 22:36:56 -07:00
2013-04-17 21:45:00 -07:00
currentItem = item;
2013-04-23 07:46:27 -07:00
renderHeader(page, item);
name = item.Name;
2013-03-27 21:27:15 -07:00
2013-04-10 10:36:34 -07:00
$('#itemImage', page).html(LibraryBrowser.getDetailImageHtml(item));
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
2013-04-10 10:36:34 -07:00
renderDetails(page, item);
2013-04-16 22:36:56 -07:00
renderTabs(page, item);
2013-03-27 21:27:15 -07:00
2013-04-10 10:36:34 -07:00
Dashboard.hideLoadingMsg();
});
}
2013-03-27 21:27:15 -07:00
2013-04-23 07:46:27 -07:00
function enableCustomHeader(page, text) {
var elem = $('.libraryPageHeader', page).show();
$('span', elem).html(text);
}
function renderHeader(page, item) {
var context = getParameterByName('context');
if (context == "movies") {
enableCustomHeader(page, "Movies");
$('#standardLogo', page).hide();
}
else if (context == "music") {
enableCustomHeader(page, "Music");
$('#standardLogo', page).hide();
}
else if (context == "tv") {
enableCustomHeader(page, "TV Shows");
$('#standardLogo', page).hide();
}
else if (context == "games") {
enableCustomHeader(page, "Games");
$('#standardLogo', page).hide();
}
else {
$('.libraryPageHeader', page).hide();
$('#standardLogo', page).show();
}
$('.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();
}
if (context == "music" && item.Type == "Genre") {
$('#musicGenreTabs', page).show();
}
}
2013-04-16 22:36:56 -07:00
function renderTabs(page, item) {
2013-04-17 09:46:52 -07:00
var promise;
2013-04-17 21:45:00 -07:00
2013-04-17 09:46:52 -07:00
if (item.Type == "Person") {
promise = ApiClient.getPersonItemCounts(Dashboard.getCurrentUserId(), item.Name);
}
else if (item.Type == "Genre") {
promise = ApiClient.getGenreItemCounts(Dashboard.getCurrentUserId(), item.Name);
}
else if (item.Type == "Studio") {
promise = ApiClient.getStudioItemCounts(Dashboard.getCurrentUserId(), item.Name);
2013-04-21 21:38:03 -07:00
}
else if (item.Type == "Artist") {
promise = ApiClient.getArtistItemCounts(Dashboard.getCurrentUserId(), item.Name);
}
else {
2013-04-17 09:46:52 -07:00
throw new Error("Unknown item type: " + item.Type);
2013-04-16 22:36:56 -07:00
}
2013-04-17 09:46:52 -07:00
promise.done(function (result) {
2013-04-16 22:36:56 -07:00
2013-04-16 23:03:47 -07:00
var html = '<fieldset data-role="controlgroup" data-type="horizontal" class="libraryTabs">';
2013-04-16 22:36:56 -07:00
html += '<legend></legend>';
if (result.MovieCount) {
2013-04-16 23:03:47 -07:00
html += '<input type="radio" name="ibnItems" id="radioMovies" value="on" data-mini="true">';
2013-04-16 22:36:56 -07:00
html += '<label for="radioMovies">Movies (' + result.MovieCount + ')</label>';
}
if (result.SeriesCount) {
2013-04-16 23:03:47 -07:00
html += '<input type="radio" name="ibnItems" id="radioShows" value="on" data-mini="true">';
2013-04-16 22:36:56 -07:00
html += '<label for="radioShows">TV Shows (' + result.SeriesCount + ')</label>';
}
2013-04-17 21:45:00 -07:00
2013-04-16 22:36:56 -07:00
if (result.EpisodeGuestStarCount) {
2013-04-16 23:03:47 -07:00
html += '<input type="radio" name="ibnItems" id="radioGuestStar" value="on" data-mini="true">';
2013-04-17 21:45:00 -07:00
html += '<label for="radioGuestStar">Guest Star (' + result.EpisodeGuestStarCount + ')</label>';
2013-04-16 22:36:56 -07:00
}
if (result.TrailerCount) {
html += '<input type="radio" name="ibnItems" id="radioTrailers" value="on" data-mini="true">';
html += '<label for="radioTrailers">Trailers (' + result.TrailerCount + ')</label>';
}
2013-04-16 22:36:56 -07:00
if (result.GameCount) {
2013-04-16 23:03:47 -07:00
html += '<input type="radio" name="ibnItems" id="radioGames" value="on" data-mini="true">';
2013-04-16 22:36:56 -07:00
html += '<label for="radioGames">Games (' + result.SeriesCount + ')</label>';
}
if (result.AlbumCount) {
html += '<input type="radio" name="ibnItems" id="radioAlbums" value="on" data-mini="true">';
html += '<label for="radioAlbums">Albums (' + result.AlbumCount + ')</label>';
}
if (result.SongCount) {
html += '<input type="radio" name="ibnItems" id="radioSongs" value="on" data-mini="true">';
html += '<label for="radioSongs">Songs (' + result.SongCount + ')</label>';
}
2013-04-16 22:36:56 -07:00
html += '</fieldset>';
2013-04-17 21:45:00 -07:00
var elem = $('#itemTabs', page).html(html).trigger('create');
bindRadioEvents(page);
$('input:first', elem).attr("checked", "checked").checkboxradio("refresh").trigger('click');
});
}
function bindRadioEvents(page) {
$("#radioMovies", page).on("click", function () {
loadItems(page, { IncludeItemTypes: "Movie" });
});
$("#radioShows", page).on("click", function () {
2013-04-16 22:36:56 -07:00
2013-04-17 21:45:00 -07:00
loadItems(page, { IncludeItemTypes: "Series" });
});
$("#radioTrailers", page).on("click", function () {
loadItems(page, { IncludeItemTypes: "Trailer" });
});
$("#radioGames", page).on("click", function () {
loadItems(page, { IncludeItemTypes: "Game" });
});
$("#radioGuestStar", page).on("click", function () {
loadItems(page, { IncludeItemTypes: "Episode", PersonTypes: "GuestStar" });
2013-04-16 22:36:56 -07:00
});
2013-04-19 16:57:23 -07:00
$("#radioAlbums", page).on("click", function () {
loadItems(page, { IncludeItemTypes: "MusicAlbum", PersonTypes: "Artist" });
});
2013-04-19 17:44:35 -07:00
$("#radioSongs", page).on("click", function () {
loadItems(page, { IncludeItemTypes: "Audio", PersonTypes: "Artist" });
});
2013-04-16 22:36:56 -07:00
}
2013-04-10 10:36:34 -07:00
function renderDetails(page, item) {
2013-03-27 21:27:15 -07:00
2013-04-21 21:38:03 -07:00
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
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
2013-04-18 22:08:18 -07:00
$('#itemBirthday', page).show().html("Birthday:&nbsp;&nbsp;" + birthday);
}
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
2013-04-18 22:08:18 -07:00
$('#itemDeathDate', page).show().html("Death day:&nbsp;&nbsp;" + deathday);
}
catch (err) {
$('#itemBirthday', page).hide();
}
2013-04-12 11:22:40 -07:00
} else {
}
if (item.Type == "Person" && item.ProductionLocations && item.ProductionLocations.length) {
var gmap = '<a target="_blank" href="https://maps.google.com/maps?q=' + item.ProductionLocations[0] + '">' + item.ProductionLocations[0] + '</a>';
2013-04-12 11:40:48 -07:00
$('#itemBirthLocation', page).show().html("Birthplace:&nbsp;&nbsp;" + 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) {
$('#itemRatings', page).html(LibraryBrowser.getUserDataIconsHtml(item));
}
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;
}
else if (currentItem.Type == "Studio") {
query.Studios = currentItem.Name;
}
}
function loadItems(page, options) {
Dashboard.showLoadingMsg();
2013-04-17 21:45:00 -07:00
var query = {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Movie",
Recursive: true,
Fields: "PrimaryImageAspectRatio,UserData,DisplayMediaType,ItemCounts,DateCreated",
Limit: LibraryBrowser.getDetaultPageSize(),
StartIndex: 0
};
query = $.extend(query, options || {});
addCurrentItemToQuery(query);
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
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
html += LibraryBrowser.getPosterDetailViewHtml({
items: result.Items,
2013-04-23 16:40:24 -07:00
useAverageAspectRatio: true,
preferBackdrop: true
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
2013-04-18 22:08:18 -07:00
$('#items', page).html(html).trigger('create');
2013-04-17 21:45:00 -07:00
2013-04-18 22:08:18 -07:00
$('.selectPage', page).on('change', function () {
2013-04-17 21:45:00 -07:00
query.StartIndex = (parseInt(this.value) - 1) * query.Limit;
loadItems(page, query);
});
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);
});
Dashboard.hideLoadingMsg();
2013-04-17 21:45:00 -07:00
});
}
2013-04-10 10:36:34 -07:00
$(document).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);