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 += '

' + year + '

'; currentYear = year; } } var imgUrl = null; var isDefault = false; var cssClass = "tileItem"; if (options.shape) { cssClass += " " + options.shape + "TileItem"; } html += ''; if (options.preferBackdrop && item.BackdropImageTags && item.BackdropImageTags.length) { imgUrl = LibraryBrowser.getImageUrl(item, 'Backdrop', 0, { height: 198, width: 352 }); } else if (options.preferBackdrop && item.ImageTags && item.ImageTags.Thumb) { imgUrl = ApiClient.getImageUrl(item.Id, { type: "Thumb", height: 198, width: 352, tag: item.ImageTags.Thumb }); } else if (item.ImageTags && item.ImageTags.Primary) { var height = 300; var width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null; imgUrl = LibraryBrowser.getImageUrl(item, 'Primary', 0, { height: height, width: width }); } else if (item.BackdropImageTags && item.BackdropImageTags.length) { imgUrl = LibraryBrowser.getImageUrl(item, 'Backdrop', 0, { height: 198, width: 352 }); } else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist") { imgUrl = "css/images/items/list/audio.png"; isDefault = true; } else if (item.MediaType == "Video" || item.Type == "Season" || item.Type == "Series") { imgUrl = "css/images/items/list/video.png"; isDefault = true; } else if (item.Type == "Person") { imgUrl = "css/images/items/list/person.png"; isDefault = true; } else if (item.Type == "Artist") { imgUrl = "css/images/items/list/audiocollection.png"; isDefault = true; } else if (item.MediaType == "Game") { imgUrl = "css/images/items/list/game.png"; isDefault = true; } else if (item.Type == "Studio" || item.Type == "Genre" || item.Type == "MusicGenre" || item.Type == "GameGenre") { 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; } else { imgUrl = "css/images/items/list/collection.png"; isDefault = true; } cssClass = isDefault ? "tileImage defaultTileImage" : "tileImage"; html += '
'; html += '
'; if (item.SeriesName || item.Album) { var seriesName = item.SeriesName || item.Album; html += '
' + seriesName + '
'; } var name = LibraryBrowser.getPosterViewDisplayName(item); html += '
' + name + '
'; if (item.CommunityRating || item.CriticRating) { 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 += '
'; if (item.LocationType == "Offline") { html += LibraryBrowser.getOfflineIndicatorHtml(item); } else { html += LibraryBrowser.getNewIndicatorHtml(item); } html += "
"; } return html; }, getSongTableHtml: function (items, options) { options = options || {}; var html = ''; var cssClass = "detailTable"; html += '
'; html += ''; html += ''; html += ''; html += ''; if (options.showAlbum) { html += ''; } if (options.showArtist) { html += ''; } html += ''; html += ''; html += ''; html += ''; for (var i = 0, length = items.length; i < length; i++) { var item = items[i]; html += ''; html += ''; var num = item.IndexNumber; if (num && item.ParentIndexNumber) { num = item.ParentIndexNumber + "." + num; } html += ''; html += ''; if (options.showAlbum) { if (item.Album && item.ParentId) { html += ''; } else { html += ''; } } if (options.showArtist) { if (item.Artists && item.Artists.length && item.Artists[0]) { var artist = item.Artists[0]; html += ''; } else { html += ''; } } var time = Dashboard.getDisplayTime(item.RunTimeTicks || 0); html += ''; html += ''; html += ''; html += ''; } html += '
TrackAlbumArtistDurationPlay Count
' + (num || "") + '' + (item.Name || "") + '' + item.Album + '' + (item.Album || '') + '' + artist + '' + (artist || '') + '' + time + '' + (item.UserData ? item.UserData.PlayCount : 0) + '' + LibraryBrowser.getUserDataIconsHtml(item) + '
'; return html; }, showPlayMenu: function (positionTo, itemId, itemType, mediaType, resumePositionTicks) { var isPlaying = MediaPlayer.isPlaying(); if (!isPlaying && !resumePositionTicks) { MediaPlayer.playById(itemId); return; } $('.playFlyout').popup("close").remove(); var html = '
'; html += ''; html += '
'; $($.mobile.activePage).append(html); $('.playFlyout').popup({ positionTo: positionTo || "window" }).trigger('create').popup("open").on("popupafterclose", function () { $(this).off("popupafterclose").remove(); }).parents(".ui-popup-container").css("margin-left", 100).css("margin-top", 35); }, closePlayMenu: function () { $('.playFlyout').popup("close").remove(); }, getHref: function (item, itemByNameContext) { if (item.url) { return item.url; } itemByNameContext = itemByNameContext || ""; // Handle search hints var id = item.Id || item.ItemId; if (item.Type == "Series") { return "itemdetails.html?id=" + id; } if (item.Type == "Season") { return "itemdetails.html?id=" + id; } if (item.Type == "BoxSet") { return "itemdetails.html?id=" + id; } if (item.Type == "MusicAlbum") { return "itemdetails.html?id=" + id; } if (item.Type == "GamePlatform") { return "itemdetails.html?id=" + id; } if (item.Type == "Genre") { return "itembynamedetails.html?genre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext; } if (item.Type == "MusicGenre") { return "itembynamedetails.html?musicgenre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext; } if (item.Type == "GameGenre") { return "itembynamedetails.html?gamegenre=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext; } if (item.Type == "Studio") { return "itembynamedetails.html?studio=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext; } if (item.Type == "Person") { return "itembynamedetails.html?person=" + ApiClient.encodeName(item.Name) + "&context=" + itemByNameContext; } if (item.Type == "Artist") { return "itembynamedetails.html?artist=" + ApiClient.encodeName(item.Name) + "&context=" + (itemByNameContext || "music"); } return item.IsFolder ? (id ? "itemList.html?parentId=" + id : "#") : "itemdetails.html?id=" + id; }, getImageUrl: function (item, type, index, options) { options = options || {}; options.type = type; options.index = index; if (type == 'Backdrop') { options.tag = item.BackdropImageTags[index]; } else if (type == 'Screenshot') { options.tag = item.ScreenshotImageTags[index]; } else if (type == 'Primary') { options.tag = item.PrimaryImageTag || item.ImageTags[type]; } else { options.tag = item.ImageTags[type]; } 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); } if (item.Type == "MusicGenre") { return ApiClient.getMusicGenreImageUrl(item.Name, options); } if (item.Type == "GameGenre") { return ApiClient.getGameGenreImageUrl(item.Name, options); } if (item.Type == "Artist") { return ApiClient.getArtistImageUrl(item.Name, options); } // For search hints return ApiClient.getImageUrl(item.Id || item.ItemId, options); }, getPosterViewHtml: function (options) { var items = options.items; options.shape = options.shape || "portrait"; var primaryImageAspectRatio = options.useAverageAspectRatio ? LibraryBrowser.getAveragePrimaryImageAspectRatio(items) : null; var html = ""; for (var i = 0, length = items.length; i < length; i++) { var item = items[i]; var imgUrl = null; var background = null; if (options.preferBackdrop && item.BackdropImageTags && item.BackdropImageTags.length) { imgUrl = ApiClient.getImageUrl(item.Id, { type: "Backdrop", height: 198, width: 352, tag: item.BackdropImageTags[0] }); } else if (item.ImageTags && item.ImageTags.Primary) { var height = 300; var width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null; imgUrl = ApiClient.getImageUrl(item.Id, { type: "Primary", height: height, width: width, tag: item.ImageTags.Primary }); } else if (item.BackdropImageTags && item.BackdropImageTags.length) { imgUrl = ApiClient.getImageUrl(item.Id, { type: "Backdrop", height: 198, width: 352, tag: item.BackdropImageTags[0] }); } else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist") { if (item.Name && options.showTitle) { imgUrl = 'css/images/items/list/audio.png'; background = defaultBackground; } else { background = '#555'; } } else if (item.MediaType == "Video" || item.Type == "Season" || item.Type == "Series") { if (item.Name && options.showTitle) { imgUrl = 'css/images/items/list/video.png'; background = defaultBackground; } else { background = '#555'; } } else { if (item.Name && options.showTitle) { imgUrl = 'css/images/items/list/collection.png'; background = LibraryBrowser.getMetroColor(item.Id); } else { background = '#555'; } } var cssClass = "posterItem"; if (options.transparent !== false) { cssClass += " transparentPosterItem"; } cssClass += ' ' + options.shape + 'PosterItem'; html += ''; var style = ""; if (imgUrl) { style += 'background-image:url(\'' + imgUrl + '\');'; } if (background) { style += "background-color:" + background + ";"; } html += '
'; var name = LibraryBrowser.getPosterViewDisplayName(item); if (!imgUrl && !options.showTitle) { html += "
"; html += name; html += "
"; } var cssclass = options.centerText ? "posterItemText posterItemTextCentered" : "posterItemText"; if (options.showParentTitle) { html += "
"; html += item.SeriesName || item.Album || " "; html += "
"; } if (options.showTitle) { html += "
"; html += name; html += "
"; } if (options.showProgressBar) { html += "
"; html += LibraryBrowser.getItemProgressBarHtml(item) || " "; html += "
"; } if (item.LocationType == "Offline") { html += LibraryBrowser.getOfflineIndicatorHtml(item); } else if (options.showNewIndicator !== false) { html += LibraryBrowser.getNewIndicatorHtml(item); } html += "
"; } return html; }, getPosterViewDisplayName: function (item) { 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; }, getOfflineIndicatorHtml: function () { return '
Offline
'; }, getNewIndicatorHtml: function (item) { if (item.RecentlyAddedItemCount) { return '
' + item.RecentlyAddedItemCount + ' New
'; } if (!item.IsFolder && item.Type !== "Genre" && item.Type !== "Studio" && item.Type !== "Person" && item.Type !== "Artist" && item.Type !== "MusicGenre" && item.Type !== "GameGenre") { var date = item.DateCreated; try { if (date && (new Date().getTime() - parseISO8601Date(date).getTime()) < 604800000) { return "
New
"; } } catch (err) { } } return ''; }, getAveragePrimaryImageAspectRatio: function (items) { var values = []; for (var i = 0, length = items.length; i < length; i++) { var ratio = items[i].PrimaryImageAspectRatio || 0; if (!ratio) { continue; } values[values.length] = ratio; } if (!values.length) { return null; } // Use the median values.sort(function (a, b) { return a - b; }); var half = Math.floor(values.length / 2); if (values.length % 2) return values[half]; else return (values[half - 1] + values[half]) / 2.0; }, metroColors: ["#6FBD45", "#4BB3DD", "#4164A5", "#E12026", "#800080", "#E1B222", "#008040", "#0094FF", "#FF00C7", "#FF870F", "#7F0037"], getRandomMetroColor: function () { var index = Math.floor(Math.random() * (LibraryBrowser.metroColors.length - 1)); return LibraryBrowser.metroColors[index]; }, getMetroColor: function (str) { if (str) { var character = String(str.substr(0, 1).charCodeAt()); var sum = 0; for (var i = 0; i < character.length; i++) { sum += parseInt(character.charAt(i)); } var index = String(sum).substr(-1); return LibraryBrowser.metroColors[index]; } else { return LibraryBrowser.getRandomMetroColor(); } }, renderName: function (item, nameElem, linkToElement) { var name = LibraryBrowser.getPosterViewDisplayName(item); Dashboard.setPageTitle(name); if (linkToElement) { nameElem.html('' + name + '').trigger('create'); } else { nameElem.html(name); } }, renderParentName: function (item, parentNameElem) { var html = []; if (item.AlbumArtist && item.Type == "Audio") { html.push('' + item.AlbumArtist + ''); } else if (item.AlbumArtist && item.Type == "MusicAlbum") { html.push('' + item.AlbumArtist + ''); } else if (item.SeriesName && item.Type == "Episode") { html.push('' + item.SeriesName + ''); } if (item.SeriesName && item.Type == "Season") { html.push('' + item.SeriesName + ''); } else if (item.ParentIndexNumber && item.Type == "Episode") { html.push('Season ' + item.ParentIndexNumber + ''); } else if (item.Album && item.Type == "Audio" && item.ParentId) { html.push('' + item.Album + ''); } 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(); } }, renderLinks: function (linksElem, item) { var links = []; if (item.HomePageUrl) { links.push('Website'); } var providerIds = item.ProviderIds || {}; if (providerIds.Imdb) { if (item.Type == "Person") { links.push('IMDb'); } else { links.push('IMDb'); } } if (providerIds.Tmdb) { if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "MusicVideo") links.push('TheMovieDB'); else if (item.Type == "BoxSet") links.push('TheMovieDB'); else if (item.Type == "Person") links.push('TheMovieDB'); } if (providerIds.Tvdb) links.push('TheTVDB'); if (providerIds.Tvcom) { if (item.Type == "Episode") links.push('TV.com'); else if (item.Type == "Person") links.push('TV.com'); } if (providerIds.Musicbrainz) { if (item.Type == "MusicArtist" || item.Type == "Artist") { links.push('MusicBrainz'); } else { links.push('MusicBrainz'); } } if (providerIds.Gamesdb) links.push('GamesDB'); if (links.length) { var html = 'Links:  ' + links.join('  /  '); $(linksElem).html(html).trigger('create'); } else { $(linksElem).hide(); } }, getPagingHtml: function (query, totalRecordCount) { if (query.Limit) { localStorage.setItem('pagesize', query.Limit); } var html = ''; var pageCount = Math.ceil(totalRecordCount / query.Limit); var pageNumber = (query.StartIndex / query.Limit) + 1; var dropdownHtml = ''; var recordsEnd = Math.min(query.StartIndex + query.Limit, totalRecordCount); // 20 is the minimum page size var showControls = totalRecordCount > 20; html += '
'; html += ''; var startAtDisplay = totalRecordCount ? query.StartIndex + 1 : 0; html += startAtDisplay + '-' + recordsEnd + ' of ' + totalRecordCount; if (showControls) { html += ', page ' + dropdownHtml + ' of ' + pageCount; } html += ''; if (showControls) { html += ''; html += ''; var id = "selectPageSize" + new Date().getTime(); var options = ''; function getOption(val) { if (query.Limit == val) { return ''; } else { return ''; } } options += getOption(20); options += getOption(50); options += getOption(100); options += getOption(200); options += getOption(300); html += ''; } html += '
'; return html; }, getRatingHtml: function (item) { var html = ""; if (item.CommunityRating) { var rating = item.CommunityRating / 2; for (var i = 1; i <= 5; i++) { if (rating < i - 1) { html += "
"; } else if (rating < i) { html += "
"; } else { html += "
"; } } } if (item.CriticRating != null) { if (item.CriticRating >= 60) { html += '
'; } else { html += '
'; } html += '
' + item.CriticRating + '%
'; } return html; }, getItemProgressBarHtml: function (item) { var html = ''; var tooltip; var pct; if (item.PlayedPercentage) { tooltip = item.PlayedPercentage.toFixed(1).toString().replace(".0", '') + '% '; if (item.Type == "Series" || item.Type == "Season" || item.Type == "BoxSet") { tooltip += "watched"; } else { tooltip += "played"; } pct = item.PlayedPercentage; } else if (item.UserData && item.UserData.PlaybackPositionTicks && item.RunTimeTicks) { tooltip = Dashboard.getDisplayTime(item.UserData.PlaybackPositionTicks) + " / " + Dashboard.getDisplayTime(item.RunTimeTicks); pct = (item.UserData.PlaybackPositionTicks / item.RunTimeTicks) * 100; } if (pct && pct < 100) { html += ''; html += ''; html += '' + tooltip + ''; } return html; }, getUserDataIconsHtml: function (item) { var html = ''; if (item.Type != "Audio") { html += LibraryBrowser.getItemProgressBarHtml(item); } var userData = item.UserData || {}; var itemId = item.Id; var type = item.Type; if (type == "Person") { itemId = item.Name; } else if (type == "Studio") { itemId = item.Name; } else if (type == "Genre") { itemId = item.Name; } else if (type == "MusicGenre") { itemId = item.Name; } else if (type == "GameGenre") { itemId = item.Name; } else if (type == "Artist") { itemId = item.Name; } if (item.MediaType || item.IsFolder) { if (userData.Played) { html += 'Played'; } else { html += 'Played'; } } if (typeof userData.Likes == "undefined") { html += 'Dislike'; html += 'Like'; } else if (userData.Likes) { html += 'Dislike'; html += 'Like'; } else { html += 'Dislike'; html += 'Like'; } if (userData.IsFavorite) { html += 'Favorite'; } else { html += 'Favorite'; } 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 += ""; if (linkToGallery) { html += ""; } return html; }, getMiscInfoHtml: function (item) { var miscInfo = []; var text; if (item.Type == "Episode") { if (item.PremiereDate) { try { var date = parseISO8601Date(item.PremiereDate, { toLocal: true }); text = date.toLocaleDateString(); miscInfo.push(text); } catch (e) { console.log("Error parsing date: " + item.PremiereDate); } } } if (item.ProductionYear && item.Type == "Series") { if (item.Status == "Continuing") { miscInfo.push(item.ProductionYear + "-Present"); } else if (item.ProductionYear) { text = item.ProductionYear; if (item.EndDate) { try { var endYear = parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear(); if (endYear != item.ProductionYear) { text += "-" + parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear(); } } catch (e) { console.log("Error parsing date: " + item.EndDate); } } miscInfo.push(text); } } if (item.Type != "Series" && item.Type != "Episode") { if (item.ProductionYear) { miscInfo.push(item.ProductionYear); } else if (item.PremiereDate) { try { text = parseISO8601Date(item.PremiereDate, { toLocal: true }).getFullYear(); miscInfo.push(text); } catch (e) { console.log("Error parsing date: " + item.PremiereDate); } } } if (item.RunTimeTicks) { if (item.Type == "Audio") { miscInfo.push(Dashboard.getDisplayTime(item.RunTimeTicks)); } else { var minutes = item.RunTimeTicks / 600000000; minutes = minutes || 1; miscInfo.push(parseInt(minutes) + "min"); } } if (item.OfficialRating) { miscInfo.push(item.OfficialRating); } if (item.MediaType && item.DisplayMediaType && item.DisplayMediaType != item.Type) { miscInfo.push(item.DisplayMediaType); } if (item.Video3DFormat) { miscInfo.push("3D"); } return miscInfo.join('    '); }, 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(); } }, renderStudios: function (elem, item, context) { if (item.Studios && item.Studios.length) { var prefix = item.Studios.length > 1 ? "Studios" : "Studio"; var html = prefix + ':  '; for (var i = 0, length = item.Studios.length; i < length; i++) { if (i > 0) { html += '  /  '; } html += '' + item.Studios[i].Name + ''; } elem.show().html(html).trigger('create'); } else { elem.hide(); } }, renderGenres: function (elem, item, context) { if (item.Genres && item.Genres.length) { var prefix = item.Genres.length > 1 ? "Genres" : "Genre"; var html = prefix + ':  '; for (var i = 0, length = item.Genres.length; i < length; i++) { if (i > 0) { html += '  /  '; } var param = item.Type == "Audio" || item.Type == "Artist" || item.Type == "MusicArtist" || item.Type == "MusicAlbum" ? "musicgenre" : "genre"; if (item.MediaType == "Game") { param = "gamegenre"; } html += '' + item.Genres[i] + ''; } elem.show().html(html).trigger('create'); } else { elem.hide(); } }, renderPremiereDate: function (elem, item) { if (item.PremiereDate) { try { var date = parseISO8601Date(item.PremiereDate, { toLocal: true }); var text = new Date().getTime() > date.getTime() ? "Premiered" : "Premieres"; elem.show().html(text + '  ' + date.toLocaleDateString()); } catch (err) { elem.hide(); } } else { elem.hide(); } }, renderBudget: function (elem, item) { if (item.Budget) { elem.show().html('Budget:  $' + item.Budget + ''); } else { elem.hide(); } }, renderRevenue: function (elem, item) { if (item.Revenue) { elem.show().html('Revenue:  $' + item.Revenue + ''); } 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 || {}; 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; } if (imageTags.BoxRear) { return true; } if (item.BackdropImageTags && item.BackdropImageTags.length) { return true; } if (item.ScreenshotImageTags && item.ScreenshotImageTags.length) { return true; } return false; }, getGalleryHtml: function (item) { var html = ''; var i, length; var imageTags = item.ImageTags || {}; if (imageTags.Primary) { html += LibraryBrowser.createGalleryImage(item, "Primary", imageTags.Primary); } if (imageTags.Banner) { html += LibraryBrowser.createGalleryImage(item, "Banner", imageTags.Banner); } if (imageTags.Logo) { html += LibraryBrowser.createGalleryImage(item, "Logo", imageTags.Logo); } if (imageTags.Thumb) { html += LibraryBrowser.createGalleryImage(item, "Thumb", imageTags.Thumb); } if (imageTags.Art) { html += LibraryBrowser.createGalleryImage(item, "Art", imageTags.Art); } if (imageTags.Menu) { html += LibraryBrowser.createGalleryImage(item, "Menu", imageTags.Menu); } if (imageTags.Box) { html += LibraryBrowser.createGalleryImage(item, "Box", imageTags.Box); } if (imageTags.BoxRear) { html += LibraryBrowser.createGalleryImage(item, "BoxRear", imageTags.BoxRear); } if (item.BackdropImageTags) { for (i = 0, length = item.BackdropImageTags.length; i < length; i++) { html += LibraryBrowser.createGalleryImage(item, "Backdrop", item.BackdropImageTags[i], i); } } if (item.ScreenshotImageTags) { for (i = 0, length = item.ScreenshotImageTags.length; i < length; i++) { html += LibraryBrowser.createGalleryImage(item, "Screenshot", item.ScreenshotImageTags[i], i); } } if (imageTags.Disc) { html += LibraryBrowser.createGalleryImage(item, "Disc", imageTags.Disc); } return html; }, createGalleryImage: function (item, type, tag, index) { var screenWidth = Math.max(screen.height, screen.width); screenWidth = Math.min(screenWidth, 1280); var html = ''; if (typeof (index) == "undefined") index = 0; html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += 'Close'; html += ''; html += '
'; return html; } }; })(window, document, jQuery, screen, localStorage); (function (window, document, $) { var itemCountsPromise; function renderHeader(page, user, counts) { var html = '
'; html += 'Home'; var selectedCssClass = ' selectedViewLink'; var selectedHtml = ""; var view = page.getAttribute('data-view'); if (counts.MovieCount || counts.TrailerCount) { html += 'Movies'; html += '' + (view == 'movies' ? selectedHtml : '') + 'Movies'; } if (counts.EpisodeCount || counts.SeriesCount) { html += 'TV'; html += '' + (view == 'tvshows' ? selectedHtml : '') + 'TV'; } if (counts.SongCount) { html += 'Music'; html += '' + (view == 'music' ? selectedHtml : '') + 'Music'; } if (counts.GameCount) { html += 'Games'; html += '' + (view == 'games' ? selectedHtml : '') + 'Games'; } html += 'Remote Control'; html += '
'; html += Search.getSearchHtml(); html += ''; if (user.PrimaryImageTag) { var url = ApiClient.getUserImageUrl(user.Id, { width: 225, tag: user.PrimaryImageTag, type: "Primary" }); html += ''; } else { html += ''; } html += ''; if (user.Configuration.IsAdministrator) { html += 'Dashboard'; } html += '
'; html += '
'; $(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);