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

231 lines
6.3 KiB
JavaScript
Raw Normal View History

2016-04-10 21:24:16 -07:00
define(['jQuery', 'scrollStyles'], function ($) {
2014-01-12 08:58:47 -07:00
2015-12-14 08:43:03 -07:00
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
function getPortraitShape() {
return enableScrollX() ? 'overflowPortrait' : 'portrait';
}
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
function getSquareShape() {
return enableScrollX() ? 'overflowSquare' : 'square';
}
function getLimit() {
return enableScrollX() ? 12 : 8;
}
2015-05-15 11:28:34 -07:00
function loadRecommendedPrograms(page) {
2015-07-24 08:20:11 -07:00
2014-01-12 08:58:47 -07:00
Dashboard.showLoadingMsg();
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvRecommendedPrograms({
2014-01-12 08:58:47 -07:00
userId: Dashboard.getCurrentUserId(),
IsAiring: true,
2015-12-14 08:43:03 -07:00
limit: getLimit() * 2,
2015-08-03 17:09:54 -07:00
ImageTypeLimit: 1,
EnableImageTypes: "Primary"
2014-01-12 08:58:47 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (result) {
2015-06-29 22:45:20 -07:00
2015-12-14 08:43:03 -07:00
renderItems(page, result.Items, 'activeProgramItems', 'play');
2015-06-29 22:45:20 -07:00
LibraryBrowser.setLastRefreshed(page);
2015-12-14 08:43:03 -07:00
Dashboard.hideLoadingMsg();
2014-01-12 08:58:47 -07:00
});
2015-05-15 11:28:34 -07:00
}
function reload(page) {
loadRecommendedPrograms(page);
2014-01-12 08:58:47 -07:00
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvRecommendedPrograms({
2014-01-12 08:58:47 -07:00
userId: Dashboard.getCurrentUserId(),
IsAiring: false,
HasAired: false,
2015-12-14 08:43:03 -07:00
limit: getLimit(),
2015-04-03 09:31:56 -07:00
IsMovie: false,
2015-08-04 07:26:36 -07:00
IsSports: false,
IsKids: false,
IsSeries: true
2014-01-12 08:58:47 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (result) {
2014-01-12 08:58:47 -07:00
2015-12-14 08:43:03 -07:00
renderItems(page, result.Items, 'upcomingProgramItems');
2014-01-12 08:58:47 -07:00
});
2015-03-14 13:56:50 -07:00
ApiClient.getLiveTvRecommendedPrograms({
userId: Dashboard.getCurrentUserId(),
IsAiring: false,
HasAired: false,
2015-12-14 08:43:03 -07:00
limit: getLimit(),
2015-03-14 13:56:50 -07:00
IsMovie: true
2015-12-14 08:43:03 -07:00
}).then(function (result) {
renderItems(page, result.Items, 'upcomingTvMovieItems', null, getPortraitShape());
2015-03-14 13:56:50 -07:00
});
2015-04-03 09:31:56 -07:00
ApiClient.getLiveTvRecommendedPrograms({
userId: Dashboard.getCurrentUserId(),
IsAiring: false,
HasAired: false,
2015-12-14 08:43:03 -07:00
limit: getLimit(),
2015-04-03 09:31:56 -07:00
IsSports: true
2015-12-14 08:43:03 -07:00
}).then(function (result) {
renderItems(page, result.Items, 'upcomingSportsItems');
2015-04-03 09:31:56 -07:00
});
2015-08-18 23:12:58 -07:00
ApiClient.getLiveTvRecommendedPrograms({
userId: Dashboard.getCurrentUserId(),
IsAiring: false,
HasAired: false,
2015-12-14 08:43:03 -07:00
limit: getLimit(),
2015-08-18 23:12:58 -07:00
IsKids: true
2015-12-14 08:43:03 -07:00
}).then(function (result) {
renderItems(page, result.Items, 'upcomingKidsItems');
2015-08-18 23:12:58 -07:00
});
2014-01-12 08:58:47 -07:00
}
2015-12-14 08:43:03 -07:00
function renderItems(page, items, sectionClass, overlayButton, shape) {
var html = LibraryBrowser.getPosterViewHtml({
items: items,
shape: shape || (enableScrollX() ? getSquareShape() : 'auto'),
showTitle: true,
centerText: true,
coverImage: true,
overlayText: false,
lazy: true,
overlayMoreButton: overlayButton != 'play',
overlayPlayButton: overlayButton == 'play'
});
var elem = page.querySelector('.' + sectionClass);
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
}
function initSuggestedTab(page, tabContent) {
if (enableScrollX()) {
$('.itemsContainer', tabContent).addClass('hiddenScrollX').createCardMenus();
} else {
$('.itemsContainer', tabContent).removeClass('hiddenScrollX').createCardMenus();
}
}
2015-08-18 08:52:48 -07:00
function renderSuggestedTab(page, tabContent) {
2015-08-02 16:47:31 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
reload(tabContent);
}
}
function loadTab(page, index) {
2014-01-12 08:58:47 -07:00
2015-08-18 08:52:48 -07:00
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
var depends = [];
var scope = 'LiveTvPage';
var renderMethod = '';
var initMethod = '';
2015-08-02 16:47:31 -07:00
switch (index) {
case 0:
2015-08-18 08:52:48 -07:00
renderMethod = 'renderSuggestedTab';
2015-12-14 08:43:03 -07:00
initMethod = 'initSuggestedTab';
2015-08-18 08:52:48 -07:00
break;
case 1:
2015-12-14 08:43:03 -07:00
depends.push('registrationservices');
2015-08-18 08:52:48 -07:00
depends.push('scripts/livetvguide');
renderMethod = 'renderGuideTab';
initMethod = 'initGuideTab';
break;
case 2:
depends.push('scripts/livetvchannels');
2016-01-21 21:03:38 -07:00
depends.push('paper-icon-item');
depends.push('paper-item-body');
2015-08-18 08:52:48 -07:00
renderMethod = 'renderChannelsTab';
break;
case 3:
depends.push('scripts/livetvrecordings');
renderMethod = 'renderRecordingsTab';
break;
case 4:
depends.push('scripts/livetvtimers');
renderMethod = 'renderTimersTab';
break;
case 5:
depends.push('scripts/livetvseriestimers');
renderMethod = 'renderSeriesTimersTab';
2015-08-02 16:47:31 -07:00
break;
default:
break;
2015-06-29 21:33:53 -07:00
}
2015-08-18 08:52:48 -07:00
require(depends, function () {
if (initMethod && !tabContent.initComplete) {
window[scope][initMethod](page, tabContent);
tabContent.initComplete = true;
}
window[scope][renderMethod](page, tabContent);
});
2015-08-02 16:47:31 -07:00
}
2015-12-14 08:43:03 -07:00
pageIdOn('pageinit', "liveTvSuggestedPage", function () {
2015-08-02 16:47:31 -07:00
var page = this;
var tabs = page.querySelector('paper-tabs');
2016-03-24 11:11:03 -07:00
var pageTabsContainer = page.querySelector('.pageTabsContainer');
2015-08-02 16:47:31 -07:00
2016-03-24 11:11:03 -07:00
LibraryBrowser.configurePaperLibraryTabs(page, tabs, pageTabsContainer, 'livetv.html');
2015-08-02 16:47:31 -07:00
2016-03-24 11:11:03 -07:00
pageTabsContainer.addEventListener('tabchange', function (e) {
loadTab(page, parseInt(e.detail.selectedTabIndex));
2015-08-02 16:47:31 -07:00
});
2014-01-12 08:58:47 -07:00
});
2016-04-26 11:28:04 -07:00
pageIdOn('viewshow', "liveTvSuggestedPage", function () {
var page = this;
// Needed on the guide tab
// Ideally this should be moved to the guide tab on show/hide
document.body.classList.add('autoScrollY');
});
pageIdOn('viewbeforehide', "liveTvSuggestedPage", function () {
var page = this;
document.body.classList.remove('autoScrollY');
});
2015-08-18 08:52:48 -07:00
window.LiveTvPage = {
2015-12-14 08:43:03 -07:00
renderSuggestedTab: renderSuggestedTab,
initSuggestedTab: initSuggestedTab
2015-08-18 08:52:48 -07:00
};
});