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

1943 lines
71 KiB
JavaScript
Raw Normal View History

2013-05-15 12:26:52 -07:00
var LibraryBrowser = (function (window, document, $, screen, localStorage) {
2013-04-08 22:06:13 -07:00
2013-04-21 21:38:03 -07:00
var defaultBackground = "#999;";
2013-04-10 12:33:19 -07:00
return {
2013-04-09 09:42:55 -07:00
2013-05-03 12:34:25 -07:00
getDefaultPageSize: function () {
2013-04-09 21:38:04 -07:00
2013-05-15 12:26:52 -07:00
var saved = localStorage.getItem('pagesize');
2013-05-15 12:26:52 -07:00
if (saved) {
return parseInt(saved);
}
2013-04-10 12:33:19 -07:00
if (window.location.toString().toLowerCase().indexOf('localhost') != -1) {
return 100;
}
2013-04-15 16:15:46 -07:00
return 20;
2013-04-10 12:33:19 -07:00
},
2013-04-01 22:14:37 -07:00
2013-04-10 22:27:27 -07:00
getPosterDetailViewHtml: function (options) {
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
var items = options.items;
2013-05-15 05:05:07 -07:00
var currentYear;
2013-04-24 13:28:42 -07:00
2013-04-23 19:50:43 -07:00
if (!options.shape) {
options.shape = options.preferBackdrop ? "backdrop" : "poster";
}
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
var primaryImageAspectRatio = options.useAverageAspectRatio ? LibraryBrowser.getAveragePrimaryImageAspectRatio(items) : null;
2013-04-01 22:14:37 -07:00
2013-04-10 22:27:27 -07:00
var html = '';
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
for (var i = 0, length = items.length; i < length; i++) {
2013-04-10 22:27:27 -07:00
2013-04-10 12:33:19 -07:00
var item = items[i];
2013-04-01 22:14:37 -07:00
2013-05-15 05:05:07 -07:00
if (options.timeline) {
var year = item.ProductionYear || "Unknown Year";
if (year != currentYear) {
html += '<h2 class="timelineHeader">' + year + '</h2>';
currentYear = year;
}
}
var imgUrl = null;
2013-04-22 13:06:43 -07:00
var isDefault = false;
var height = null;
var width = null;
2013-04-22 13:06:43 -07:00
2013-04-23 19:50:43 -07:00
var cssClass = "tileItem";
if (options.shape) {
cssClass += " " + options.shape + "TileItem";
}
html += '<a class="' + cssClass + '" href="' + LibraryBrowser.getHref(item, options.context) + '">';
2013-04-01 22:14:37 -07:00
2013-04-10 22:27:27 -07:00
if (options.preferBackdrop && item.BackdropImageTags && item.BackdropImageTags.length) {
2013-04-01 22:14:37 -07:00
2013-04-22 13:06:43 -07:00
imgUrl = LibraryBrowser.getImageUrl(item, 'Backdrop', 0, {
2013-04-10 22:27:27 -07:00
height: 198,
2013-04-21 21:38:03 -07:00
width: 352
2013-04-22 13:06:43 -07:00
});
2013-04-01 22:14:37 -07:00
2013-04-10 22:27:27 -07:00
}
else if (options.preferBackdrop && item.ImageTags && item.ImageTags.Thumb) {
2013-04-09 21:38:04 -07:00
2013-04-22 13:06:43 -07:00
imgUrl = ApiClient.getImageUrl(item.Id, {
2013-04-10 22:27:27 -07:00
type: "Thumb",
2013-04-10 12:33:19 -07:00
height: 198,
width: 352,
2013-04-10 22:27:27 -07:00
tag: item.ImageTags.Thumb
2013-04-22 13:06:43 -07:00
});
2013-04-10 22:27:27 -07:00
}
else if (item.ImageTags && item.ImageTags.Primary) {
2013-04-01 22:14:37 -07:00
height = 300;
width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null;
2013-04-09 21:38:04 -07:00
2013-04-22 13:06:43 -07:00
imgUrl = LibraryBrowser.getImageUrl(item, 'Primary', 0, {
2013-04-10 12:33:19 -07:00
height: height,
2013-04-11 20:50:47 -07:00
width: width
2013-04-22 13:06:43 -07:00
});
2013-04-09 21:38:04 -07:00
}
else if (item.AlbumId && item.AlbumPrimaryImageTag) {
height = 300;
width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null;
imgUrl = ApiClient.getImageUrl(item.AlbumId, {
type: "Primary",
height: 100,
width: width,
tag: item.AlbumPrimaryImageTag
});
2013-04-10 22:27:27 -07:00
}
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
2013-04-22 13:06:43 -07:00
imgUrl = LibraryBrowser.getImageUrl(item, 'Backdrop', 0, {
2013-04-10 12:33:19 -07:00
height: 198,
2013-04-21 21:38:03 -07:00
width: 352
2013-04-22 13:06:43 -07:00
});
2013-04-10 12:33:19 -07:00
}
else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist") {
2013-04-04 10:27:36 -07:00
2013-04-22 13:06:43 -07:00
imgUrl = "css/images/items/list/audio.png";
isDefault = true;
2013-04-10 12:33:19 -07:00
}
else if (item.MediaType == "Video" || item.Type == "Season" || item.Type == "Series") {
2013-04-01 22:14:37 -07:00
2013-04-22 13:06:43 -07:00
imgUrl = "css/images/items/list/video.png";
isDefault = true;
2013-04-10 12:33:19 -07:00
}
2013-04-11 20:50:47 -07:00
else if (item.Type == "Person") {
2013-04-22 13:06:43 -07:00
imgUrl = "css/images/items/list/person.png";
isDefault = true;
2013-04-21 21:38:03 -07:00
}
else if (item.Type == "Artist") {
2013-04-22 13:06:43 -07:00
imgUrl = "css/images/items/list/audiocollection.png";
isDefault = true;
2013-04-11 20:50:47 -07:00
}
2013-04-14 20:37:07 -07:00
else if (item.MediaType == "Game") {
2013-04-22 13:06:43 -07:00
imgUrl = "css/images/items/list/game.png";
isDefault = true;
2013-04-14 20:37:07 -07:00
}
2013-07-01 10:17:33 -07:00
else if (item.Type == "Studio" || item.Type == "Genre" || item.Type == "MusicGenre" || item.Type == "GameGenre") {
2013-04-23 16:21:49 -07:00
if (options.context == "games") {
imgUrl = "css/images/items/list/game.png";
}
else if (options.context == "music") {
imgUrl = "css/images/items/list/audio.png";
}
else if (options.context == "movies") {
imgUrl = "css/images/items/list/chapter.png";
}
else {
imgUrl = "css/images/items/list/collection.png";
}
isDefault = true;
}
2013-04-10 12:33:19 -07:00
else {
2013-04-01 22:14:37 -07:00
2013-04-22 13:06:43 -07:00
imgUrl = "css/images/items/list/collection.png";
isDefault = true;
2013-04-10 12:33:19 -07:00
}
2013-04-01 22:14:37 -07:00
2013-04-23 19:50:43 -07:00
cssClass = isDefault ? "tileImage defaultTileImage" : "tileImage";
2013-04-22 13:06:43 -07:00
html += '<div class="' + cssClass + '" style="background-image: url(\'' + imgUrl + '\');"></div>';
html += '<div class="tileContent">';
2013-04-10 22:27:27 -07:00
if (item.SeriesName || item.Album) {
var seriesName = item.SeriesName || item.Album;
2013-04-22 13:06:43 -07:00
html += '<div class="tileName">' + seriesName + '</div>';
2013-04-10 12:33:19 -07:00
}
2013-04-09 21:38:04 -07:00
2013-05-23 21:02:42 -07:00
var name = LibraryBrowser.getPosterViewDisplayName(item);
2013-04-10 06:53:44 -07:00
2013-04-22 13:06:43 -07:00
html += '<div class="tileName">' + name + '</div>';
2013-04-01 22:14:37 -07:00
2013-06-04 21:01:22 -07:00
if (item.CommunityRating || item.CriticRating) {
2013-05-05 20:58:45 -07:00
html += '<p>' + LibraryBrowser.getRatingHtml(item) + '</p>';
2013-04-10 22:27:27 -07:00
}
2013-04-11 12:36:50 -07:00
2013-06-25 11:02:53 -07:00
var childText = null;
2013-04-11 08:43:57 -07:00
if (item.Type == "BoxSet") {
2013-04-10 22:27:27 -07:00
2013-04-11 12:36:50 -07:00
childText = item.ChildCount == 1 ? "1 Movie" : item.ChildCount + " Movies";
2013-04-11 12:36:50 -07:00
html += '<p class="itemMiscInfo">' + childText + '</p>';
}
else if (item.Type == "GamePlatform") {
childText = item.ChildCount == 1 ? "1 Game" : item.ChildCount + " Games";
html += '<p class="itemMiscInfo">' + childText + '</p>';
}
2013-04-21 21:38:03 -07:00
else if (item.Type == "MusicAlbum") {
childText = item.ChildCount == 1 ? "1 Song" : item.ChildCount + " Songs";
html += '<p class="itemMiscInfo">' + childText + '</p>';
}
2013-07-01 10:17:33 -07:00
else if (item.Type == "Genre" || item.Type == "Studio" || item.Type == "Person" || item.Type == "Artist" || item.Type == "MusicGenre" || item.Type == "GameGenre") {
2013-04-11 12:36:50 -07:00
childText = item.ChildCount == 1 ? "1 " + options.countNameSingular : item.ChildCount + " " + options.countNamePlural;
html += '<p class="itemMiscInfo">' + childText + '</p>';
}
else if (item.Type == "Game") {
html += '<p class="itemMiscInfo">' + item.GameSystem + '</p>';
}
2013-04-11 12:36:50 -07:00
else {
2013-04-18 19:52:22 -07:00
html += '<p class="itemMiscInfo">' + LibraryBrowser.getMiscInfoHtml(item) + '</p>';
2013-04-11 08:43:57 -07:00
}
2013-04-10 22:27:27 -07:00
2013-04-21 21:38:03 -07:00
if (item.Type == "MusicAlbum") {
html += '<p class="itemMiscInfo">' + LibraryBrowser.getMiscInfoHtml(item) + '</p>';
}
2013-04-10 22:27:27 -07:00
html += '<p class="userDataIcons">' + LibraryBrowser.getUserDataIconsHtml(item) + '</p>';
html += '</div>';
if (item.LocationType == "Offline") {
html += LibraryBrowser.getOfflineIndicatorHtml(item);
} else {
html += LibraryBrowser.getNewIndicatorHtml(item);
}
2013-04-10 22:27:27 -07:00
html += "</a>";
2013-04-10 12:33:19 -07:00
}
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
return html;
},
2013-04-01 22:14:37 -07:00
2013-04-22 20:56:11 -07:00
getSongTableHtml: function (items, options) {
options = options || {};
2013-04-22 13:06:43 -07:00
var html = '';
2013-04-25 20:31:10 -07:00
var cssClass = "detailTable";
2013-04-22 20:56:11 -07:00
2013-04-25 20:31:10 -07:00
html += '<div class="detailTableContainer"><table class="' + cssClass + '">';
2013-04-22 13:06:43 -07:00
html += '<tr>';
2013-04-30 10:21:21 -07:00
html += '<th></th>';
2013-04-22 13:06:43 -07:00
html += '<th></th>';
2013-04-22 20:56:11 -07:00
2013-04-29 18:29:04 -07:00
html += '<th>Track</th>';
2013-04-22 20:56:11 -07:00
if (options.showAlbum) {
html += '<th>Album</th>';
}
if (options.showArtist) {
2013-04-25 20:31:10 -07:00
html += '<th>Artist</th>';
2013-04-22 20:56:11 -07:00
}
2013-04-27 15:04:14 -07:00
html += '<th class="tabletColumn">Duration</th>';
html += '<th class="tabletColumn">Play Count</th>';
html += '<th class="tabletColumn userDataCell"></th>';
2013-04-22 13:06:43 -07:00
html += '</tr>';
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
html += '<tr>';
2013-06-07 09:06:32 -07:00
html += '<td><button class="btnPlay" type="button" data-role="none" onclick="LibraryBrowser.showPlayMenu(this, \'' + item.Id + '\', \'Audio\', \'Audio\');"><img src="css/images/media/playCircle.png" style="height: 20px;"></button></td>';
2013-04-30 10:21:21 -07:00
2013-04-22 13:06:43 -07:00
var num = item.IndexNumber;
if (num && item.ParentIndexNumber) {
num = item.ParentIndexNumber + "." + num;
}
2013-04-29 18:29:04 -07:00
html += '<td>' + (num || "") + '</td>';
2013-04-22 13:06:43 -07:00
2013-04-23 07:46:27 -07:00
html += '<td><a href="' + LibraryBrowser.getHref(item, "music") + '">' + (item.Name || "") + '</a></td>';
2013-04-22 13:06:43 -07:00
2013-04-22 20:56:11 -07:00
if (options.showAlbum) {
2013-04-24 09:03:10 -07:00
if (item.Album && item.ParentId) {
2013-04-24 07:05:47 -07:00
html += '<td><a href="itemdetails.html?id=' + item.ParentId + '">' + item.Album + '</a></td>';
} else {
2013-05-12 18:54:06 -07:00
html += '<td>' + (item.Album || '') + '</td>';
2013-04-24 07:05:47 -07:00
}
2013-04-22 20:56:11 -07:00
}
if (options.showArtist) {
2013-04-24 13:28:42 -07:00
2013-05-16 20:24:41 -07:00
if (item.Artists && item.Artists.length && item.Artists[0]) {
2013-04-25 20:31:10 -07:00
var artist = item.Artists[0];
2013-04-27 15:52:41 -07:00
2013-04-29 08:06:31 -07:00
html += '<td><a href="itembynamedetails.html?context=music&artist=' + ApiClient.encodeName(artist) + '">' + artist + '</a></td>';
2013-04-24 07:05:47 -07:00
} else {
2013-05-12 18:54:06 -07:00
html += '<td>' + (artist || '') + '</td>';
2013-04-24 07:05:47 -07:00
}
2013-04-22 20:56:11 -07:00
}
2013-06-07 10:29:33 -07:00
var time = Dashboard.getDisplayTime(item.RunTimeTicks || 0);
2013-04-22 13:06:43 -07:00
2013-04-27 15:04:14 -07:00
html += '<td class="tabletColumn">' + time + '</td>';
2013-04-22 13:06:43 -07:00
2013-04-27 15:04:14 -07:00
html += '<td class="tabletColumn">' + (item.UserData ? item.UserData.PlayCount : 0) + '</td>';
2013-04-27 15:04:14 -07:00
html += '<td class="tabletColumn userDataCell">' + LibraryBrowser.getUserDataIconsHtml(item) + '</td>';
2013-04-22 13:06:43 -07:00
html += '</tr>';
}
2013-04-25 20:31:10 -07:00
html += '</table></div>';
2013-04-22 13:06:43 -07:00
return html;
},
2013-06-07 09:06:32 -07:00
showPlayMenu: function (positionTo, itemId, itemType, mediaType, resumePositionTicks) {
2013-05-23 18:47:07 -07:00
2013-04-30 10:21:21 -07:00
var isPlaying = MediaPlayer.isPlaying();
2013-08-08 07:53:25 -07:00
if (!isPlaying && !resumePositionTicks && mediaType != "Audio") {
2013-04-30 10:21:21 -07:00
MediaPlayer.playById(itemId);
return;
}
$('.playFlyout').popup("close").remove();
var html = '<div data-role="popup" class="playFlyout" style="max-width:300px;" data-corners="false" data-theme="c" data-history="false">';
html += '<ul data-role="listview" style="min-width: 150px;" data-theme="c">';
2013-04-30 10:21:21 -07:00
html += '<li data-role="list-divider" data-theme="a">Play Menu</li>';
2013-08-08 07:53:25 -07:00
if (itemType == "Artist") {
html += '<li><a href="#" onclick="MediaPlayer.playArtist(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Play</a></li>';
2013-08-09 08:55:22 -07:00
} else if (itemType != "MusicGenre") {
2013-08-08 07:53:25 -07:00
html += '<li><a href="#" onclick="MediaPlayer.playById(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Play</a></li>';
}
2013-04-30 10:21:21 -07:00
2013-08-09 08:55:22 -07:00
if (itemType == "Audio") {
html += '<li><a href="#" onclick="MediaPlayer.playInstantMixFromSong(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Instant Mix</a></li>';
}
else if (itemType == "MusicAlbum") {
html += '<li><a href="#" onclick="MediaPlayer.playInstantMixFromAlbum(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Instant Mix</a></li>';
}
else if (itemType == "Artist") {
html += '<li><a href="#" onclick="MediaPlayer.playInstantMixFromArtist(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Instant Mix</a></li>';
}
else if (itemType == "MusicGenre") {
html += '<li><a href="#" onclick="MediaPlayer.playInstantMixFromMusicGenre(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Instant Mix</a></li>';
}
2013-06-07 09:06:32 -07:00
if (resumePositionTicks) {
html += '<li><a href="#" onclick="MediaPlayer.playById(\'' + itemId + '\', ' + resumePositionTicks + ');LibraryBrowser.closePlayMenu();">Resume</a></li>';
}
2013-04-30 10:21:21 -07:00
2013-06-07 09:06:32 -07:00
if (isPlaying) {
2013-08-08 07:53:25 -07:00
if (itemType == "Artist") {
html += '<li><a href="#" onclick="MediaPlayer.queueArtist(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Queue</a></li>';
2013-08-09 08:55:22 -07:00
} else if (itemType != "MusicGenre") {
2013-08-08 07:53:25 -07:00
html += '<li><a href="#" onclick="MediaPlayer.queue(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Queue</a></li>';
}
2013-04-30 10:21:21 -07:00
}
html += '</ul>';
html += '</div>';
$($.mobile.activePage).append(html);
$('.playFlyout').popup({ positionTo: positionTo || "window" }).trigger('create').popup("open").on("popupafterclose", function () {
$(this).off("popupafterclose").remove();
2013-04-30 12:13:06 -07:00
}).parents(".ui-popup-container").css("margin-left", 100).css("margin-top", 35);
2013-04-30 10:21:21 -07:00
},
closePlayMenu: function () {
$('.playFlyout').popup("close").remove();
},
2013-04-23 07:46:27 -07:00
getHref: function (item, itemByNameContext) {
2013-04-10 22:27:27 -07:00
if (item.url) {
return item.url;
}
2013-04-27 06:05:33 -07:00
itemByNameContext = itemByNameContext || "";
2013-04-27 15:52:41 -07:00
2013-04-27 06:05:33 -07:00
// Handle search hints
var id = item.Id || item.ItemId;
2013-04-10 22:27:27 -07:00
if (item.Type == "Series") {
2013-04-27 06:05:33 -07:00
return "itemdetails.html?id=" + id;
2013-04-10 22:27:27 -07:00
}
2013-04-16 21:21:24 -07:00
if (item.Type == "Season") {
2013-04-27 06:05:33 -07:00
return "itemdetails.html?id=" + id;
2013-04-16 21:21:24 -07:00
}
2013-04-10 22:27:27 -07:00
if (item.Type == "BoxSet") {
2013-04-27 06:05:33 -07:00
return "itemdetails.html?id=" + id;
2013-04-10 22:27:27 -07:00
}
2013-04-22 08:10:54 -07:00
if (item.Type == "MusicAlbum") {
2013-04-27 06:05:33 -07:00
return "itemdetails.html?id=" + id;
2013-04-22 08:10:54 -07:00
}
if (item.Type == "GamePlatform") {
return "itemdetails.html?id=" + id;
}
if (item.Type == "Genre") {
2013-04-29 08:06:31 -07:00
return "itembynamedetails.html?genre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext;
}
2013-06-10 20:31:00 -07:00
if (item.Type == "MusicGenre") {
return "itembynamedetails.html?musicgenre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext;
}
2013-07-01 10:17:33 -07:00
if (item.Type == "GameGenre") {
return "itembynamedetails.html?gamegenre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext;
}
if (item.Type == "Studio") {
2013-04-29 08:06:31 -07:00
return "itembynamedetails.html?studio=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext;
}
if (item.Type == "Person") {
2013-04-29 08:06:31 -07:00
return "itembynamedetails.html?person=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext;
}
2013-04-21 21:38:03 -07:00
if (item.Type == "Artist") {
2013-04-29 08:06:31 -07:00
return "itembynamedetails.html?artist=" + ApiClient.encodeName(item.Name) + "&context=" + (itemByNameContext || "music");
2013-04-21 21:38:03 -07:00
}
2013-04-10 22:27:27 -07:00
2013-04-27 06:05:33 -07:00
return item.IsFolder ? (id ? "itemList.html?parentId=" + id : "#") : "itemdetails.html?id=" + id;
2013-04-10 22:27:27 -07:00
},
2013-04-21 21:38:03 -07:00
getImageUrl: function (item, type, index, options) {
2013-04-11 20:50:47 -07:00
options = options || {};
2013-04-21 21:38:03 -07:00
options.type = type;
options.index = index;
if (type == 'Backdrop') {
options.tag = item.BackdropImageTags[index];
2013-05-07 11:57:16 -07:00
}
else if (type == 'Screenshot') {
options.tag = item.ScreenshotImageTags[index];
}
else if (type == 'Primary') {
options.tag = item.PrimaryImageTag || item.ImageTags[type];
}
else {
2013-04-21 21:38:03 -07:00
options.tag = item.ImageTags[type];
}
2013-04-11 20:50:47 -07:00
if (item.Type == "Studio") {
return ApiClient.getStudioImageUrl(item.Name, options);
}
if (item.Type == "Person") {
return ApiClient.getPersonImageUrl(item.Name, options);
}
if (item.Type == "Genre") {
return ApiClient.getGenreImageUrl(item.Name, options);
}
2013-06-10 20:31:00 -07:00
if (item.Type == "MusicGenre") {
return ApiClient.getMusicGenreImageUrl(item.Name, options);
}
2013-07-01 10:17:33 -07:00
if (item.Type == "GameGenre") {
return ApiClient.getGameGenreImageUrl(item.Name, options);
}
2013-04-21 21:38:03 -07:00
if (item.Type == "Artist") {
return ApiClient.getArtistImageUrl(item.Name, options);
}
2013-04-11 20:50:47 -07:00
2013-04-27 06:05:33 -07:00
// For search hints
return ApiClient.getImageUrl(item.Id || item.ItemId, options);
2013-04-11 20:50:47 -07:00
},
2013-04-10 22:27:27 -07:00
getPosterViewHtml: function (options) {
2013-04-02 15:53:31 -07:00
2013-04-10 12:33:19 -07:00
var items = options.items;
2013-04-02 15:53:31 -07:00
2013-04-25 17:52:55 -07:00
options.shape = options.shape || "portrait";
2013-04-10 12:33:19 -07:00
var primaryImageAspectRatio = options.useAverageAspectRatio ? LibraryBrowser.getAveragePrimaryImageAspectRatio(items) : null;
2013-04-02 15:53:31 -07:00
2013-04-10 12:33:19 -07:00
var html = "";
2013-04-02 15:53:31 -07:00
2013-04-10 12:33:19 -07:00
for (var i = 0, length = items.length; i < length; i++) {
2013-04-02 15:53:31 -07:00
2013-04-25 17:52:55 -07:00
var item = items[i];
2013-04-02 15:53:31 -07:00
2013-04-25 17:52:55 -07:00
var imgUrl = null;
2013-06-25 11:02:53 -07:00
var background = null;
var width = null;
var height = null;
2013-04-02 15:53:31 -07:00
2013-04-10 12:33:19 -07:00
if (options.preferBackdrop && item.BackdropImageTags && item.BackdropImageTags.length) {
2013-04-25 17:52:55 -07:00
imgUrl = ApiClient.getImageUrl(item.Id, {
2013-04-10 12:33:19 -07:00
type: "Backdrop",
height: 198,
width: 352,
tag: item.BackdropImageTags[0]
2013-04-25 17:52:55 -07:00
});
2013-04-10 22:27:27 -07:00
2013-04-25 17:52:55 -07:00
} else if (item.ImageTags && item.ImageTags.Primary) {
2013-04-02 15:53:31 -07:00
height = 300;
width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null;
2013-04-02 15:53:31 -07:00
2013-04-25 17:52:55 -07:00
imgUrl = ApiClient.getImageUrl(item.Id, {
2013-04-10 12:33:19 -07:00
type: "Primary",
height: height,
width: width,
tag: item.ImageTags.Primary
2013-04-25 17:52:55 -07:00
});
2013-04-02 15:53:31 -07:00
}
else if (item.AlbumId && item.AlbumPrimaryImageTag) {
height = 300;
width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null;
imgUrl = ApiClient.getImageUrl(item.AlbumId, {
type: "Primary",
height: height,
width: width,
tag: item.AlbumPrimaryImageTag
});
}
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
2013-04-25 17:52:55 -07:00
imgUrl = ApiClient.getImageUrl(item.Id, {
2013-04-10 12:33:19 -07:00
type: "Backdrop",
height: 198,
width: 352,
tag: item.BackdropImageTags[0]
2013-04-25 17:52:55 -07:00
});
2013-04-10 22:27:27 -07:00
}
else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist") {
2013-04-25 17:52:55 -07:00
if (item.Name && options.showTitle) {
imgUrl = 'css/images/items/list/audio.png';
background = defaultBackground;
} else {
background = '#555';
}
2013-04-10 22:27:27 -07:00
}
else if (item.MediaType == "Video" || item.Type == "Season" || item.Type == "Series") {
2013-04-25 17:52:55 -07:00
if (item.Name && options.showTitle) {
imgUrl = 'css/images/items/list/video.png';
background = defaultBackground;
} else {
background = '#555';
}
2013-04-10 22:27:27 -07:00
}
else {
2013-04-25 17:52:55 -07:00
if (item.Name && options.showTitle) {
imgUrl = 'css/images/items/list/collection.png';
background = LibraryBrowser.getMetroColor(item.Id);
} else {
background = '#555';
}
2013-04-03 05:03:13 -07:00
}
2013-04-10 12:33:19 -07:00
var cssClass = "posterItem";
if (options.transparent !== false) {
cssClass += " transparentPosterItem";
}
cssClass += ' ' + options.shape + 'PosterItem';
html += '<a class="' + cssClass + '" href="' + LibraryBrowser.getHref(item, options.context) + '">';
2013-04-02 15:53:31 -07:00
2013-04-25 17:52:55 -07:00
var style = "";
2013-04-09 21:38:04 -07:00
2013-04-25 17:52:55 -07:00
if (imgUrl) {
style += 'background-image:url(\'' + imgUrl + '\');';
}
2013-04-03 21:21:46 -07:00
2013-04-25 17:52:55 -07:00
if (background) {
style += "background-color:" + background + ";";
}
2013-04-03 21:21:46 -07:00
2013-04-25 17:52:55 -07:00
html += '<div class="posterItemImage" style="' + style + '"></div>';
2013-04-03 21:21:46 -07:00
2013-05-23 21:02:42 -07:00
var name = LibraryBrowser.getPosterViewDisplayName(item);
2013-04-25 20:33:54 -07:00
2013-04-25 17:52:55 -07:00
if (!imgUrl && !options.showTitle) {
html += "<div class='posterItemDefaultText'>";
2013-04-25 20:33:54 -07:00
html += name;
2013-04-25 17:52:55 -07:00
html += "</div>";
}
2013-04-03 21:21:46 -07:00
2013-04-25 17:52:55 -07:00
var cssclass = options.centerText ? "posterItemText posterItemTextCentered" : "posterItemText";
2013-04-03 21:21:46 -07:00
2013-04-25 17:52:55 -07:00
if (options.showParentTitle) {
2013-04-03 21:21:46 -07:00
2013-04-25 17:52:55 -07:00
html += "<div class='" + cssclass + "'>";
2013-04-25 20:31:10 -07:00
html += item.SeriesName || item.Album || "&nbsp;";
2013-04-25 17:52:55 -07:00
html += "</div>";
2013-04-10 12:33:19 -07:00
}
2013-04-03 21:21:46 -07:00
2013-04-25 17:52:55 -07:00
if (options.showTitle) {
2013-04-10 22:27:27 -07:00
2013-04-25 17:52:55 -07:00
html += "<div class='" + cssclass + "'>";
2013-04-25 20:33:54 -07:00
html += name;
2013-04-10 12:33:19 -07:00
html += "</div>";
}
2013-04-03 21:21:46 -07:00
2013-05-03 19:33:44 -07:00
if (options.showProgressBar) {
2013-05-04 11:21:29 -07:00
2013-05-03 19:33:44 -07:00
html += "<div class='posterItemText posterItemProgress'>";
2013-05-04 11:21:29 -07:00
html += LibraryBrowser.getItemProgressBarHtml(item) || "&nbsp;";
2013-05-03 19:33:44 -07:00
html += "</div>";
}
if (item.LocationType == "Offline") {
html += LibraryBrowser.getOfflineIndicatorHtml(item);
} else if (options.showNewIndicator !== false) {
2013-04-10 12:33:19 -07:00
html += LibraryBrowser.getNewIndicatorHtml(item);
}
2013-04-03 21:21:46 -07:00
2013-04-25 17:52:55 -07:00
html += "</a>";
2013-04-08 22:06:13 -07:00
}
2013-04-03 21:21:46 -07:00
2013-04-10 12:33:19 -07:00
return html;
},
getPosterViewDisplayName: function (item) {
2013-05-23 21:02:42 -07:00
var name = item.Name;
if (item.Type == "Episode" && item.IndexNumber != null && item.ParentIndexNumber != null) {
var displayIndexNumber = item.IndexNumber < 10 ? "0" + item.IndexNumber : item.IndexNumber;
var number = item.ParentIndexNumber + "x" + displayIndexNumber;
if (item.IndexNumberEnd) {
displayIndexNumber = item.IndexNumberEnd < 10 ? "0" + item.IndexNumberEnd : item.IndexNumberEnd;
number += "-x" + displayIndexNumber;
}
name = number + " - " + name;
} else {
if (item.IndexNumber != null && item.Type !== "Season") {
name = item.IndexNumber + " - " + name;
}
if (item.ParentIndexNumber != null && item.Type != "Episode") {
name = item.ParentIndexNumber + "." + name;
}
}
return name;
},
2013-04-09 21:38:04 -07:00
getOfflineIndicatorHtml: function () {
return '<div class="posterRibbon offlinePosterRibbon">Offline</div>';
},
2013-04-10 12:33:19 -07:00
getNewIndicatorHtml: function (item) {
2013-04-09 21:38:04 -07:00
2013-04-10 12:33:19 -07:00
if (item.RecentlyAddedItemCount) {
return '<div class="posterRibbon">' + item.RecentlyAddedItemCount + ' New</div>';
}
2013-04-10 06:53:44 -07:00
2013-07-01 10:17:33 -07:00
if (!item.IsFolder && item.Type !== "Genre" && item.Type !== "Studio" && item.Type !== "Person" && item.Type !== "Artist" && item.Type !== "MusicGenre" && item.Type !== "GameGenre") {
2013-04-09 21:38:04 -07:00
2013-04-10 12:33:19 -07:00
var date = item.DateCreated;
2013-04-10 06:53:44 -07:00
2013-04-18 22:08:18 -07:00
try {
2013-05-15 12:26:52 -07:00
if (date && (new Date().getTime() - parseISO8601Date(date).getTime()) < 604800000) {
2013-04-18 22:08:18 -07:00
return "<div class='posterRibbon'>New</div>";
}
} catch (err) {
2013-04-19 09:28:06 -07:00
2013-04-10 12:33:19 -07:00
}
2013-04-09 21:38:04 -07:00
}
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
return '';
},
2013-04-09 21:38:04 -07:00
2013-04-10 12:33:19 -07:00
getAveragePrimaryImageAspectRatio: function (items) {
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
var values = [];
2013-04-02 15:53:31 -07:00
2013-04-10 12:33:19 -07:00
for (var i = 0, length = items.length; i < length; i++) {
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
var ratio = items[i].PrimaryImageAspectRatio || 0;
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
if (!ratio) {
continue;
}
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
values[values.length] = ratio;
2013-04-03 05:03:13 -07:00
}
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
if (!values.length) {
return null;
}
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
// Use the median
values.sort(function (a, b) { return a - b; });
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
var half = Math.floor(values.length / 2);
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
if (values.length % 2)
return values[half];
else
return (values[half - 1] + values[half]) / 2.0;
},
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
metroColors: ["#6FBD45", "#4BB3DD", "#4164A5", "#E12026", "#800080", "#E1B222", "#008040", "#0094FF", "#FF00C7", "#FF870F", "#7F0037"],
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
getRandomMetroColor: function () {
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
var index = Math.floor(Math.random() * (LibraryBrowser.metroColors.length - 1));
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
return LibraryBrowser.metroColors[index];
},
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
getMetroColor: function (str) {
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
if (str) {
2013-05-04 21:49:49 -07:00
var character = String(str.substr(0, 1).charCodeAt());
2013-04-10 12:33:19 -07:00
var sum = 0;
2013-05-04 21:49:49 -07:00
for (var i = 0; i < character.length; i++) {
sum += parseInt(character.charAt(i));
2013-04-10 12:33:19 -07:00
}
var index = String(sum).substr(-1);
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
return LibraryBrowser.metroColors[index];
} else {
return LibraryBrowser.getRandomMetroColor();
2013-04-08 22:06:13 -07:00
}
2013-04-01 22:14:37 -07:00
2013-04-10 12:33:19 -07:00
},
2013-04-05 11:35:37 -07:00
renderName: function (item, nameElem, linkToElement) {
2013-05-04 21:49:49 -07:00
2013-05-23 21:30:34 -07:00
var name = LibraryBrowser.getPosterViewDisplayName(item);
2013-05-23 21:30:34 -07:00
Dashboard.setPageTitle(name);
2013-05-04 21:49:49 -07:00
if (linkToElement) {
nameElem.html('<a class="detailPageParentLink" href="' + LibraryBrowser.getHref(item) + '">' + name + '</a>').trigger('create');
} else {
nameElem.html(name);
}
},
renderParentName: function (item, parentNameElem) {
var html = [];
if (item.AlbumArtist && item.Type == "Audio") {
html.push('<a class="detailPageParentLink" href="itembynamedetails.html?context=music&artist=' + ApiClient.encodeName(item.AlbumArtist) + '">' + item.AlbumArtist + '</a>');
}
else if (item.AlbumArtist && item.Type == "MusicAlbum") {
html.push('<a class="detailPageParentLink" href="itembynamedetails.html?context=music&artist=' + ApiClient.encodeName(item.AlbumArtist) + '">' + item.AlbumArtist + '</a>');
}
2013-07-22 16:59:28 -07:00
else if (item.Artists && item.Artists.length && item.Type == "MusicVideo") {
html.push('<a class="detailPageParentLink" href="itembynamedetails.html?context=music&artist=' + ApiClient.encodeName(item.Artists[0]) + '">' + item.Artists[0] + '</a>');
}
else if (item.SeriesName && item.Type == "Episode") {
html.push('<a class="detailPageParentLink" href="itemdetails.html?id=' + item.SeriesId + '">' + item.SeriesName + '</a>');
}
if (item.SeriesName && item.Type == "Season") {
html.push('<a class="detailPageParentLink" href="itemdetails.html?id=' + item.SeriesId + '">' + item.SeriesName + '</a>');
}
else if (item.ParentIndexNumber && item.Type == "Episode") {
html.push('<a class="detailPageParentLink" href="itemdetails.html?id=' + item.ParentId + '">Season ' + item.ParentIndexNumber + '</a>');
}
2013-07-22 16:59:28 -07:00
else if (item.Album && item.Type == "Audio" && (item.AlbumId || item.ParentId)) {
html.push('<a class="detailPageParentLink" href="itemdetails.html?id=' + (item.AlbumId || item.ParentId) + '">' + item.Album + '</a>');
}
else if (item.Album && item.Type == "MusicVideo" && item.AlbumId) {
html.push('<a class="detailPageParentLink" href="itemdetails.html?id=' + item.AlbumId + '">' + item.Album + '</a>');
}
else if (item.AlbumArtist && item.Type == "MusicAlbum") {
}
else if (item.Album) {
html.push(item.Album);
}
if (html.length) {
parentNameElem.show().html(html.join(' - ')).trigger('create');
} else {
parentNameElem.hide();
}
},
2013-04-14 08:14:10 -07:00
renderLinks: function (linksElem, item) {
2013-04-08 22:06:13 -07:00
2013-04-10 12:33:19 -07:00
var links = [];
2013-04-08 22:06:13 -07:00
if (item.HomePageUrl) {
2013-05-11 23:05:51 -07:00
links.push('<a class="textlink" href="' + item.HomePageUrl + '" target="_blank">Website</a>');
}
2013-04-14 08:14:10 -07:00
var providerIds = item.ProviderIds || {};
if (providerIds.Imdb) {
if (item.Type == "Person") {
2013-05-11 23:05:51 -07:00
links.push('<a class="textlink" href="http://www.imdb.com/name/' + providerIds.Imdb + '" target="_blank">IMDb</a>');
}
else {
links.push('<a class="textlink" href="http://www.imdb.com/title/' + providerIds.Imdb + '" target="_blank">IMDb</a>');
}
2013-04-10 12:33:19 -07:00
}
2013-04-14 08:14:10 -07:00
if (providerIds.Tmdb) {
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "MusicVideo")
2013-05-12 13:30:23 -07:00
links.push('<a class="textlink" href="http://www.themoviedb.org/movie/' + providerIds.Tmdb + '" target="_blank">TheMovieDB</a>');
2013-05-06 16:12:22 -07:00
else if (item.Type == "BoxSet")
2013-05-12 13:30:23 -07:00
links.push('<a class="textlink" href="http://www.themoviedb.org/collection/' + providerIds.Tmdb + '" target="_blank">TheMovieDB</a>');
2013-04-10 12:33:19 -07:00
else if (item.Type == "Person")
2013-05-12 13:30:23 -07:00
links.push('<a class="textlink" href="http://www.themoviedb.org/person/' + providerIds.Tmdb + '" target="_blank">TheMovieDB</a>');
2013-04-10 12:33:19 -07:00
}
2013-04-14 08:14:10 -07:00
if (providerIds.Tvdb)
2013-05-12 13:30:23 -07:00
links.push('<a class="textlink" href="http://thetvdb.com/index.php?tab=series&id=' + providerIds.Tvdb + '" target="_blank">TheTVDB</a>');
2013-04-14 08:14:10 -07:00
if (providerIds.Tvcom) {
2013-04-10 12:33:19 -07:00
if (item.Type == "Episode")
2013-05-11 23:05:51 -07:00
links.push('<a class="textlink" href="http://www.tv.com/shows/' + providerIds.Tvcom + '" target="_blank">TV.com</a>');
2013-04-10 12:33:19 -07:00
else if (item.Type == "Person")
2013-05-11 23:05:51 -07:00
links.push('<a class="textlink" href="http://www.tv.com/people/' + providerIds.Tvcom + '" target="_blank">TV.com</a>');
2013-04-10 12:33:19 -07:00
}
2013-04-22 20:56:11 -07:00
if (providerIds.Musicbrainz) {
if (item.Type == "MusicArtist" || item.Type == "Artist") {
2013-05-11 23:05:51 -07:00
links.push('<a class="textlink" href="http://musicbrainz.org/artist/' + providerIds.Musicbrainz + '" target="_blank">MusicBrainz</a>');
2013-04-22 20:56:11 -07:00
} else {
2013-05-11 23:05:51 -07:00
links.push('<a class="textlink" href="http://musicbrainz.org/release/' + providerIds.Musicbrainz + '" target="_blank">MusicBrainz</a>');
2013-04-22 20:56:11 -07:00
}
}
2013-04-14 08:14:10 -07:00
if (providerIds.Gamesdb)
2013-07-13 10:59:12 -07:00
links.push('<a class="textlink" href="http://thegamesdb.net/game/' + providerIds.Gamesdb + '" target="_blank">GamesDB</a>');
2013-04-08 22:06:13 -07:00
if (providerIds.Zap2It)
links.push('<a class="textlink" href="http://tvlistings.zap2it.com/tv/dexter/' + providerIds.Zap2It + '?aid=zap2it" target="_blank">Zap2It</a>');
2013-04-14 08:14:10 -07:00
if (links.length) {
2013-04-10 10:11:23 -07:00
2013-04-14 08:14:10 -07:00
var html = 'Links:&nbsp;&nbsp;' + links.join('&nbsp;&nbsp;/&nbsp;&nbsp;');
2013-04-10 10:11:23 -07:00
2013-05-11 23:05:51 -07:00
$(linksElem).html(html).trigger('create');
2013-04-08 22:06:13 -07:00
2013-04-10 12:33:19 -07:00
} else {
2013-04-14 08:14:10 -07:00
$(linksElem).hide();
2013-04-10 12:33:19 -07:00
}
},
2013-04-08 22:06:13 -07:00
2013-04-18 22:08:18 -07:00
getPagingHtml: function (query, totalRecordCount) {
2013-04-08 22:06:13 -07:00
2013-05-15 12:26:52 -07:00
if (query.Limit) {
localStorage.setItem('pagesize', query.Limit);
}
2013-04-10 12:33:19 -07:00
var html = '';
2013-04-08 22:06:13 -07:00
2013-04-10 12:33:19 -07:00
var pageCount = Math.ceil(totalRecordCount / query.Limit);
var pageNumber = (query.StartIndex / query.Limit) + 1;
2013-04-08 22:06:13 -07:00
2013-04-18 22:08:18 -07:00
var dropdownHtml = '<select class="selectPage" data-enhance="false" data-role="none">';
2013-04-10 12:33:19 -07:00
for (var i = 1; i <= pageCount; i++) {
2013-04-08 22:06:13 -07:00
2013-04-10 12:33:19 -07:00
if (i == pageNumber) {
dropdownHtml += '<option value="' + i + '" selected="selected">' + i + '</option>';
} else {
dropdownHtml += '<option value="' + i + '">' + i + '</option>';
}
2013-04-08 22:06:13 -07:00
}
2013-04-10 12:33:19 -07:00
dropdownHtml += '</select>';
2013-04-08 22:06:13 -07:00
2013-04-10 12:33:19 -07:00
var recordsEnd = Math.min(query.StartIndex + query.Limit, totalRecordCount);
2013-04-08 22:06:13 -07:00
2013-05-15 12:40:47 -07:00
// 20 is the minimum page size
var showControls = totalRecordCount > 20;
2013-04-19 09:28:06 -07:00
2013-04-18 22:08:18 -07:00
html += '<div class="listPaging">';
2013-04-15 15:03:05 -07:00
html += '<span style="margin-right: 10px;">';
2013-04-19 16:45:27 -07:00
var startAtDisplay = totalRecordCount ? query.StartIndex + 1 : 0;
html += startAtDisplay + '-' + recordsEnd + ' of ' + totalRecordCount;
2013-04-19 09:28:06 -07:00
if (showControls) {
html += ', page ' + dropdownHtml + ' of ' + pageCount;
}
2013-04-15 15:03:05 -07:00
html += '</span>';
2013-04-19 09:28:06 -07:00
if (showControls) {
html += '<button data-icon="arrow-left" data-iconpos="notext" data-inline="true" data-mini="true" class="btnPreviousPage" ' + (query.StartIndex ? '' : 'disabled') + '>Previous Page</button>';
2013-04-15 15:03:05 -07:00
2013-04-19 09:28:06 -07:00
html += '<button data-icon="arrow-right" data-iconpos="notext" data-inline="true" data-mini="true" class="btnNextPage" ' + (query.StartIndex + query.Limit > totalRecordCount ? 'disabled' : '') + '>Next Page</button>';
2013-04-27 15:52:41 -07:00
var id = "selectPageSize" + new Date().getTime();
var options = '';
function getOption(val) {
if (query.Limit == val) {
return '<option value="' + val + '" selected="selected">' + val + '</option>';
} else {
return '<option value="' + val + '">' + val + '</option>';
}
}
options += getOption(20);
options += getOption(50);
options += getOption(100);
options += getOption(200);
options += getOption(300);
html += '<label class="labelPageSize" for="' + id + '">Limit: </label><select class="selectPageSize" id="' + id + '" data-enhance="false" data-role="none">' + options + '</select>';
2013-04-19 09:28:06 -07:00
}
2013-04-15 15:03:05 -07:00
2013-04-10 12:33:19 -07:00
html += '</div>';
2013-04-08 22:06:13 -07:00
2013-04-10 12:33:19 -07:00
return html;
},
2013-04-10 06:53:44 -07:00
2013-05-05 20:58:45 -07:00
getRatingHtml: function (item) {
2013-04-10 12:33:19 -07:00
var html = "";
2013-05-05 21:50:40 -07:00
if (item.CommunityRating) {
var rating = item.CommunityRating / 2;
for (var i = 1; i <= 5; i++) {
if (rating < i - 1) {
html += "<div class='starRating emptyStarRating' title='" + item.CommunityRating + "'></div>";
}
else if (rating < i) {
html += "<div class='starRating halfStarRating' title='" + item.CommunityRating + "'></div>";
}
else {
html += "<div class='starRating' title='" + item.CommunityRating + "'></div>";
}
2013-04-10 12:33:19 -07:00
}
2013-04-10 06:53:44 -07:00
}
if (item.CriticRating != null) {
2013-04-10 06:53:44 -07:00
2013-05-05 20:58:45 -07:00
if (item.CriticRating >= 60) {
2013-05-07 06:06:01 -07:00
html += '<div class="fresh rottentomatoesicon" title="fresh"></div>';
2013-05-05 20:58:45 -07:00
} else {
2013-05-07 06:06:01 -07:00
html += '<div class="rotten rottentomatoesicon" title="rotten"></div>';
2013-05-05 20:58:45 -07:00
}
2013-04-10 22:27:27 -07:00
2013-05-05 20:58:45 -07:00
html += '<div class="criticRating">' + item.CriticRating + '%</div>';
2013-04-10 22:27:27 -07:00
}
return html;
},
2013-05-04 11:21:29 -07:00
getItemProgressBarHtml: function (item) {
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var html = '';
2013-04-10 06:53:44 -07:00
2013-04-15 19:36:12 -07:00
var tooltip;
var pct;
if (item.PlayedPercentage) {
2013-05-07 18:17:41 -07:00
tooltip = item.PlayedPercentage.toFixed(1).toString().replace(".0", '') + '% ';
2013-05-04 11:21:29 -07:00
if (item.Type == "Series" || item.Type == "Season" || item.Type == "BoxSet") {
tooltip += "watched";
} else {
tooltip += "played";
}
2013-05-03 19:33:44 -07:00
2013-04-15 19:36:12 -07:00
pct = item.PlayedPercentage;
}
else if (item.UserData && item.UserData.PlaybackPositionTicks && item.RunTimeTicks) {
2013-06-07 10:29:33 -07:00
tooltip = Dashboard.getDisplayTime(item.UserData.PlaybackPositionTicks) + " / " + Dashboard.getDisplayTime(item.RunTimeTicks);
2013-04-15 19:36:12 -07:00
pct = (item.UserData.PlaybackPositionTicks / item.RunTimeTicks) * 100;
}
2013-05-03 12:34:25 -07:00
if (pct && pct < 100) {
2013-04-15 19:36:12 -07:00
2013-05-03 12:34:25 -07:00
html += '<progress title="' + tooltip + '" class="itemProgressBar" min="0" max="100" value="' + pct + '">';
html += '</progress>';
2013-05-03 19:33:44 -07:00
2013-05-04 11:21:29 -07:00
html += '<span class="itemProgressText">' + tooltip + '</span>';
2013-04-15 19:36:12 -07:00
}
2013-05-03 19:33:44 -07:00
return html;
},
getUserDataIconsHtml: function (item) {
var html = '';
if (item.Type != "Audio") {
html += LibraryBrowser.getItemProgressBarHtml(item);
}
2013-05-03 19:33:44 -07:00
2013-04-10 12:33:19 -07:00
var userData = item.UserData || {};
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
var itemId = item.Id;
var type = item.Type;
2013-04-14 08:14:10 -07:00
if (type == "Person") {
itemId = item.Name;
}
else if (type == "Studio") {
itemId = item.Name;
}
else if (type == "Genre") {
itemId = item.Name;
}
2013-06-10 20:31:00 -07:00
else if (type == "MusicGenre") {
itemId = item.Name;
}
2013-07-01 10:17:33 -07:00
else if (type == "GameGenre") {
itemId = item.Name;
}
2013-04-21 21:38:03 -07:00
else if (type == "Artist") {
itemId = item.Name;
}
2013-04-10 10:11:23 -07:00
2013-04-16 05:30:50 -07:00
if (item.MediaType || item.IsFolder) {
2013-04-10 12:33:19 -07:00
if (userData.Played) {
2013-04-10 22:27:27 -07:00
html += '<img data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgPlayed" src="css/images/userdata/played.png" alt="Played" title="Played" onclick="LibraryBrowser.markPlayed(this);return false;" />';
2013-04-10 12:33:19 -07:00
} else {
2013-04-10 22:27:27 -07:00
html += '<img data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgPlayedOff" src="css/images/userdata/unplayed.png" alt="Played" title="Played" onclick="LibraryBrowser.markPlayed(this);return false;" />';
2013-04-10 12:33:19 -07:00
}
2013-04-10 10:11:23 -07:00
}
2013-04-10 12:33:19 -07:00
if (typeof userData.Likes == "undefined") {
2013-04-10 22:27:27 -07:00
html += '<img onclick="LibraryBrowser.markDislike(this);return false;" data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgDislikeOff" src="css/images/userdata/thumbs_down_off.png" alt="Dislike" title="Dislike" />';
html += '<img onclick="LibraryBrowser.markLike(this);return false;" data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgLikeOff" src="css/images/userdata/thumbs_up_off.png" alt="Like" title="Like" />';
2013-04-10 12:33:19 -07:00
}
else if (userData.Likes) {
2013-04-10 22:27:27 -07:00
html += '<img onclick="LibraryBrowser.markDislike(this);return false;" data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgDislikeOff" src="css/images/userdata/thumbs_down_off.png" alt="Dislike" title="Dislike" />';
html += '<img onclick="LibraryBrowser.markLike(this);return false;" data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgLike" src="css/images/userdata/thumbs_up_on.png" alt="Like" title="Like" />';
2013-04-10 12:33:19 -07:00
}
else {
2013-04-10 22:27:27 -07:00
html += '<img onclick="LibraryBrowser.markDislike(this);return false;" data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgDislike" src="css/images/userdata/thumbs_down_on.png" alt="Dislike" title="Dislike" />';
html += '<img onclick="LibraryBrowser.markLike(this);return false;" data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgLikeOff" src="css/images/userdata/thumbs_up_off.png" alt="Like" title="Like" />';
2013-04-10 12:33:19 -07:00
}
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
if (userData.IsFavorite) {
2013-04-10 22:27:27 -07:00
html += '<img onclick="LibraryBrowser.markFavorite(this);return false;" data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgFavorite" src="css/images/userdata/heart_on.png" alt="Favorite" title="Favorite" />';
2013-04-10 12:33:19 -07:00
} else {
2013-04-10 22:27:27 -07:00
html += '<img onclick="LibraryBrowser.markFavorite(this);return false;" data-type="' + type + '" data-itemid="' + itemId + '" class="imgUserItemRating imgFavoriteOff" src="css/images/userdata/heart_off.png" alt="Favorite" title="Favorite" />';
2013-04-10 12:33:19 -07:00
}
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
return html;
},
2013-04-10 12:33:19 -07:00
markPlayed: function (link) {
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var id = link.getAttribute('data-itemid');
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var $link = $(link);
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var markAsPlayed = $link.hasClass('imgPlayedOff');
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
ApiClient.updatePlayedStatus(Dashboard.getCurrentUserId(), id, markAsPlayed);
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
if (markAsPlayed) {
link.src = "css/images/userdata/played.png";
$link.addClass('imgPlayed').removeClass('imgPlayedOff');
} else {
link.src = "css/images/userdata/unplayed.png";
$link.addClass('imgPlayedOff').removeClass('imgPlayed');
}
},
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
markFavorite: function (link) {
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var id = link.getAttribute('data-itemid');
var type = link.getAttribute('data-type');
2013-04-10 12:33:19 -07:00
var $link = $(link);
2013-04-10 12:33:19 -07:00
var markAsFavorite = $link.hasClass('imgFavoriteOff');
2013-04-10 10:11:23 -07:00
2013-04-21 21:38:03 -07:00
if (type == "Person") {
ApiClient.updateFavoritePersonStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
else if (type == "Studio") {
ApiClient.updateFavoriteStudioStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
else if (type == "Artist") {
ApiClient.updateFavoriteArtistStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
else if (type == "Genre") {
ApiClient.updateFavoriteGenreStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
2013-06-10 20:31:00 -07:00
else if (type == "MusicGenre") {
ApiClient.updateFavoriteMusicGenreStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
2013-07-01 10:17:33 -07:00
else if (type == "GameGenre") {
ApiClient.updateFavoriteGameGenreStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
else {
ApiClient.updateFavoriteStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
if (markAsFavorite) {
link.src = "css/images/userdata/heart_on.png";
$link.addClass('imgFavorite').removeClass('imgFavoriteOff');
} else {
link.src = "css/images/userdata/heart_off.png";
$link.addClass('imgFavoriteOff').removeClass('imgFavorite');
}
},
2013-04-10 12:33:19 -07:00
markLike: function (link) {
2013-04-10 12:33:19 -07:00
var id = link.getAttribute('data-itemid');
var type = link.getAttribute('data-type');
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var $link = $(link);
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
if ($link.hasClass('imgLikeOff')) {
2013-04-21 21:38:03 -07:00
LibraryBrowser.updateUserItemRating(type, id, true);
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
link.src = "css/images/userdata/thumbs_up_on.png";
$link.addClass('imgLike').removeClass('imgLikeOff');
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
} else {
2013-04-21 21:38:03 -07:00
LibraryBrowser.clearUserItemRating(type, id);
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
link.src = "css/images/userdata/thumbs_up_off.png";
$link.addClass('imgLikeOff').removeClass('imgLike');
}
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
$link.prev().removeClass('imgDislike').addClass('imgDislikeOff').each(function () {
this.src = "css/images/userdata/thumbs_down_off.png";
});
},
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
markDislike: function (link) {
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var id = link.getAttribute('data-itemid');
var type = link.getAttribute('data-type');
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var $link = $(link);
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
if ($link.hasClass('imgDislikeOff')) {
2013-04-10 10:11:23 -07:00
2013-04-21 21:38:03 -07:00
LibraryBrowser.updateUserItemRating(type, id, false);
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
link.src = "css/images/userdata/thumbs_down_on.png";
$link.addClass('imgDislike').removeClass('imgDislikeOff');
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
} else {
2013-04-10 10:11:23 -07:00
2013-04-21 21:38:03 -07:00
LibraryBrowser.clearUserItemRating(type, id);
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
link.src = "css/images/userdata/thumbs_down_off.png";
$link.addClass('imgDislikeOff').removeClass('imgDislike');
}
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
$link.next().removeClass('imgLike').addClass('imgLikeOff').each(function () {
this.src = "css/images/userdata/thumbs_up_off.png";
});
},
2013-04-10 10:11:23 -07:00
2013-04-21 21:38:03 -07:00
updateUserItemRating: function (type, id, likes) {
if (type == "Person") {
ApiClient.updatePersonRating(Dashboard.getCurrentUserId(), id, likes);
}
else if (type == "Studio") {
ApiClient.updateStudioRating(Dashboard.getCurrentUserId(), id, likes);
}
else if (type == "Artist") {
ApiClient.updateArtistRating(Dashboard.getCurrentUserId(), id, likes);
}
else if (type == "Genre") {
ApiClient.updateGenreRating(Dashboard.getCurrentUserId(), id, likes);
}
2013-06-10 20:31:00 -07:00
else if (type == "MusicGenre") {
ApiClient.updateMusicGenreRating(Dashboard.getCurrentUserId(), id, likes);
}
2013-07-01 10:17:33 -07:00
else if (type == "GameGenre") {
ApiClient.updateGameGenreRating(Dashboard.getCurrentUserId(), id, likes);
}
2013-04-21 21:38:03 -07:00
else {
ApiClient.updateUserItemRating(Dashboard.getCurrentUserId(), id, likes);
}
},
clearUserItemRating: function (type, id) {
if (type == "Person") {
ApiClient.clearPersonRating(Dashboard.getCurrentUserId(), id);
}
else if (type == "Studio") {
ApiClient.clearStudioRating(Dashboard.getCurrentUserId(), id);
}
else if (type == "Artist") {
ApiClient.clearArtistRating(Dashboard.getCurrentUserId(), id);
}
else if (type == "Genre") {
ApiClient.clearGenreRating(Dashboard.getCurrentUserId(), id);
}
2013-06-10 20:31:00 -07:00
else if (type == "MusicGenre") {
ApiClient.clearMusicGenreRating(Dashboard.getCurrentUserId(), id);
}
2013-07-01 10:17:33 -07:00
else if (type == "GameGenre") {
ApiClient.clearGameGenreRating(Dashboard.getCurrentUserId(), id);
}
2013-04-21 21:38:03 -07:00
else {
ApiClient.clearUserItemRating(Dashboard.getCurrentUserId(), id);
}
},
2013-04-10 12:33:19 -07:00
getDetailImageHtml: function (item) {
2013-04-10 12:33:19 -07:00
var imageTags = item.ImageTags || {};
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
var html = '';
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
var url;
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
if (imageTags.Primary) {
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
if (item.Type == "Person") {
url = ApiClient.getPersonImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-10 12:33:19 -07:00
tag: imageTags.Primary,
2013-04-21 21:38:03 -07:00
type: "Primary"
2013-04-10 12:33:19 -07:00
});
}
else if (item.Type == "Genre") {
url = ApiClient.getGenreImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-10 12:33:19 -07:00
tag: imageTags.Primary,
2013-04-21 21:38:03 -07:00
type: "Primary"
2013-04-10 12:33:19 -07:00
});
}
2013-06-10 20:31:00 -07:00
else if (item.Type == "MusicGenre") {
url = ApiClient.getMusicGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Primary,
type: "Primary"
});
}
2013-07-01 10:17:33 -07:00
else if (item.Type == "GameGenre") {
url = ApiClient.getGameGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Primary,
type: "Primary"
});
}
2013-04-10 12:33:19 -07:00
else if (item.Type == "Studio") {
url = ApiClient.getStudioImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-10 12:33:19 -07:00
tag: imageTags.Primary,
2013-04-21 21:38:03 -07:00
type: "Primary"
});
}
else if (item.Type == "Artist") {
url = ApiClient.getArtistImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: imageTags.Primary,
type: "Primary"
2013-04-10 12:33:19 -07:00
});
}
else {
url = ApiClient.getImageUrl(item.Id, {
type: "Primary",
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-10 12:33:19 -07:00
tag: item.ImageTags.Primary
});
}
2013-04-10 10:36:34 -07:00
}
2013-04-10 12:33:19 -07:00
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
2013-04-21 21:38:03 -07:00
if (item.Type == "Person") {
url = ApiClient.getPersonImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else if (item.Type == "Genre") {
url = ApiClient.getGenreImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
2013-06-10 20:31:00 -07:00
else if (item.Type == "MusicGenre") {
url = ApiClient.getMusicGenreImageUrl(item.Name, {
maxheight: 480,
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
2013-07-01 10:17:33 -07:00
else if (item.Type == "GameGenre") {
url = ApiClient.getGameGenreImageUrl(item.Name, {
maxheight: 480,
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
2013-04-21 21:38:03 -07:00
else if (item.Type == "Studio") {
url = ApiClient.getStudioImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else if (item.Type == "Artist") {
url = ApiClient.getArtistImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else {
url = ApiClient.getImageUrl(item.Id, {
type: "Backdrop",
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: item.BackdropImageTags[0]
});
}
2013-04-10 10:36:34 -07:00
}
2013-04-10 12:33:19 -07:00
else if (imageTags.Thumb) {
2013-04-21 21:38:03 -07:00
if (item.Type == "Person") {
url = ApiClient.getPersonImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: imageTags.Thumb,
type: "Thumb"
});
}
else if (item.Type == "Genre") {
url = ApiClient.getGenreImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: imageTags.Thumb,
type: "Thumb"
});
}
2013-06-10 20:31:00 -07:00
else if (item.Type == "MusicGenre") {
url = ApiClient.getMusicGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Thumb,
type: "Thumb"
});
}
2013-07-01 10:17:33 -07:00
else if (item.Type == "GameGenre") {
url = ApiClient.getGameGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Thumb,
type: "Thumb"
});
}
2013-04-21 21:38:03 -07:00
else if (item.Type == "Studio") {
url = ApiClient.getStudioImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: imageTags.Thumb,
type: "Thumb"
});
}
else if (item.Type == "Artist") {
url = ApiClient.getArtistImageUrl(item.Name, {
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: imageTags.Thumb,
type: "Thumb"
});
}
else {
url = ApiClient.getImageUrl(item.Id, {
type: "Thumb",
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-21 21:38:03 -07:00
tag: item.ImageTags.Thumb
});
}
2013-04-10 10:36:34 -07:00
}
2013-04-10 12:33:19 -07:00
else if (imageTags.Disc) {
2013-04-10 10:36:34 -07:00
url = ApiClient.getImageUrl(item.Id, {
2013-04-10 12:33:19 -07:00
type: "Disc",
2013-05-15 05:05:07 -07:00
maxheight: 480,
2013-04-10 12:33:19 -07:00
tag: item.ImageTags.Disc
2013-04-10 10:36:34 -07:00
});
}
else if (item.AlbumId && item.AlbumPrimaryImageTag) {
url = ApiClient.getImageUrl(item.AlbumId, {
type: "Primary",
maxheight: 480,
tag: item.AlbumPrimaryImageTag
});
}
else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicGenre") {
2013-04-10 12:33:19 -07:00
url = "css/images/items/detail/audio.png";
}
2013-07-01 10:17:33 -07:00
else if (item.MediaType == "Game" || item.Type == "GameGenre") {
2013-04-10 12:33:19 -07:00
url = "css/images/items/detail/game.png";
}
2013-04-13 20:33:43 -07:00
else if (item.Type == "Person") {
url = "css/images/items/detail/person.png";
}
else if (item.Type == "Genre" || item.Type == "Studio") {
url = "css/images/items/detail/video.png";
2013-04-13 20:33:43 -07:00
}
2013-04-10 12:33:19 -07:00
else {
url = "css/images/items/detail/video.png";
}
2013-04-10 06:53:44 -07:00
2013-05-31 18:48:41 -07:00
var identifierName = "id";
var identifierValue = item.Id;
2013-04-10 06:53:44 -07:00
2013-07-01 10:17:33 -07:00
if (item.Type == "Person" || item.Type == "Genre" || item.Type == "Studio" || item.Type == "Artist" || item.Type == "MusicGenre" || item.Type == "GameGenre") {
2013-05-31 18:48:41 -07:00
identifierName = item.Type;
identifierValue = ApiClient.encodeName(item.Name);
2013-04-10 12:33:19 -07:00
}
2013-04-10 06:53:44 -07:00
2013-05-31 18:48:41 -07:00
var href = "itemgallery.html?" + identifierName + "=" + identifierValue;
var linkToGallery = LibraryBrowser.shouldDisplayGallery(item);
if (linkToGallery) {
html += "<a class='itemDetailGalleryLink' href='" + href + "'>";
}
2013-06-04 20:40:17 -07:00
html += "<img class='itemDetailImage' src='" + url + "' />";
if (linkToGallery) {
html += "</a>";
}
2013-05-31 18:48:41 -07:00
2013-04-10 12:33:19 -07:00
return html;
},
2013-04-10 06:53:44 -07:00
2013-04-18 19:52:22 -07:00
getMiscInfoHtml: function (item) {
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
var miscInfo = [];
2013-04-24 13:28:42 -07:00
var text;
2013-04-25 17:52:55 -07:00
2013-05-04 12:53:13 -07:00
if (item.Type == "Episode") {
if (item.PremiereDate) {
try {
var date = parseISO8601Date(item.PremiereDate, { toLocal: true });
2013-05-11 23:05:51 -07:00
text = date.toLocaleDateString();
2013-05-04 12:53:13 -07:00
miscInfo.push(text);
}
catch (e) {
console.log("Error parsing date: " + item.PremiereDate);
}
}
}
2013-04-24 13:28:42 -07:00
if (item.ProductionYear && item.Type == "Series") {
2013-04-18 19:52:22 -07:00
if (item.Status == "Continuing") {
miscInfo.push(item.ProductionYear + "-Present");
2013-04-24 13:28:42 -07:00
} else if (item.ProductionYear) {
text = item.ProductionYear;
if (item.EndDate) {
try {
2013-06-09 06:35:50 -07:00
var endYear = parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear();
2013-06-09 06:35:50 -07:00
if (endYear != item.ProductionYear) {
text += "-" + parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear();
}
2013-04-24 13:28:42 -07:00
}
catch (e) {
console.log("Error parsing date: " + item.EndDate);
}
}
miscInfo.push(text);
}
}
if (item.Type != "Series" && item.Type != "Episode") {
2013-04-25 17:52:55 -07:00
2013-04-24 13:28:42 -07:00
if (item.ProductionYear) {
2013-04-18 19:52:22 -07:00
miscInfo.push(item.ProductionYear);
}
2013-04-24 13:28:42 -07:00
else if (item.PremiereDate) {
2013-04-25 17:52:55 -07:00
2013-04-24 13:28:42 -07:00
try {
2013-06-04 20:40:17 -07:00
text = parseISO8601Date(item.PremiereDate, { toLocal: true }).getFullYear();
2013-04-24 13:28:42 -07:00
miscInfo.push(text);
}
catch (e) {
console.log("Error parsing date: " + item.PremiereDate);
}
}
2013-04-10 12:33:19 -07:00
}
2013-04-10 10:11:23 -07:00
2013-04-10 12:33:19 -07:00
if (item.RunTimeTicks) {
2013-04-10 10:11:23 -07:00
2013-04-22 13:06:43 -07:00
if (item.Type == "Audio") {
2013-04-10 10:11:23 -07:00
2013-06-07 10:29:33 -07:00
miscInfo.push(Dashboard.getDisplayTime(item.RunTimeTicks));
2013-04-22 13:06:43 -07:00
} else {
var minutes = item.RunTimeTicks / 600000000;
2013-04-10 10:11:23 -07:00
2013-04-22 13:06:43 -07:00
minutes = minutes || 1;
miscInfo.push(parseInt(minutes) + "min");
}
2013-04-10 12:33:19 -07:00
}
2013-04-10 10:11:23 -07:00
if (item.OfficialRating && item.Type !== "Season" && item.Type !== "Episode") {
2013-05-04 12:53:13 -07:00
miscInfo.push(item.OfficialRating);
}
2013-06-27 10:04:48 -07:00
if (item.Video3DFormat) {
miscInfo.push("3D");
2013-04-18 19:52:22 -07:00
}
2013-04-10 22:27:27 -07:00
2013-05-05 20:58:45 -07:00
return miscInfo.join('&nbsp;&nbsp;&nbsp;&nbsp;');
2013-04-10 12:33:19 -07:00
},
2013-04-10 10:11:23 -07:00
2013-04-21 21:38:03 -07:00
renderOverview: function (elem, item) {
if (item.Overview || item.OverviewHtml) {
var overview = item.OverviewHtml || item.Overview;
elem.html(overview).show().trigger('create');
$('a', elem).each(function () {
$(this).attr("target", "_blank");
});
} else {
elem.hide();
}
},
2013-04-23 07:46:27 -07:00
renderStudios: function (elem, item, context) {
2013-04-10 12:33:19 -07:00
if (item.Studios && item.Studios.length) {
var prefix = item.Studios.length > 1 ? "Studios" : "Studio";
var html = prefix + ':&nbsp;&nbsp;';
2013-04-10 12:33:19 -07:00
for (var i = 0, length = item.Studios.length; i < length; i++) {
2013-04-10 12:33:19 -07:00
if (i > 0) {
html += '&nbsp;&nbsp;/&nbsp;&nbsp;';
}
2013-05-11 23:05:51 -07:00
html += '<a class="textlink" href="itembynamedetails.html?context=' + context + '&studio=' + ApiClient.encodeName(item.Studios[i].Name) + '">' + item.Studios[i].Name + '</a>';
}
2013-04-10 12:33:19 -07:00
elem.show().html(html).trigger('create');
2013-04-10 12:33:19 -07:00
} else {
elem.hide();
}
},
2013-04-23 07:46:27 -07:00
renderGenres: function (elem, item, context) {
2013-04-10 12:33:19 -07:00
if (item.Genres && item.Genres.length) {
var prefix = item.Genres.length > 1 ? "Genres" : "Genre";
var html = prefix + ':&nbsp;&nbsp;';
2013-04-10 12:33:19 -07:00
for (var i = 0, length = item.Genres.length; i < length; i++) {
2013-04-10 12:33:19 -07:00
if (i > 0) {
html += '&nbsp;&nbsp;/&nbsp;&nbsp;';
}
2013-07-01 08:59:32 -07:00
var param = item.Type == "Audio" || item.Type == "Artist" || item.Type == "MusicArtist" || item.Type == "MusicAlbum" ? "musicgenre" : "genre";
2013-07-01 10:17:33 -07:00
if (item.MediaType == "Game") {
param = "gamegenre";
}
html += '<a class="textlink" href="itembynamedetails.html?context=' + context + '&' + param + '=' + ApiClient.encodeName(item.Genres[i]) + '">' + item.Genres[i] + '</a>';
}
2013-04-10 12:33:19 -07:00
elem.show().html(html).trigger('create');
2013-04-12 08:25:00 -07:00
} else {
elem.hide();
2013-04-18 07:27:21 -07:00
}
},
renderPremiereDate: function (elem, item) {
if (item.PremiereDate) {
2013-04-18 22:08:18 -07:00
try {
2013-04-24 13:28:42 -07:00
var date = parseISO8601Date(item.PremiereDate, { toLocal: true });
var text = new Date().getTime() > date.getTime() ? "Premiered" : "Premieres";
elem.show().html(text + '&nbsp;&nbsp;' + date.toLocaleDateString());
2013-04-18 22:08:18 -07:00
} catch (err) {
elem.hide();
}
2013-04-18 07:27:21 -07:00
} else {
elem.hide();
2013-04-12 08:25:00 -07:00
}
},
2013-04-12 08:25:00 -07:00
renderBudget: function (elem, item) {
if (item.Budget) {
elem.show().html('Budget:&nbsp;&nbsp;$<span class="autoNumeric" data-a-pad="false">' + item.Budget + '</span>');
2013-04-10 12:33:19 -07:00
} else {
elem.hide();
}
2013-04-14 20:37:07 -07:00
},
2013-04-18 07:05:38 -07:00
renderRevenue: function (elem, item) {
if (item.Revenue) {
elem.show().html('Revenue:&nbsp;&nbsp;$<span class="autoNumeric" data-a-pad="false">' + item.Revenue + '</span>');
2013-04-18 07:05:38 -07:00
} else {
elem.hide();
}
},
renderDetailPageBackdrop: function (page, item) {
var screenWidth = Math.max(screen.height, screen.width);
var imgUrl;
if (item.BackdropImageTags && item.BackdropImageTags.length) {
imgUrl = LibraryBrowser.getImageUrl(item, 'Backdrop', 0, {
maxwidth: screenWidth
});
$('#itemBackdrop', page).removeClass('noBackdrop').css('background-image', 'url("' + imgUrl + '")');
}
else if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
imgUrl = ApiClient.getImageUrl(item.ParentBackdropItemId, {
type: 'Backdrop',
index: 0,
tag: item.ParentBackdropImageTags[0],
maxwidth: screenWidth
});
$('#itemBackdrop', page).removeClass('noBackdrop').css('background-image', 'url("' + imgUrl + '")');
}
else {
$('#itemBackdrop', page).addClass('noBackdrop').css('background-image', 'none');
}
},
shouldDisplayGallery: function (item) {
var imageTags = item.ImageTags || {};
2013-05-31 18:48:41 -07:00
if (imageTags.Primary) {
return true;
}
if (imageTags.Banner) {
return true;
}
if (imageTags.Logo) {
return true;
}
if (imageTags.Thumb) {
return true;
}
if (imageTags.Art) {
return true;
}
if (imageTags.Menu) {
return true;
}
if (imageTags.Disc) {
return true;
}
if (imageTags.Box) {
return true;
}
2013-04-28 18:27:01 -07:00
if (imageTags.BoxRear) {
return true;
}
if (item.BackdropImageTags && item.BackdropImageTags.length) {
return true;
}
if (item.ScreenshotImageTags && item.ScreenshotImageTags.length) {
return true;
}
return false;
},
2013-04-15 18:09:27 -07:00
getGalleryHtml: function (item) {
2013-04-15 19:36:12 -07:00
var html = '';
var i, length;
2013-04-15 18:09:27 -07:00
var imageTags = item.ImageTags || {};
2013-05-31 18:48:41 -07:00
if (imageTags.Primary) {
html += LibraryBrowser.createGalleryImage(item, "Primary", imageTags.Primary);
}
2013-04-15 18:15:34 -07:00
if (imageTags.Banner) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Banner", imageTags.Banner);
2013-04-15 18:15:34 -07:00
}
2013-04-15 18:09:27 -07:00
if (imageTags.Logo) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Logo", imageTags.Logo);
2013-04-15 19:36:12 -07:00
}
if (imageTags.Thumb) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Thumb", imageTags.Thumb);
2013-04-15 19:36:12 -07:00
}
if (imageTags.Art) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Art", imageTags.Art);
2013-04-15 19:36:12 -07:00
}
if (imageTags.Menu) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Menu", imageTags.Menu);
2013-04-15 19:36:12 -07:00
}
if (imageTags.Box) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Box", imageTags.Box);
2013-04-15 19:36:12 -07:00
}
2013-04-28 18:27:01 -07:00
if (imageTags.BoxRear) {
2013-05-12 13:30:23 -07:00
html += LibraryBrowser.createGalleryImage(item, "BoxRear", imageTags.BoxRear);
2013-04-28 18:27:01 -07:00
}
2013-04-15 19:36:12 -07:00
if (item.BackdropImageTags) {
2013-04-15 19:36:12 -07:00
for (i = 0, length = item.BackdropImageTags.length; i < length; i++) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Backdrop", item.BackdropImageTags[i], i);
2013-04-15 19:36:12 -07:00
}
2013-04-15 19:36:12 -07:00
}
2013-04-15 19:36:12 -07:00
if (item.ScreenshotImageTags) {
2013-04-15 19:36:12 -07:00
for (i = 0, length = item.ScreenshotImageTags.length; i < length; i++) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Screenshot", item.ScreenshotImageTags[i], i);
2013-04-15 19:36:12 -07:00
}
}
2013-04-22 07:44:11 -07:00
if (imageTags.Disc) {
2013-04-25 20:31:10 -07:00
html += LibraryBrowser.createGalleryImage(item, "Disc", imageTags.Disc);
2013-04-22 07:44:11 -07:00
}
2013-04-15 19:36:12 -07:00
return html;
},
2013-04-25 20:31:10 -07:00
createGalleryImage: function (item, type, tag, index) {
2013-05-15 21:16:26 -07:00
var screenWidth = Math.max(screen.height, screen.width);
screenWidth = Math.min(screenWidth, 1280);
2013-04-15 19:36:12 -07:00
var html = '';
2013-04-15 19:36:12 -07:00
if (typeof (index) == "undefined") index = 0;
2013-05-04 11:21:29 -07:00
html += '<div class="galleryImageContainer">';
2013-04-15 19:36:12 -07:00
html += '<a href="#pop_' + index + '_' + tag + '" data-transition="fade" data-rel="popup" data-position-to="window">';
2013-04-25 20:31:10 -07:00
html += '<img class="galleryImage" src="' + LibraryBrowser.getImageUrl(item, type, index, {
2013-05-15 21:16:26 -07:00
maxwidth: screenWidth,
2013-04-25 20:31:10 -07:00
tag: tag
2013-04-15 19:36:12 -07:00
}) + '" />';
html += '</div>';
2013-04-15 19:36:12 -07:00
html += '<div class="galleryPopup" id="pop_' + index + '_' + tag + '" data-role="popup" data-theme="d" data-corners="false" data-overlay-theme="a">';
html += '<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>';
2013-04-25 20:31:10 -07:00
html += '<img class="" src="' + LibraryBrowser.getImageUrl(item, type, index, {
2013-05-15 21:16:26 -07:00
maxwidth: screenWidth,
2013-04-25 20:31:10 -07:00
tag: tag
2013-04-27 15:52:41 -07:00
2013-04-15 19:36:12 -07:00
}) + '" />';
html += '</div>';
2013-04-15 19:36:12 -07:00
return html;
}
2013-04-10 06:53:44 -07:00
2013-04-10 12:33:19 -07:00
};
2013-05-15 12:26:52 -07:00
})(window, document, jQuery, screen, localStorage);
(function (window, document, $) {
var itemCountsPromise;
function renderHeader(page, user, counts) {
var html = '<div class="viewMenuBar">';
html += '<a class="viewMenuLink" href="index.html" title="Home"><img src="css/images/mblogoicon.png" alt="Home" /></a>';
var selectedCssClass = ' selectedViewLink';
var selectedHtml = "<span class='selectedViewIndicator'>&#9654;</span>";
var view = page.getAttribute('data-view');
if (counts.MovieCount || counts.TrailerCount) {
html += '<a class="viewMenuLink viewMenuImageLink" href="moviesrecommended.html" title="Movies"><img src="css/images/views/movies.png" alt="Movies" /></a>';
html += '<a class="viewMenuLink viewMenuTextLink' + (view == 'movies' ? selectedCssClass : '') + '" href="moviesrecommended.html">' + (view == 'movies' ? selectedHtml : '') + '<span class="viewName">Movies</span></a>';
}
if (counts.EpisodeCount || counts.SeriesCount) {
html += '<a class="viewMenuLink viewMenuImageLink" href="tvrecommended.html" title="TV"><img src="css/images/views/tvshows.png" alt="TV" /></a>';
html += '<a class="viewMenuLink viewMenuTextLink' + (view == 'tvshows' ? selectedCssClass : '') + '" href="tvrecommended.html">' + (view == 'tvshows' ? selectedHtml : '') + '<span class="viewName">TV</span></a>';
}
if (counts.SongCount) {
html += '<a class="viewMenuLink viewMenuImageLink" href="musicrecommended.html" title="Music"><img src="css/images/views/music.png" alt="Music" /></a>';
html += '<a class="viewMenuLink viewMenuTextLink' + (view == 'music' ? selectedCssClass : '') + '" href="musicrecommended.html">' + (view == 'music' ? selectedHtml : '') + '<span class="viewName">Music</span></a>';
}
if (counts.GameCount) {
html += '<a class="viewMenuLink viewMenuImageLink" href="gamesrecommended.html" title="Games"><img src="css/images/views/games.png" alt="Games" /></a>';
html += '<a class="viewMenuLink viewMenuTextLink' + (view == 'games' ? selectedCssClass : '') + '" href="gamesrecommended.html">' + (view == 'games' ? selectedHtml : '') + '<span class="viewName">Games</span></a>';
}
2013-07-11 13:25:12 -07:00
html += '<a class="viewMenuLink viewMenuImageLink remoteControlMenuLink" href="#" onclick="RemoteControl.showMenu();" title="Remote Control"><img src="css/images/remote.png" alt="Remote Control" /></a>';
html += '<div class="viewMenuSecondary">';
html += Search.getSearchHtml();
html += '<a class="viewMenuLink" class="btnCurrentUser" href="#" onclick="Dashboard.showUserFlyout(this);">';
if (user.PrimaryImageTag) {
var url = ApiClient.getUserImageUrl(user.Id, {
width: 225,
tag: user.PrimaryImageTag,
type: "Primary"
});
html += '<img src="' + url + '" />';
} else {
html += '<img src="css/images/currentuserdefaultwhite.png" />';
}
html += '</a>';
2013-07-16 10:18:32 -07:00
if (user.Configuration.IsAdministrator) {
html += '<a class="viewMenuLink" href="dashboard.html" title="Dashboard"><img src="css/images/toolswhite.png" alt="Dashboard" /></a>';
}
html += '</div>';
html += '</div>';
$(page).prepend(html);
Search.onSearchRendered($('.viewMenuBar', page));
}
$(document).on('pagebeforeshow', ".libraryPage", function () {
var page = this;
if (!$('.viewMenuBar', page).length) {
itemCountsPromise = itemCountsPromise || ApiClient.getItemCounts(Dashboard.getCurrentUserId());
itemCountsPromise.done(function (counts) {
Dashboard.getCurrentUser().done(function (user) {
renderHeader(page, user, counts);
});
});
}
});
})(window, document, jQuery);