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

255 lines
7.7 KiB
JavaScript
Raw Normal View History

2016-08-14 12:58:13 -07:00
define(['libraryBrowser', 'cardBuilder', 'scrollStyles', 'emby-itemscontainer', 'emby-tabs', 'emby-button'], function (libraryBrowser, cardBuilder) {
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 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();
2016-09-05 22:02:05 -07:00
var limit = getLimit();
if (enableScrollX()) {
limit *= 2;
}
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvRecommendedPrograms({
2014-01-12 08:58:47 -07:00
userId: Dashboard.getCurrentUserId(),
IsAiring: true,
2016-09-05 22:02:05 -07:00
limit: limit,
2015-08-03 17:09:54 -07:00
ImageTypeLimit: 1,
2016-09-16 22:47:49 -07:00
EnableImageTypes: "Primary,Thumb,Backdrop",
2016-09-05 13:07:36 -07:00
Fields: "ChannelInfo"
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');
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,
2016-05-08 20:13:38 -07:00
IsSeries: true,
2016-09-05 13:07:36 -07:00
EnableTotalRecordCount: false,
2016-09-14 09:20:03 -07:00
Fields: "ChannelInfo",
EnableImageTypes: "Primary,Thumb"
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(),
2016-05-08 20:13:38 -07:00
IsMovie: true,
2016-09-05 13:07:36 -07:00
EnableTotalRecordCount: false,
2016-09-14 09:20:03 -07:00
Fields: "ChannelInfo",
EnableImageTypes: "Primary,Thumb"
2015-03-14 13:56:50 -07:00
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(),
2016-05-08 20:13:38 -07:00
IsSports: true,
2016-09-05 13:07:36 -07:00
EnableTotalRecordCount: false,
2016-09-14 09:20:03 -07:00
Fields: "ChannelInfo",
EnableImageTypes: "Primary,Thumb"
2015-04-03 09:31:56 -07:00
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(),
2016-05-08 20:13:38 -07:00
IsKids: true,
2016-09-05 13:07:36 -07:00
EnableTotalRecordCount: false,
2016-09-14 09:20:03 -07:00
Fields: "ChannelInfo",
EnableImageTypes: "Primary,Thumb"
2015-08-18 23:12:58 -07:00
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) {
2016-07-29 13:06:58 -07:00
var html = cardBuilder.getCardsHtml({
2015-12-14 08:43:03 -07:00
items: items,
2016-09-05 13:07:36 -07:00
preferThumb: !shape,
2016-09-16 22:47:49 -07:00
inheritThumb: false,
2016-09-04 08:01:31 -07:00
shape: shape || (enableScrollX() ? 'overflowBackdrop' : 'backdrop'),
2016-09-16 05:21:22 -07:00
showParentTitleOrTitle: true,
showTitle: false,
2015-12-14 08:43:03 -07:00
centerText: true,
coverImage: true,
overlayText: false,
lazy: true,
overlayMoreButton: overlayButton != 'play',
2016-08-12 08:54:37 -07:00
overlayPlayButton: overlayButton == 'play',
2016-09-04 22:39:14 -07:00
allowBottomPadding: !enableScrollX(),
2016-09-30 11:43:59 -07:00
showAirTime: true,
showAirDateTime: true,
showChannelName: true
2016-09-05 13:07:36 -07:00
//cardFooterAside: 'logo'
2015-12-14 08:43:03 -07:00
});
var elem = page.querySelector('.' + sectionClass);
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
}
2016-05-15 10:11:26 -07:00
return function (view, params) {
2015-12-14 08:43:03 -07:00
2016-05-15 10:11:26 -07:00
var self = this;
2015-08-02 16:47:31 -07:00
2016-05-15 10:11:26 -07:00
self.initTab = function () {
2015-08-18 08:52:48 -07:00
2016-05-15 10:11:26 -07:00
var tabContent = view.querySelector('.pageTabContent[data-index=\'' + 0 + '\']');
2016-06-01 23:08:47 -07:00
var containers = tabContent.querySelectorAll('.itemsContainer');
for (var i = 0, length = containers.length; i < length; i++) {
if (enableScrollX()) {
containers[i].classList.add('hiddenScrollX');
2016-07-29 22:25:07 -07:00
containers[i].classList.remove('vertical-wrap');
2016-06-01 23:08:47 -07:00
} else {
containers[i].classList.remove('hiddenScrollX');
2016-07-29 22:25:07 -07:00
containers[i].classList.add('vertical-wrap');
2016-06-01 23:08:47 -07:00
}
2016-05-15 10:11:26 -07:00
}
};
self.renderTab = function () {
var tabContent = view.querySelector('.pageTabContent[data-index=\'' + 0 + '\']');
reload(tabContent);
};
var tabControllers = [];
var renderedTabs = [];
function loadTab(page, index) {
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
var depends = [];
switch (index) {
case 0:
break;
case 1:
2016-05-16 22:45:06 -07:00
document.body.classList.add('autoScrollY');
2016-05-15 10:11:26 -07:00
depends.push('scripts/livetvguide');
break;
case 2:
2016-05-16 22:45:06 -07:00
document.body.classList.remove('autoScrollY');
2016-05-15 10:11:26 -07:00
depends.push('scripts/livetvchannels');
break;
case 3:
2016-05-16 22:45:06 -07:00
document.body.classList.remove('autoScrollY');
2016-05-15 10:11:26 -07:00
depends.push('scripts/livetvrecordings');
break;
case 4:
2016-09-04 08:01:31 -07:00
document.body.classList.remove('autoScrollY');
depends.push('scripts/livetvschedule');
break;
case 5:
2016-05-16 22:45:06 -07:00
document.body.classList.remove('autoScrollY');
2016-05-15 10:11:26 -07:00
depends.push('scripts/livetvseriestimers');
break;
default:
break;
2015-08-18 08:52:48 -07:00
}
2016-05-15 10:11:26 -07:00
require(depends, function (controllerFactory) {
if (index == 0) {
self.tabContent = tabContent;
}
var controller = tabControllers[index];
if (!controller) {
controller = index ? new controllerFactory(view, params, tabContent) : self;
tabControllers[index] = controller;
if (controller.initTab) {
controller.initTab();
}
}
if (renderedTabs.indexOf(index) == -1) {
renderedTabs.push(index);
controller.renderTab();
}
});
}
2015-08-02 16:47:31 -07:00
2016-08-15 19:40:29 -07:00
var viewTabs = view.querySelector('.libraryViewNav');
2015-08-02 16:47:31 -07:00
2016-09-04 08:01:31 -07:00
libraryBrowser.configurePaperLibraryTabs(view, viewTabs, view.querySelectorAll('.pageTabContent'), [0, 2, 3, 4, 5]);
2015-08-02 16:47:31 -07:00
2016-08-15 19:40:29 -07:00
viewTabs.addEventListener('tabchange', function (e) {
2016-05-15 10:11:26 -07:00
loadTab(view, parseInt(e.detail.selectedTabIndex));
2015-08-02 16:47:31 -07:00
});
2014-01-12 08:58:47 -07:00
2016-05-15 10:11:26 -07:00
view.addEventListener('viewbeforehide', function (e) {
2016-04-26 11:28:04 -07:00
2016-05-15 10:11:26 -07:00
document.body.classList.remove('autoScrollY');
});
2016-04-26 11:28:04 -07:00
2016-09-01 09:36:11 -07:00
require(["headroom-window"], function (headroom) {
headroom.add(viewTabs);
self.headroom = headroom;
});
2016-08-15 19:40:29 -07:00
2016-05-15 10:11:26 -07:00
view.addEventListener('viewdestroy', function (e) {
2016-04-26 11:28:04 -07:00
2016-08-15 19:40:29 -07:00
if (self.headroom) {
self.headroom.remove(viewTabs);
}
2016-05-15 10:11:26 -07:00
tabControllers.forEach(function (t) {
if (t.destroy) {
t.destroy();
}
});
});
2015-08-18 08:52:48 -07:00
};
});