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

228 lines
6.7 KiB
JavaScript
Raw Normal View History

2016-07-29 13:06:58 -07:00
define(['libraryBrowser', 'cardBuilder', 'scrollStyles', 'emby-itemscontainer'], 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();
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,
2016-05-08 20:13:38 -07:00
EnableImageTypes: "Primary",
EnableTotalRecordCount: false
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,
EnableTotalRecordCount: false
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,
EnableTotalRecordCount: false
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,
EnableTotalRecordCount: false
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,
EnableTotalRecordCount: false
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-05-18 14:46:56 -07:00
shape: shape || (enableScrollX() ? 'autooverflow' : 'auto'),
2015-12-14 08:43:03 -07:00
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);
}
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-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-05-15 10:11:26 -07:00
var mdlTabs = view.querySelector('.libraryViewNav');
2015-08-02 16:47:31 -07:00
2016-05-15 10:11:26 -07:00
var baseUrl = 'tv.html';
var topParentId = params.topParentId;
if (topParentId) {
baseUrl += '?topParentId=' + topParentId;
}
2016-05-09 12:27:38 -07:00
2016-05-16 10:11:49 -07:00
libraryBrowser.configurePaperLibraryTabs(view, mdlTabs, view.querySelectorAll('.pageTabContent'), [0, 2, 3, 4]);
2015-08-02 16:47:31 -07:00
2016-05-09 12:27:38 -07:00
mdlTabs.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-05-15 10:11:26 -07:00
view.addEventListener('viewdestroy', function (e) {
2016-04-26 11:28:04 -07:00
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
};
});