var LibraryBrowser = (function (window, document, $, screen, localStorage) { var defaultBackground = "#333"; 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; }, loadSavedQueryValues: function (key, query) { var values = localStorage.getItem(key + '_' + Dashboard.getCurrentUserId()); if (values) { values = JSON.parse(values); return $.extend(query, values); } return query; }, saveQueryValues: function (key, query) { var values = {}; if (query.SortBy) { values.SortBy = query.SortBy; } if (query.SortOrder) { values.SortOrder = query.SortOrder; } localStorage.setItem(key + '_' + Dashboard.getCurrentUserId(), JSON.stringify(values)); }, saveViewSetting: function (key, value) { localStorage.setItem(key + '_' + Dashboard.getCurrentUserId() + '_view', value); }, getSavedViewSetting: function (key) { var deferred = $.Deferred(); var val = localStorage.getItem(key + '_' + Dashboard.getCurrentUserId() + '_view'); deferred.resolveWith(null, [val]); return deferred.promise(); }, getDateParamValue: function (date) { function formatDigit(i) { return i < 10 ? "0" + i : i; } var d = date; return "" + d.getFullYear() + formatDigit(d.getMonth() + 1) + formatDigit(d.getDate()) + formatDigit(d.getHours()) + formatDigit(d.getMinutes()) + formatDigit(d.getSeconds()); }, getItemCountsHtml: function (options, item) { var counts = []; var childText; if (options.context == "movies") { if (item.MovieCount) { childText = item.MovieCount == 1 ? "1 Movie" : item.MovieCount + " Movies"; counts.push(childText); } if (item.TrailerCount) { childText = item.TrailerCount == 1 ? "1 Trailer" : item.TrailerCount + " Trailers"; counts.push(childText); } } else if (options.context == "tv") { if (item.SeriesCount) { childText = item.SeriesCount == 1 ? "1 Show" : item.SeriesCount + " Shows"; counts.push(childText); } if (item.EpisodeCount) { childText = item.EpisodeCount == 1 ? "1 Episode" : item.EpisodeCount + " Episodes"; counts.push(childText); } } else if (options.context == "games") { if (item.GameCount) { childText = item.GameCount == 1 ? "1 Game" : item.GameCount + " Games"; counts.push(childText); } } else if (options.context == "music") { if (item.AlbumCount) { childText = item.AlbumCount == 1 ? "1 Album" : item.AlbumCount + " Albums"; counts.push(childText); } if (item.SongCount) { childText = item.SongCount == 1 ? "1 Song" : item.SongCount + " Songs"; counts.push(childText); } if (item.MusicVideoCount) { childText = item.MusicVideoCount == 1 ? "1 Music Video" : item.MusicVideoCount + " Music Videos"; counts.push(childText); } } return counts.join(' • '); }, getSongHeaderCellHtml: function (text, cssClass, enableSorting, sortField, selectedSortField, sortDirection) { var html = cssClass ? '
| '; html += ''; 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) { var artistLinksHtml = LibraryBrowser.getArtistLinksHtml(item.Artists); html += '' + artistLinksHtml + ' | '; } else { html += ''; } } if (options.showArtist) { if (item.AlbumArtist) { html += ' | ' + LibraryBrowser.getArtistLinksHtml([item.AlbumArtist]) + ' | '; } else { html += ''; } } var time = Dashboard.getDisplayTime(item.RunTimeTicks || 0); html += ' | ' + time + ' | '; html += '' + (item.UserData ? item.UserData.PlayCount : 0) + ' | '; 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');
if (markAsPlayed) {
ApiClient.markPlayed(Dashboard.getCurrentUserId(), id);
} else {
ApiClient.markUnplayed(Dashboard.getCurrentUserId(), id);
}
if (markAsPlayed) {
link.src = "css/images/userdata/checkedon.png";
$link.addClass('imgPlayed').removeClass('imgPlayedOff');
} else {
link.src = "css/images/userdata/checkedoff.png";
$link.addClass('imgPlayedOff').removeClass('imgPlayed');
}
},
markFavorite: function (link) {
var id = link.getAttribute('data-itemid');
var $link = $(link);
var markAsFavorite = $link.hasClass('imgFavoriteOff');
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 $link = $(link);
if ($link.hasClass('imgLikeOff')) {
ApiClient.updateUserItemRating(Dashboard.getCurrentUserId(), id, true);
link.src = "css/images/userdata/thumbs_up_on.png";
$link.addClass('imgLike').removeClass('imgLikeOff');
} else {
ApiClient.clearUserItemRating(Dashboard.getCurrentUserId(), 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 $link = $(link);
if ($link.hasClass('imgDislikeOff')) {
ApiClient.updateUserItemRating(Dashboard.getCurrentUserId(), id, false);
link.src = "css/images/userdata/thumbs_down_on.png";
$link.addClass('imgDislike').removeClass('imgDislikeOff');
} else {
ApiClient.clearUserItemRating(Dashboard.getCurrentUserId(), 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";
});
},
getDetailImageHtml: function (item, href) {
var imageTags = item.ImageTags || {};
if (item.PrimaryImageTag) {
imageTags.Primary = item.PrimaryImageTag;
}
var html = '';
var url;
var imageHeight = 600;
if (imageTags.Primary) {
url = ApiClient.getImageUrl(item.Id, {
type: "Primary",
maxheight: imageHeight,
tag: item.ImageTags.Primary
});
}
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
url = ApiClient.getImageUrl(item.Id, {
type: "Backdrop",
maxheight: imageHeight,
tag: item.BackdropImageTags[0]
});
}
else if (imageTags.Thumb) {
url = ApiClient.getImageUrl(item.Id, {
type: "Thumb",
maxheight: imageHeight,
tag: item.ImageTags.Thumb
});
}
else if (imageTags.Disc) {
url = ApiClient.getImageUrl(item.Id, {
type: "Disc",
maxheight: imageHeight,
tag: item.ImageTags.Disc
});
}
else if (item.AlbumId && item.AlbumPrimaryImageTag) {
url = ApiClient.getImageUrl(item.AlbumId, {
type: "Primary",
maxheight: imageHeight,
tag: item.AlbumPrimaryImageTag
});
}
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 if (item.Type == "TvChannel") {
url = "css/images/items/detail/tv.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 == "MusicArtist" || item.Type == "MusicGenre" || item.Type == "GameGenre") {
identifierName = item.Type;
identifierValue = ApiClient.encodeName(item.Name);
}
if (!href) {
href = "itemgallery.html?" + identifierName + "=" + identifierValue;
}
var linkToGallery = LibraryBrowser.shouldDisplayGallery(item);
html += '