2016-05-09 12:27:38 -07:00
|
|
|
|
define(['jQuery', 'libraryBrowser', 'scrollStyles'], function ($, libraryBrowser) {
|
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,
|
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-05-09 12:27:38 -07:00
|
|
|
|
var html = libraryBrowser.getPosterViewHtml({
|
2015-12-14 08:43:03 -07:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
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 + '\']');
|
|
|
|
|
if (enableScrollX()) {
|
|
|
|
|
$('.itemsContainer', tabContent).addClass('hiddenScrollX').createCardMenus();
|
|
|
|
|
} else {
|
|
|
|
|
$('.itemsContainer', tabContent).removeClass('hiddenScrollX').createCardMenus();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
depends.push('scripts/livetvguide');
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
depends.push('scripts/livetvchannels');
|
|
|
|
|
depends.push('paper-icon-item');
|
|
|
|
|
depends.push('paper-item-body');
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
depends.push('scripts/livetvrecordings');
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
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('viewshow', function (e) {
|
2016-04-26 11:28:04 -07:00
|
|
|
|
|
2016-05-15 10:11:26 -07:00
|
|
|
|
// Needed on the guide tab
|
|
|
|
|
// Ideally this should be moved to the guide tab on show/hide
|
|
|
|
|
document.body.classList.add('autoScrollY');
|
|
|
|
|
});
|
2016-04-26 11:28:04 -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
|
|
|
|
};
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|