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

198 lines
6.7 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() {
2015-12-14 08:43:03 -07:00
return browserInfo.mobile && AppInfo.enableAppLayouts;
2015-07-12 12:33:00 -07:00
}
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 [
2016-02-12 13:26:03 -07:00
{ name: 'HeaderFavoriteMovies', types: "Movie", id: "favoriteMovies", shape: getPosterShape(), showTitle: false, overlayPlayButton: true },
{ name: 'HeaderFavoriteShows', types: "Series", id: "favoriteShows", shape: getPosterShape(), showTitle: false, overlayPlayButton: true },
{ name: 'HeaderFavoriteEpisodes', types: "Episode", id: "favoriteEpisode", shape: getThumbShape(), preferThumb: false, showTitle: true, showParentTitle: true, overlayPlayButton: true },
2015-07-12 12:33:00 -07:00
{ name: 'HeaderFavoriteGames', types: "Game", id: "favoriteGames", shape: getSquareShape(), preferThumb: false, showTitle: true },
2015-12-29 19:32:54 -07:00
{ name: 'HeaderFavoriteArtists', types: "MusicArtist", id: "favoriteArtists", shape: getSquareShape(), preferThumb: false, showTitle: true, overlayText: false, showParentTitle: true, centerText: true, overlayPlayButton: true },
{ name: 'HeaderFavoriteAlbums', types: "MusicAlbum", id: "favoriteAlbums", shape: getSquareShape(), preferThumb: false, showTitle: true, overlayText: false, showParentTitle: true, centerText: true, overlayPlayButton: true },
2015-12-14 08:43:03 -07:00
{ name: 'HeaderFavoriteSongs', types: "Audio", id: "favoriteSongs", shape: getSquareShape(), preferThumb: false, showTitle: true, overlayText: false, showParentTitle: true, centerText: true, overlayMoreButton: true, defaultAction: 'instantmix' }
2014-05-29 12:34:20 -07:00
];
}
2015-12-14 08:43:03 -07:00
function loadSection(elem, userId, topParentId, section, isSingleSection) {
2014-05-29 12:34:20 -07:00
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",
Filters: "IsFavorite",
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
2015-12-14 08:43:03 -07:00
if (topParentId) {
options.ParentId = topParentId;
2014-05-29 12:34:20 -07:00
}
2015-12-14 08:43:03 -07:00
if (!isSingleSection) {
options.Limit = screenWidth >= 1920 ? 10 : (screenWidth >= 1440 ? 8 : 6);
if (enableScrollX()) {
options.Limit = 12;
}
}
var promise;
if (section.types == 'MusicArtist') {
promise = ApiClient.getArtists(userId, options);
} else {
options.IncludeItemTypes = section.types;
promise = ApiClient.getItems(userId, options);
}
return promise.then(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,
2015-12-14 08:43:03 -07:00
overlayMoreButton: section.overlayMoreButton,
context: 'home-favorites',
defaultAction: section.defaultAction
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
});
}
2015-12-14 08:43:03 -07:00
function loadSections(page, userId, topParentId, types) {
2014-05-29 12:34:20 -07:00
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;
});
}
2015-12-14 08:43:03 -07:00
if (types) {
sections = sections.filter(function (s) {
return types.indexOf(s.id) != -1;
});
}
2014-05-29 12:34:20 -07:00
var i, length;
2015-12-14 08:43:03 -07:00
var elem = page.querySelector('.favoriteSections');
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-12-14 08:43:03 -07:00
promises.push(loadSection(elem, userId, topParentId, section, sections.length == 1));
2014-05-29 12:34:20 -07:00
}
2015-06-17 18:41:22 -07:00
2015-12-14 08:43:03 -07:00
Promise.all(promises).then(function () {
2015-06-17 18:41:22 -07:00
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() {
2015-12-14 08:43:03 -07:00
if (window.HomePage) {
window.HomePage.renderFavorites = function (page, tabContent) {
if (LibraryBrowser.needsRefresh(tabContent)) {
loadSections(tabContent, Dashboard.getCurrentUserId());
}
};
}
2015-09-24 10:08:10 -07:00
}
initHomePage();
2015-12-14 08:43:03 -07:00
pageIdOn('pageinit', "indexPage", initHomePage);
pageIdOn('pagebeforeshow', "favoritesPage", function () {
2015-09-24 10:08:10 -07:00
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
2015-12-14 08:43:03 -07:00
window.FavoriteItems = {
render: loadSections
};
2014-10-15 20:26:39 -07:00
})(jQuery, document);