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

164 lines
5.3 KiB
JavaScript
Raw Normal View History

2014-10-15 20:26:39 -07:00
(function ($, document) {
2014-05-29 12:34:20 -07:00
2015-07-12 12:33:00 -07:00
function enableScrollX() {
return $.browser.mobile && AppInfo.enableAppLayouts;
}
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
function getPosterShape() {
2015-07-13 14:26:11 -07:00
return enableScrollX() ? 'overflowPortrait' : 'portrait';
2015-07-12 12:33:00 -07:00
}
function getSquareShape() {
return enableScrollX() ? 'overflowSquare' : 'square';
}
2014-05-29 12:34:20 -07:00
function getSections() {
return [
2015-07-12 12:33:00 -07:00
{ name: 'HeaderFavoriteMovies', types: "Movie", id: "favoriteMovies", shape: getPosterShape(), showTitle: false },
{ name: 'HeaderFavoriteShows', types: "Series", id: "favoriteShows", shape: getPosterShape(), showTitle: false },
{ name: 'HeaderFavoriteEpisodes', types: "Episode", id: "favoriteEpisode", shape: getThumbShape(), preferThumb: false, showTitle: true, showParentTitle: true },
{ name: 'HeaderFavoriteGames', types: "Game", id: "favoriteGames", shape: getSquareShape(), preferThumb: false, showTitle: true },
{ name: 'HeaderFavoriteAlbums', types: "MusicAlbum", id: "favoriteAlbums", shape: getSquareShape(), preferThumb: false, showTitle: true, overlayText: false, showParentTitle: true, centerText: true, overlayPlayButton: true }
2014-05-29 12:34:20 -07:00
];
}
function loadSection(elem, userId, section, isSingleSection) {
var screenWidth = $(window).width();
var options = {
2015-07-12 12:33:00 -07:00
SortBy: "SortName",
2014-05-29 12:34:20 -07:00
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;
}
2015-06-17 18:41:22 -07:00
return ApiClient.getItems(userId, options).done(function (result) {
2014-05-29 12:34:20 -07:00
var html = '';
if (result.Items.length) {
2015-07-12 12:33:00 -07:00
2014-05-29 12:34:20 -07:00
html += '<div>';
2015-07-12 12:33:00 -07:00
html += '<h1 style="display:inline-block; vertical-align:middle;" class="listHeader">' + Globalize.translate(section.name) + '</h1>';
if (result.TotalRecordCount > result.Items.length) {
var href = "secondaryitems.html?type=" + section.types + "&filters=IsFavorite&titlekey=" + section.name;
2015-08-20 20:21:27 -07:00
html += '<a class="clearLink" href="' + href + '" style="margin-left:2em;"><paper-button raised class="more mini">' + Globalize.translate('ButtonMore') + '</paper-button></a>';
2015-07-12 12:33:00 -07:00
}
html += '</div>';
if (enableScrollX()) {
html += '<div class="itemsContainer hiddenScrollX">';
} else {
html += '<div class="itemsContainer">';
}
2014-05-29 12:34:20 -07:00
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
showTitle: section.showTitle,
2014-05-29 21:16:31 -07:00
showParentTitle: section.showParentTitle,
2015-05-14 19:16:57 -07:00
lazy: true,
2015-07-08 17:20:01 -07:00
showDetailsMenu: true,
centerText: section.centerText,
2015-07-27 09:21:18 -07:00
overlayPlayButton: section.overlayPlayButton,
context: 'home-favorites'
2014-05-29 12:34:20 -07:00
});
2015-06-26 20:27:38 -07:00
html += '</div>';
2014-05-29 12:34:20 -07:00
}
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
$(elem).createCardMenus();
2014-05-29 12:34:20 -07:00
});
}
function loadSections(page, userId) {
2015-06-17 18:41:22 -07:00
Dashboard.showLoadingMsg();
2014-05-29 12:34:20 -07:00
var sections = getSections();
var sectionid = getParameterByName('sectionid');
if (sectionid) {
sections = sections.filter(function (s) {
return s.id == sectionid;
});
}
var i, length;
2015-09-07 21:22:38 -07:00
var elem = page.querySelector('.sections');
2014-05-29 12:34:20 -07:00
2015-09-07 21:22:38 -07:00
if (!elem.innerHTML) {
2014-05-29 12:34:20 -07:00
var html = '';
for (i = 0, length = sections.length; i < length; i++) {
html += '<div class="homePageSection section' + sections[i].id + '"></div>';
}
2015-09-07 21:22:38 -07:00
elem.innerHTML = html;
2014-05-29 12:34:20 -07:00
}
2015-06-17 18:41:22 -07:00
var promises = [];
2014-05-29 12:34:20 -07:00
for (i = 0, length = sections.length; i < length; i++) {
var section = sections[i];
2015-06-28 07:45:21 -07:00
elem = page.querySelector('.section' + section.id);
2014-05-29 12:34:20 -07:00
2015-06-17 18:41:22 -07:00
promises.push(loadSection(elem, userId, section, sections.length == 1));
2014-05-29 12:34:20 -07:00
}
2015-06-17 18:41:22 -07:00
$.when(promises).done(function () {
Dashboard.hideLoadingMsg();
2015-06-30 10:21:20 -07:00
LibraryBrowser.setLastRefreshed(page);
2015-06-17 18:41:22 -07:00
});
2014-05-29 12:34:20 -07:00
}
2015-09-24 10:08:10 -07:00
function initHomePage() {
window.HomePage.renderFavorites = function (page, tabContent) {
if (LibraryBrowser.needsRefresh(tabContent)) {
loadSections(tabContent, Dashboard.getCurrentUserId());
}
};
}
initHomePage();
pageIdOn('pageshow', "favoritesPage", function () {
var page = this;
if (LibraryBrowser.needsRefresh(page)) {
loadSections(page, Dashboard.getCurrentUserId());
2015-08-18 08:35:51 -07:00
}
2015-09-24 10:08:10 -07:00
});
2014-05-29 12:34:20 -07:00
2014-10-15 20:26:39 -07:00
})(jQuery, document);