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

187 lines
5.0 KiB
JavaScript
Raw Normal View History

2013-04-01 18:28:01 -07:00
(function ($, document) {
2015-05-12 21:55:19 -07:00
function getView() {
return 'Thumb';
}
function getResumeView() {
return 'Poster';
}
function reload(page) {
2015-06-16 12:17:12 -07:00
Dashboard.showLoadingMsg();
2014-07-10 21:27:46 -07:00
var context = '';
2015-05-07 07:04:10 -07:00
if (LibraryMenu.getTopParentId()) {
$('.scopedContent', page).show();
2014-07-10 21:27:46 -07:00
context = 'tv';
loadResume(page);
} else {
$('.scopedContent', page).hide();
}
2014-07-10 21:27:46 -07:00
loadNextUp(page, context || 'home-nextup');
}
2014-07-10 21:27:46 -07:00
function loadNextUp(page, context) {
2013-04-30 20:28:26 -07:00
2015-05-07 07:04:10 -07:00
var limit = AppInfo.hasLowImageBandwidth ?
2015-05-07 15:27:01 -07:00
16 :
2015-05-07 07:04:10 -07:00
24;
2014-06-14 16:13:09 -07:00
var query = {
2014-02-22 22:52:30 -07:00
2015-05-07 07:04:10 -07:00
Limit: limit,
2014-12-10 23:20:28 -07:00
Fields: "PrimaryImageAspectRatio,SeriesInfo,DateCreated,SyncInfo",
2014-02-22 22:52:30 -07:00
UserId: Dashboard.getCurrentUserId(),
2014-11-30 12:01:33 -07:00
ExcludeLocationTypes: "Virtual",
ImageTypeLimit: 1,
2014-12-01 05:43:34 -07:00
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
2013-04-30 20:28:26 -07:00
};
2014-06-14 16:13:09 -07:00
query.ParentId = LibraryMenu.getTopParentId();
2014-06-14 16:13:09 -07:00
ApiClient.getNextUpEpisodes(query).done(function (result) {
2013-04-30 20:28:26 -07:00
if (result.Items.length) {
2014-03-31 14:04:22 -07:00
$('.noNextUpItems', page).hide();
2013-04-30 20:28:26 -07:00
} else {
2014-03-31 14:04:22 -07:00
$('.noNextUpItems', page).show();
2013-04-30 20:28:26 -07:00
}
2015-05-12 21:55:19 -07:00
var view = getView();
var html = '';
if (view == 'ThumbCard') {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
preferThumb: true,
showParentTitle: true,
lazy: true,
cardLayout: true,
2015-05-14 19:16:57 -07:00
context: 'tv',
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
} else if (view == 'Thumb') {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
showParentTitle: true,
overlayText: false,
context: context,
lazy: true,
2015-05-14 19:16:57 -07:00
preferThumb: true,
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
}
2014-09-29 21:47:30 -07:00
2015-06-28 08:43:49 -07:00
var elem = page.querySelector('#nextUpItems');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
2015-06-16 12:17:12 -07:00
Dashboard.hideLoadingMsg();
2013-04-30 20:28:26 -07:00
});
2014-02-22 22:52:30 -07:00
}
2015-05-17 12:50:37 -07:00
function enableScrollX() {
2015-06-04 13:27:46 -07:00
return $.browser.mobile && AppInfo.enableAppLayouts;
2015-05-17 12:50:37 -07:00
}
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
function loadResume(page) {
var parentId = LibraryMenu.getTopParentId();
2015-05-12 06:58:03 -07:00
var screenWidth = $(window).width();
2015-06-17 08:39:46 -07:00
var limit = 6;
2015-05-07 15:27:01 -07:00
var options = {
SortBy: "DatePlayed",
SortOrder: "Descending",
IncludeItemTypes: "Episode",
Filters: "IsResumable",
2015-05-07 15:27:01 -07:00
Limit: limit,
Recursive: true,
2014-12-10 23:20:28 -07:00
Fields: "PrimaryImageAspectRatio,SeriesInfo,UserData,SyncInfo",
ExcludeLocationTypes: "Virtual",
2014-11-30 12:01:33 -07:00
ParentId: parentId,
ImageTypeLimit: 1,
2014-12-01 05:43:34 -07:00
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
};
ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) {
if (result.Items.length) {
$('#resumableSection', page).show();
} else {
$('#resumableSection', page).hide();
}
2015-05-12 21:55:19 -07:00
var view = getResumeView();
var html = '';
if (view == 'PosterCard') {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
2015-05-17 12:50:37 -07:00
shape: getThumbShape(),
2015-05-12 21:55:19 -07:00
showTitle: true,
showParentTitle: true,
lazy: true,
cardLayout: true,
2015-05-14 19:16:57 -07:00
context: 'tv',
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
} else if (view == 'Poster') {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
2015-05-17 12:50:37 -07:00
shape: getThumbShape(),
2015-05-12 21:55:19 -07:00
showTitle: true,
showParentTitle: true,
overlayText: screenWidth >= 800 && !AppInfo.hasLowImageBandwidth,
lazy: true,
2015-05-14 19:16:57 -07:00
context: 'tv',
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
}
2015-06-28 08:43:49 -07:00
var elem = page.querySelector('#resumableItems');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
});
}
2015-06-16 10:37:49 -07:00
$(document).on('pagebeforeshowready', "#tvRecommendedPage", function () {
2014-02-22 22:52:30 -07:00
var page = this;
2013-04-30 20:28:26 -07:00
2015-05-17 12:50:37 -07:00
if (enableScrollX()) {
2015-06-28 07:45:21 -07:00
page.querySelector('#resumableItems').classList.add('hiddenScrollX');
2015-05-17 12:50:37 -07:00
} else {
2015-06-28 07:45:21 -07:00
page.querySelector('#resumableItems').classList.remove('hiddenScrollX');
2015-05-17 12:50:37 -07:00
}
reload(page);
2013-04-30 20:28:26 -07:00
});
2013-04-01 18:28:01 -07:00
})(jQuery, document);