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

523 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;
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
2013-04-16 22:36:56 -07:00
var name = getParameterByName('person');
2013-03-27 15:29:37 -07:00
if (name) {
2013-05-31 18:48:41 -07:00
return ApiClient.getPerson(name, Dashboard.getCurrentUserId());
}
2013-04-16 22:36:56 -07:00
2013-05-31 18:48:41 -07:00
name = getParameterByName('studio');
2013-04-16 22:36:56 -07:00
2013-05-31 18:48:41 -07:00
if (name) {
2013-04-16 22:36:56 -07:00
2013-05-31 18:48:41 -07:00
return ApiClient.getStudio(name, Dashboard.getCurrentUserId());
2013-04-16 22:36:56 -07:00
2013-05-31 18:48:41 -07:00
}
2013-04-16 22:36:56 -07:00
2013-05-31 18:48:41 -07:00
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-05-31 18:48:41 -07:00
name = getParameterByName('artist');
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
2013-04-17 21:45:00 -07:00
currentItem = item;
2013-04-23 07:46:27 -07:00
renderHeader(page, item);
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
$('#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-05-10 05:18:07 -07:00
if (ApiClient.isWebSocketOpen()) {
2013-05-21 20:59:55 -07:00
var vals = [item.Type, item.Id, item.Name];
2013-05-10 05:18:07 -07:00
var context = getParameterByName('context');
2013-05-10 05:18:07 -07:00
if (context) {
vals.push(vals);
}
ApiClient.sendWebSocketMessage("Context", vals.join('|'));
}
2013-08-08 07:53:25 -07:00
if (MediaPlayer.canPlay(item)) {
$('#playButtonContainer', page).show();
} else {
$('#playButtonContainer', page).hide();
}
2013-06-27 06:31:49 -07:00
Dashboard.getCurrentUser().done(function (user) {
2013-07-29 08:05:09 -07:00
if (user.Configuration.IsAdministrator && item.LocationType !== "Offline") {
2013-06-27 06:31:49 -07:00
$('#editButtonContainer', page).show();
} else {
$('#editButtonContainer', page).hide();
}
});
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 renderHeader(page, item) {
var context = getParameterByName('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-04-23 19:50:43 -07:00
if (context == "music" && item.Type == "Artist") {
$('#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
}
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);
}
2013-06-10 20:31:00 -07:00
else if (item.Type == "MusicGenre") {
promise = ApiClient.getMusicGenreItemCounts(Dashboard.getCurrentUserId(), item.Name);
}
2013-07-01 10:17:33 -07:00
else if (item.Type == "GameGenre") {
promise = ApiClient.getGameGenreItemCounts(Dashboard.getCurrentUserId(), item.Name);
}
2013-04-17 09:46:52 -07:00
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-05-03 21:38:38 -07:00
if (result.EpisodeCount) {
2013-04-16 22:36:56 -07:00
2013-05-03 21:38:38 -07:00
html += '<input type="radio" name="ibnItems" id="radioEpisodes" value="on" data-mini="true">';
html += '<label for="radioEpisodes">Episodes (' + result.EpisodeCount + ')</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-24 13:28:42 -07:00
html += '<label for="radioGames">Games (' + result.GameCount + ')</label>';
2013-04-16 22:36:56 -07:00
}
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>';
}
if (result.MusicVideoCount) {
2013-07-12 12:56:40 -07:00
html += '<input type="radio" name="ibnItems" id="radioMusicVideos" value="on" data-mini="true">';
html += '<label for="radioMusicVideos">Music Videos (' + result.MusicVideoCount + ')</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) {
$("#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
}
2013-04-10 10:36:34 -07:00
function renderDetails(page, item) {
2013-03-27 21:27:15 -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
2013-06-10 18:28:41 -07:00
LibraryBrowser.renderGenres($('.itemGenres', page), item, getParameterByName('context'));
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) {
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
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-05-14 22:04:12 -07:00
var elem = $('.detailSectionContent', page)[0];
var text = elem.textContent || elem.innerText;
if (!text.trim()) {
$('#detailSection', page).hide();
} else {
$('#detailSection', page).show();
}
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-04-24 07:05:47 -07:00
else if (currentItem.Type == "Artist") {
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,
2013-05-12 18:54:06 -07:00
Fields: "UserData,DisplayMediaType,ItemCounts,DateCreated,AudioInfo,SeriesInfo,ParentId",
2013-05-03 12:34:25 -07:00
Limit: LibraryBrowser.getDefaultPageSize(),
2013-04-17 21:45:00 -07:00
StartIndex: 0
};
query = $.extend(query, options || {});
addCurrentItemToQuery(query);
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
2013-05-12 18:54:06 -07:00
if (query.IncludeItemTypes == "Audio") {
2013-05-12 18:54:06 -07:00
html += LibraryBrowser.getSongTableHtml(result.Items, {
showAlbum: true,
showArtist: true
});
2013-05-12 18:54:06 -07:00
} else {
2013-05-12 18:54:06 -07:00
html += LibraryBrowser.getPosterDetailViewHtml({
items: result.Items,
preferBackdrop: shape == "backdrop",
shape: shape
});
}
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);
});
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;
2013-08-08 07:53:25 -07:00
$('#btnPlay', page).on('click', function () {
var userdata = currentItem.UserData || {};
LibraryBrowser.showPlayMenu(this, currentItem.Name, currentItem.Type, "Audio", userdata.PlaybackPositionTicks);
});
2013-05-28 21:00:24 -07:00
$('#btnRemote', page).on('click', function () {
2013-07-11 13:25:12 -07:00
RemoteControl.showMenuForItem({ item: currentItem, context: getParameterByName('context') || '' });
2013-05-28 21:00:24 -07:00
});
2013-06-27 06:31:49 -07:00
$('#btnEdit', page).on('click', function () {
Dashboard.navigate("edititemmetadata.html", true);
});
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);