var LibraryBrowser = (function (window, document, $, screen, localStorage) { var defaultBackground = "#999;"; return { getDefaultPageSize: function () { var saved = localStorage.getItem('pagesize'); if (saved) { return parseInt(saved); } if (window.location.toString().toLowerCase().indexOf('localhost') != -1) { return 100; } return 20; }, getPosterDetailViewHtml: function (options) { var items = options.items; var currentYear; if (!options.shape) { options.shape = options.preferBackdrop ? "backdrop" : "poster"; } var primaryImageAspectRatio = options.useAverageAspectRatio ? LibraryBrowser.getAveragePrimaryImageAspectRatio(items) : null; var html = ''; for (var i = 0, length = items.length; i < length; i++) { var item = items[i]; if (options.timeline) { var year = item.ProductionYear || "Unknown Year"; if (year != currentYear) { html += '
' + LibraryBrowser.getRatingHtml(item) + '
'; } var childText = null; if (item.Type == "BoxSet") { childText = item.ChildCount == 1 ? "1 Movie" : item.ChildCount + " Movies"; html += '' + childText + '
'; } else if (item.Type == "GamePlatform") { childText = item.ChildCount == 1 ? "1 Game" : item.ChildCount + " Games"; html += '' + childText + '
'; } else if (item.Type == "MusicAlbum") { childText = item.ChildCount == 1 ? "1 Song" : item.ChildCount + " Songs"; html += '' + childText + '
'; } else if (item.Type == "Genre" || item.Type == "Studio" || item.Type == "Person" || item.Type == "Artist" || item.Type == "MusicGenre" || item.Type == "GameGenre") { childText = item.ChildCount == 1 ? "1 " + options.countNameSingular : item.ChildCount + " " + options.countNamePlural; html += '' + childText + '
'; } else if (item.Type == "Game") { html += '' + item.GameSystem + '
'; } else { html += '' + LibraryBrowser.getMiscInfoHtml(item) + '
'; } if (item.Type == "MusicAlbum") { html += '' + LibraryBrowser.getMiscInfoHtml(item) + '
'; } html += '' + LibraryBrowser.getUserDataIconsHtml(item) + '
'; html += '| '; html += ' | '; html += ' | Track | '; if (options.showAlbum) { html += 'Album | '; } if (options.showArtist) { html += 'Artist | '; } html += 'Duration | '; html += 'Play Count | '; html += ''; html += ' | ||
|---|---|---|---|---|---|---|---|---|---|
| '; var num = item.IndexNumber; if (num && item.ParentIndexNumber) { num = item.ParentIndexNumber + "." + num; } html += ' | ' + (num || "") + ' | '; html += '' + (item.Name || "") + ' | '; if (options.showAlbum) { if (item.Album && item.ParentId) { html += '' + item.Album + ' | '; } else { html += '' + (item.Album || '') + ' | '; } } if (options.showArtist) { if (item.Artists && item.Artists.length && item.Artists[0]) { var artist = item.Artists[0]; html += '' + artist + ' | '; } else { html += '' + (artist || '') + ' | '; } } var time = Dashboard.getDisplayTime(item.RunTimeTicks || 0); html += '' + time + ' | '; html += '' + (item.UserData ? item.UserData.PlayCount : 0) + ' | '; html += '' + LibraryBrowser.getUserDataIconsHtml(item) + ' | '; html += '
';
} else {
html += '
';
}
}
if (typeof userData.Likes == "undefined") {
html += '
';
} else {
html += '
';
}
return html;
},
markPlayed: function (link) {
var id = link.getAttribute('data-itemid');
var $link = $(link);
var markAsPlayed = $link.hasClass('imgPlayedOff');
ApiClient.updatePlayedStatus(Dashboard.getCurrentUserId(), id, markAsPlayed);
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');
}
},
markFavorite: function (link) {
var id = link.getAttribute('data-itemid');
var type = link.getAttribute('data-type');
var $link = $(link);
var markAsFavorite = $link.hasClass('imgFavoriteOff');
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);
}
else if (type == "MusicGenre") {
ApiClient.updateFavoriteMusicGenreStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
else if (type == "GameGenre") {
ApiClient.updateFavoriteGameGenreStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
else {
ApiClient.updateFavoriteStatus(Dashboard.getCurrentUserId(), id, markAsFavorite);
}
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');
}
},
markLike: function (link) {
var id = link.getAttribute('data-itemid');
var type = link.getAttribute('data-type');
var $link = $(link);
if ($link.hasClass('imgLikeOff')) {
LibraryBrowser.updateUserItemRating(type, id, true);
link.src = "css/images/userdata/thumbs_up_on.png";
$link.addClass('imgLike').removeClass('imgLikeOff');
} else {
LibraryBrowser.clearUserItemRating(type, id);
link.src = "css/images/userdata/thumbs_up_off.png";
$link.addClass('imgLikeOff').removeClass('imgLike');
}
$link.prev().removeClass('imgDislike').addClass('imgDislikeOff').each(function () {
this.src = "css/images/userdata/thumbs_down_off.png";
});
},
markDislike: function (link) {
var id = link.getAttribute('data-itemid');
var type = link.getAttribute('data-type');
var $link = $(link);
if ($link.hasClass('imgDislikeOff')) {
LibraryBrowser.updateUserItemRating(type, id, false);
link.src = "css/images/userdata/thumbs_down_on.png";
$link.addClass('imgDislike').removeClass('imgDislikeOff');
} else {
LibraryBrowser.clearUserItemRating(type, id);
link.src = "css/images/userdata/thumbs_down_off.png";
$link.addClass('imgDislikeOff').removeClass('imgDislike');
}
$link.next().removeClass('imgLike').addClass('imgLikeOff').each(function () {
this.src = "css/images/userdata/thumbs_up_off.png";
});
},
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);
}
else if (type == "MusicGenre") {
ApiClient.updateMusicGenreRating(Dashboard.getCurrentUserId(), id, likes);
}
else if (type == "GameGenre") {
ApiClient.updateGameGenreRating(Dashboard.getCurrentUserId(), id, likes);
}
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);
}
else if (type == "MusicGenre") {
ApiClient.clearMusicGenreRating(Dashboard.getCurrentUserId(), id);
}
else if (type == "GameGenre") {
ApiClient.clearGameGenreRating(Dashboard.getCurrentUserId(), id);
}
else {
ApiClient.clearUserItemRating(Dashboard.getCurrentUserId(), id);
}
},
getDetailImageHtml: function (item) {
var imageTags = item.ImageTags || {};
var html = '';
var url;
if (imageTags.Primary) {
if (item.Type == "Person") {
url = ApiClient.getPersonImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Primary,
type: "Primary"
});
}
else if (item.Type == "Genre") {
url = ApiClient.getGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Primary,
type: "Primary"
});
}
else if (item.Type == "MusicGenre") {
url = ApiClient.getMusicGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Primary,
type: "Primary"
});
}
else if (item.Type == "GameGenre") {
url = ApiClient.getGameGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Primary,
type: "Primary"
});
}
else if (item.Type == "Studio") {
url = ApiClient.getStudioImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Primary,
type: "Primary"
});
}
else if (item.Type == "Artist") {
url = ApiClient.getArtistImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Primary,
type: "Primary"
});
}
else {
url = ApiClient.getImageUrl(item.Id, {
type: "Primary",
maxheight: 480,
tag: item.ImageTags.Primary
});
}
}
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
if (item.Type == "Person") {
url = ApiClient.getPersonImageUrl(item.Name, {
maxheight: 480,
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else if (item.Type == "Genre") {
url = ApiClient.getGenreImageUrl(item.Name, {
maxheight: 480,
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else if (item.Type == "MusicGenre") {
url = ApiClient.getMusicGenreImageUrl(item.Name, {
maxheight: 480,
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else if (item.Type == "GameGenre") {
url = ApiClient.getGameGenreImageUrl(item.Name, {
maxheight: 480,
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else if (item.Type == "Studio") {
url = ApiClient.getStudioImageUrl(item.Name, {
maxheight: 480,
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else if (item.Type == "Artist") {
url = ApiClient.getArtistImageUrl(item.Name, {
maxheight: 480,
tag: item.BackdropImageTags[0],
type: "Backdrop"
});
}
else {
url = ApiClient.getImageUrl(item.Id, {
type: "Backdrop",
maxheight: 480,
tag: item.BackdropImageTags[0]
});
}
}
else if (imageTags.Thumb) {
if (item.Type == "Person") {
url = ApiClient.getPersonImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Thumb,
type: "Thumb"
});
}
else if (item.Type == "Genre") {
url = ApiClient.getGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Thumb,
type: "Thumb"
});
}
else if (item.Type == "MusicGenre") {
url = ApiClient.getMusicGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Thumb,
type: "Thumb"
});
}
else if (item.Type == "GameGenre") {
url = ApiClient.getGameGenreImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Thumb,
type: "Thumb"
});
}
else if (item.Type == "Studio") {
url = ApiClient.getStudioImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Thumb,
type: "Thumb"
});
}
else if (item.Type == "Artist") {
url = ApiClient.getArtistImageUrl(item.Name, {
maxheight: 480,
tag: imageTags.Thumb,
type: "Thumb"
});
}
else {
url = ApiClient.getImageUrl(item.Id, {
type: "Thumb",
maxheight: 480,
tag: item.ImageTags.Thumb
});
}
}
else if (imageTags.Disc) {
url = ApiClient.getImageUrl(item.Id, {
type: "Disc",
maxheight: 480,
tag: item.ImageTags.Disc
});
}
else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicGenre") {
url = "css/images/items/detail/audio.png";
}
else if (item.MediaType == "Game" || item.Type == "GameGenre") {
url = "css/images/items/detail/game.png";
}
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";
}
else {
url = "css/images/items/detail/video.png";
}
var identifierName = "id";
var identifierValue = item.Id;
if (item.Type == "Person" || item.Type == "Genre" || item.Type == "Studio" || item.Type == "Artist" || item.Type == "MusicGenre" || item.Type == "GameGenre") {
identifierName = item.Type;
identifierValue = ApiClient.encodeName(item.Name);
}
var href = "itemgallery.html?" + identifierName + "=" + identifierValue;
var linkToGallery = LibraryBrowser.shouldDisplayGallery(item);
if (linkToGallery) {
html += "";
}
html += "
';
html += '' + (view == 'movies' ? selectedHtml : '') + 'Movies';
}
if (counts.EpisodeCount || counts.SeriesCount) {
html += '
';
html += '' + (view == 'tvshows' ? selectedHtml : '') + 'TV';
}
if (counts.SongCount) {
html += '
';
html += '' + (view == 'music' ? selectedHtml : '') + 'Music';
}
if (counts.GameCount) {
html += '
';
html += '' + (view == 'games' ? selectedHtml : '') + 'Games';
}
html += '
';
}
html += '';
html += '
';
html += '