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

117 lines
4.0 KiB
JavaScript
Raw Normal View History

2014-10-15 20:26:39 -07:00
(function ($, document) {
2014-05-29 12:34:20 -07:00
function getSections() {
return [
2015-01-22 23:15:15 -07:00
{ name: Globalize.translate('HeaderFavoriteMovies'), types: "Movie", id: "favoriteMovies", shape: 'backdrop', preferThumb: true, showTitle: false },
{ name: Globalize.translate('HeaderFavoriteShows'), types: "Series", id: "favoriteShows", shape: 'backdrop', preferThumb: true, showTitle: false },
{ name: Globalize.translate('HeaderFavoriteEpisodes'), types: "Episode", id: "favoriteEpisode", shape: 'backdrop', preferThumb: false, showTitle: true, showParentTitle: true },
{ name: Globalize.translate('HeaderFavoriteGames'), types: "Game", id: "favoriteGames", shape: 'autohome', preferThumb: false, showTitle: true },
2015-01-04 07:18:28 -07:00
{ name: Globalize.translate('HeaderFavoriteAlbums'), types: "MusicAlbum", id: "favoriteAlbums", shape: 'square', preferThumb: false, showTitle: true, overlayText: false, showParentTitle: true }
2014-05-29 12:34:20 -07:00
];
}
function loadSection(elem, userId, section, isSingleSection) {
var screenWidth = $(window).width();
var options = {
SortBy: isSingleSection ? "SortName" : "Random",
SortOrder: "Ascending",
IncludeItemTypes: section.types,
Filters: "IsFavorite",
2014-08-11 07:15:53 -07:00
Limit: screenWidth >= 1920 ? 10 : (screenWidth >= 1440 ? 8 : 6),
2014-05-29 12:34:20 -07:00
Recursive: true,
2014-12-10 23:20:28 -07:00
Fields: "PrimaryImageAspectRatio,SyncInfo",
2014-05-29 12:34:20 -07:00
CollapseBoxSetItems: false,
ExcludeLocationTypes: "Virtual"
};
2014-05-30 14:06:57 -07:00
2014-05-29 12:34:20 -07:00
if (isSingleSection) {
options.Limit = null;
}
ApiClient.getItems(userId, options).done(function (result) {
var html = '';
if (result.Items.length) {
html += '<h1 class="listHeader">' + section.name + '</h1>';
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferThumb: section.preferThumb,
shape: section.shape,
2014-08-01 19:34:45 -07:00
overlayText: section.overlayText !== false,
2014-05-29 12:34:20 -07:00
context: 'home-favorites',
showTitle: section.showTitle,
2014-05-29 21:16:31 -07:00
showParentTitle: section.showParentTitle,
2015-05-14 19:16:57 -07:00
lazy: true,
showDetailsMenu: true
2014-05-29 12:34:20 -07:00
});
if (result.TotalRecordCount > result.Items.length) {
2015-01-22 23:15:15 -07:00
html += '<div class="itemsContainer">';
2014-05-29 12:34:20 -07:00
var href = "favorites.html?sectionid=" + section.id;
2014-08-07 21:36:51 -07:00
html += '<a data-role="button" href="' + href + '" data-mini="true" data-inline="true">' + Globalize.translate('ButtonMoreItems') + '</a>';
2014-05-29 12:34:20 -07:00
html += '</div>';
}
html += '</div>';
}
elem = $(elem).html(html).trigger('create').lazyChildren();
2015-01-22 23:15:15 -07:00
elem.createCardMenus();
2014-05-29 12:34:20 -07:00
});
}
function loadSections(page, userId) {
var sections = getSections();
var sectionid = getParameterByName('sectionid');
if (sectionid) {
sections = sections.filter(function (s) {
return s.id == sectionid;
});
}
var i, length;
var elem = $('.sections', page);
if (!elem.html().length) {
var html = '';
for (i = 0, length = sections.length; i < length; i++) {
html += '<div class="homePageSection section' + sections[i].id + '"></div>';
}
elem.html(html);
}
for (i = 0, length = sections.length; i < length; i++) {
var section = sections[i];
elem = $('.section' + section.id, page);
loadSection(elem, userId, section, sections.length == 1);
}
}
2015-05-19 12:15:40 -07:00
$(document).on('pageshowready', "#favoritesPage", function () {
2014-05-29 12:34:20 -07:00
var page = this;
var userId = Dashboard.getCurrentUserId();
loadSections(page, userId);
});
2014-10-15 20:26:39 -07:00
})(jQuery, document);