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

321 lines
9.1 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();
2015-05-07 07:04:10 -07:00
if (LibraryMenu.getTopParentId()) {
$('.scopedContent', page).show();
loadResume(page);
} else {
$('.scopedContent', page).hide();
}
2015-08-17 09:52:56 -07:00
loadNextUp(page);
}
2015-08-17 09:52:56 -07:00
function loadNextUp(page) {
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
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();
2015-12-14 08:43:03 -07:00
ApiClient.getNextUpEpisodes(query).then(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
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,
lazy: true,
2015-05-14 19:16:57 -07:00
preferThumb: true,
2015-07-17 15:32:00 -07:00
showDetailsMenu: true,
centerText: true,
2015-07-19 20:43:13 -07:00
overlayPlayButton: AppInfo.enableAppLayouts
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();
2015-06-29 22:45:20 -07:00
LibraryBrowser.setLastRefreshed(page);
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-12-14 08:43:03 -07:00
return browserInfo.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-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"
};
2015-12-14 08:43:03 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), options).then(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-07-19 20:43:13 -07:00
showDetailsMenu: true,
preferThumb: 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,
lazy: true,
2015-07-17 15:32:00 -07:00
showDetailsMenu: true,
2015-07-19 20:43:13 -07:00
overlayPlayButton: true,
2015-07-26 14:02:23 -07:00
preferThumb: true,
centerText: 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-09-28 20:35:50 -07:00
function initSuggestedTab(page, tabContent) {
2015-09-21 10:46:02 -07:00
if (enableScrollX()) {
tabContent.querySelector('#resumableItems').classList.add('hiddenScrollX');
} else {
tabContent.querySelector('#resumableItems').classList.remove('hiddenScrollX');
}
2015-09-28 20:35:50 -07:00
$(tabContent.querySelector('#resumableItems')).createCardMenus();
}
function loadSuggestionsTab(page, tabContent) {
2015-09-21 10:46:02 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
reload(tabContent);
}
}
function loadTab(page, index) {
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
var depends = [];
var scope = 'TvPage';
var renderMethod = '';
var initMethod = '';
switch (index) {
case 0:
2015-09-28 20:35:50 -07:00
initMethod = 'initSuggestedTab';
2015-09-21 10:46:02 -07:00
renderMethod = 'renderSuggestedTab';
break;
case 1:
depends.push('scripts/tvlatest');
renderMethod = 'renderLatestTab';
break;
case 2:
depends.push('scripts/tvupcoming');
renderMethod = 'renderUpcomingTab';
break;
case 3:
depends.push('scripts/tvshows');
depends.push('scripts/queryfilters');
renderMethod = 'renderSeriesTab';
initMethod = 'initSeriesTab';
break;
case 4:
depends.push('scripts/episodes');
renderMethod = 'renderEpisodesTab';
initMethod = 'initEpisodesTab';
break;
case 5:
depends.push('scripts/tvgenres');
renderMethod = 'renderGenresTab';
break;
case 6:
depends.push('scripts/tvstudios');
renderMethod = 'renderStudiosTab';
break;
default:
break;
}
require(depends, function () {
if (initMethod && !tabContent.initComplete) {
window[scope][initMethod](page, tabContent);
tabContent.initComplete = true;
}
window[scope][renderMethod](page, tabContent);
});
}
window.TvPage = window.TvPage || {};
window.TvPage.renderSuggestedTab = loadSuggestionsTab;
2015-09-28 20:35:50 -07:00
window.TvPage.initSuggestedTab = initSuggestedTab;
2015-09-21 10:46:02 -07:00
pageIdOn('pageinit', "tvRecommendedPage", function () {
var page = this;
$('.recommendations', page).createCardMenus();
var tabs = page.querySelector('paper-tabs');
var pages = page.querySelector('neon-animated-pages');
2015-09-21 11:39:18 -07:00
var baseUrl = 'tv.html';
2015-09-21 10:46:02 -07:00
var topParentId = LibraryMenu.getTopParentId();
if (topParentId) {
baseUrl += '?topParentId=' + topParentId;
}
2015-09-28 20:35:50 -07:00
if (enableScrollX()) {
page.querySelector('#resumableItems').classList.add('hiddenScrollX');
} else {
page.querySelector('#resumableItems').classList.remove('hiddenScrollX');
}
$(page.querySelector('#resumableItems')).createCardMenus();
2015-09-21 10:46:02 -07:00
LibraryBrowser.configurePaperLibraryTabs(page, tabs, pages, baseUrl);
2015-12-14 08:43:03 -07:00
pages.addEventListener('tabchange', function (e) {
2015-09-21 10:46:02 -07:00
loadTab(page, parseInt(this.selected));
});
});
2015-09-28 20:35:50 -07:00
pageIdOn('pagebeforeshow', "tvRecommendedPage", function () {
var page = this;
2015-09-21 10:46:02 -07:00
if (!page.getAttribute('data-title')) {
var parentId = LibraryMenu.getTopParentId();
if (parentId) {
2015-12-14 08:43:03 -07:00
ApiClient.getItem(Dashboard.getCurrentUserId(), parentId).then(function (item) {
2015-09-21 10:46:02 -07:00
page.setAttribute('data-title', item.Name);
LibraryMenu.setTitle(item.Name);
});
} else {
page.setAttribute('data-title', Globalize.translate('TabShows'));
LibraryMenu.setTitle(Globalize.translate('TabShows'));
}
}
2015-12-23 10:46:01 -07:00
Events.on(MediaController, 'playbackstop', onPlaybackStop);
2015-09-21 10:46:02 -07:00
});
pageIdOn('pagebeforehide', "tvRecommendedPage", function () {
var page = this;
2015-12-23 10:46:01 -07:00
Events.off(MediaController, 'playbackstop', onPlaybackStop);
2015-09-21 10:46:02 -07:00
});
function onPlaybackStop(e, state) {
if (state.NowPlayingItem && state.NowPlayingItem.MediaType == 'Video') {
var page = $($.mobile.activePage)[0];
var pages = page.querySelector('neon-animated-pages');
2015-12-14 08:43:03 -07:00
pages.dispatchEvent(new CustomEvent("tabchange", {}));
2015-09-21 10:46:02 -07:00
}
}
2013-04-01 18:28:01 -07:00
})(jQuery, document);