2016-04-10 21:24:16 -07:00
|
|
|
|
define(['libraryBrowser', 'scripts/alphapicker', 'scrollStyles'], function (libraryBrowser) {
|
2013-04-01 18:28:01 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
return function (view, params) {
|
2015-05-12 21:55:19 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var self = this;
|
2015-05-12 21:55:19 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function getView() {
|
2015-05-12 21:55:19 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
return 'Thumb';
|
|
|
|
|
}
|
2015-05-12 21:55:19 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function getResumeView() {
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
return 'Poster';
|
|
|
|
|
}
|
2015-06-16 12:17:12 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function reload() {
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-04-30 20:28:26 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
loadResume();
|
|
|
|
|
loadNextUp();
|
|
|
|
|
}
|
2015-05-07 07:04:10 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function loadNextUp() {
|
2014-02-22 22:52:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var limit = AppInfo.hasLowImageBandwidth ?
|
|
|
|
|
16 :
|
|
|
|
|
24;
|
2013-04-30 20:28:26 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var query = {
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
Limit: limit,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SeriesInfo,DateCreated,SyncInfo",
|
|
|
|
|
UserId: Dashboard.getCurrentUserId(),
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
|
|
|
|
|
};
|
2013-04-30 20:28:26 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
query.ParentId = LibraryMenu.getTopParentId();
|
2013-04-30 20:28:26 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
ApiClient.getNextUpEpisodes(query).then(function (result) {
|
2014-09-29 21:47:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (result.Items.length) {
|
|
|
|
|
view.querySelector('.noNextUpItems').classList.add('hide');
|
|
|
|
|
} else {
|
|
|
|
|
view.querySelector('.noNextUpItems').classList.remove('hide');
|
|
|
|
|
}
|
2015-06-29 22:45:20 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var viewStyle = getView();
|
|
|
|
|
var html = '';
|
2014-02-22 22:52:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (viewStyle == 'ThumbCard') {
|
2015-05-17 12:50:37 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
html += libraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
showTitle: true,
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
showParentTitle: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showDetailsMenu: true
|
|
|
|
|
});
|
2015-05-17 12:50:37 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
} else if (viewStyle == 'Thumb') {
|
|
|
|
|
|
|
|
|
|
html += libraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showParentTitle: true,
|
|
|
|
|
overlayText: false,
|
|
|
|
|
lazy: true,
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
showDetailsMenu: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
overlayPlayButton: AppInfo.enableAppLayouts
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var elem = view.querySelector('#nextUpItems');
|
|
|
|
|
elem.innerHTML = html;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-05-07 15:27:01 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function enableScrollX() {
|
|
|
|
|
return browserInfo.mobile && AppInfo.enableAppLayouts;
|
|
|
|
|
}
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function getThumbShape() {
|
|
|
|
|
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
|
|
|
|
|
}
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function loadResume() {
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var parentId = LibraryMenu.getTopParentId();
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var limit = 6;
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var options = {
|
2014-06-15 16:30:04 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
SortBy: "DatePlayed",
|
|
|
|
|
SortOrder: "Descending",
|
|
|
|
|
IncludeItemTypes: "Episode",
|
|
|
|
|
Filters: "IsResumable",
|
|
|
|
|
Limit: limit,
|
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SeriesInfo,UserData,SyncInfo",
|
|
|
|
|
ExcludeLocationTypes: "Virtual",
|
|
|
|
|
ParentId: parentId,
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
|
|
|
|
|
};
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), options).then(function (result) {
|
2015-09-28 20:35:50 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (result.Items.length) {
|
|
|
|
|
view.querySelector('#resumableSection').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
view.querySelector('#resumableSection').classList.add('hide');
|
|
|
|
|
}
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var viewStyle = getResumeView();
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
if (viewStyle == 'PosterCard') {
|
|
|
|
|
|
|
|
|
|
html += libraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: getThumbShape(),
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showParentTitle: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showDetailsMenu: true,
|
|
|
|
|
preferThumb: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else if (viewStyle == 'Poster') {
|
|
|
|
|
|
|
|
|
|
html += libraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: getThumbShape(),
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showParentTitle: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
showDetailsMenu: true,
|
|
|
|
|
overlayPlayButton: true,
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
centerText: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var elem = view.querySelector('#resumableItems');
|
|
|
|
|
elem.innerHTML = html;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
|
|
|
|
});
|
2015-09-21 10:46:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
self.initTab = function () {
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var tabContent = self.tabContent;
|
|
|
|
|
if (enableScrollX()) {
|
|
|
|
|
tabContent.querySelector('#resumableItems').classList.add('hiddenScrollX');
|
|
|
|
|
} else {
|
|
|
|
|
tabContent.querySelector('#resumableItems').classList.remove('hiddenScrollX');
|
|
|
|
|
}
|
|
|
|
|
libraryBrowser.createCardMenus(tabContent.querySelector('#resumableItems'));
|
|
|
|
|
};
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
self.renderTab = function () {
|
2016-03-18 20:14:53 -07:00
|
|
|
|
reload();
|
2016-03-18 12:43:17 -07:00
|
|
|
|
};
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 18:40:13 -07:00
|
|
|
|
var tabControllers = [];
|
2016-03-18 20:14:53 -07:00
|
|
|
|
var renderedTabs = [];
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function loadTab(page, index) {
|
|
|
|
|
|
|
|
|
|
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
|
|
|
|
|
var depends = [];
|
|
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
depends.push('scripts/tvlatest');
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
depends.push('scripts/tvupcoming');
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
depends.push('scripts/tvshows');
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
depends.push('scripts/episodes');
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
depends.push('scripts/tvgenres');
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
depends.push('scripts/tvstudios');
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
require(depends, function (controllerFactory) {
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (index == 0) {
|
|
|
|
|
self.tabContent = tabContent;
|
|
|
|
|
}
|
2016-03-18 18:40:13 -07:00
|
|
|
|
var controller = tabControllers[index];
|
|
|
|
|
if (!controller) {
|
|
|
|
|
controller = index ? new controllerFactory(view, params, tabContent) : self;
|
|
|
|
|
tabControllers[index] = controller;
|
|
|
|
|
|
|
|
|
|
if (controller.initTab) {
|
|
|
|
|
controller.initTab();
|
|
|
|
|
}
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 20:14:53 -07:00
|
|
|
|
if (renderedTabs.indexOf(index) == -1) {
|
|
|
|
|
renderedTabs.push(index);
|
|
|
|
|
controller.renderTab();
|
|
|
|
|
}
|
2016-03-18 12:43:17 -07:00
|
|
|
|
});
|
2016-03-16 22:04:32 -07:00
|
|
|
|
}
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function onPlaybackStop(e, state) {
|
|
|
|
|
|
|
|
|
|
if (state.NowPlayingItem && state.NowPlayingItem.MediaType == 'Video') {
|
|
|
|
|
|
2016-03-24 11:11:03 -07:00
|
|
|
|
var pageTabsContainer = view.querySelector('.pageTabsContainer');
|
|
|
|
|
|
|
|
|
|
pageTabsContainer.dispatchEvent(new CustomEvent("tabchange", {
|
|
|
|
|
detail: {
|
2016-03-25 19:37:18 -07:00
|
|
|
|
selectedTabIndex: libraryBrowser.selectedTab(pageTabsContainer)
|
2016-03-24 11:11:03 -07:00
|
|
|
|
}
|
|
|
|
|
}));
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-16 22:04:32 -07:00
|
|
|
|
|
2016-03-24 11:11:03 -07:00
|
|
|
|
var pageTabsContainer = view.querySelector('.pageTabsContainer');
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2015-09-21 11:39:18 -07:00
|
|
|
|
var baseUrl = 'tv.html';
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var topParentId = params.topParentId;
|
2015-09-21 10:46:02 -07:00
|
|
|
|
if (topParentId) {
|
|
|
|
|
baseUrl += '?topParentId=' + topParentId;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-28 20:35:50 -07:00
|
|
|
|
if (enableScrollX()) {
|
2016-03-16 22:04:32 -07:00
|
|
|
|
view.querySelector('#resumableItems').classList.add('hiddenScrollX');
|
2015-09-28 20:35:50 -07:00
|
|
|
|
} else {
|
2016-03-16 22:04:32 -07:00
|
|
|
|
view.querySelector('#resumableItems').classList.remove('hiddenScrollX');
|
2015-09-28 20:35:50 -07:00
|
|
|
|
}
|
2016-03-16 22:04:32 -07:00
|
|
|
|
libraryBrowser.createCardMenus(view.querySelector('#resumableItems'));
|
2015-09-28 20:35:50 -07:00
|
|
|
|
|
2016-03-24 11:11:03 -07:00
|
|
|
|
libraryBrowser.configurePaperLibraryTabs(view, view.querySelector('paper-tabs'), pageTabsContainer, baseUrl);
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-24 11:11:03 -07:00
|
|
|
|
pageTabsContainer.addEventListener('tabchange', function (e) {
|
|
|
|
|
loadTab(view, parseInt(e.detail.selectedTabIndex));
|
2015-09-21 10:46:02 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-03-16 22:04:32 -07:00
|
|
|
|
view.addEventListener('viewbeforeshow', function (e) {
|
2015-09-28 20:35:50 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (!view.getAttribute('data-title')) {
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var parentId = params.topParentId;
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-16 22:04:32 -07:00
|
|
|
|
if (parentId) {
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-16 22:04:32 -07:00
|
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), parentId).then(function (item) {
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
view.setAttribute('data-title', item.Name);
|
2016-03-16 22:04:32 -07:00
|
|
|
|
LibraryMenu.setTitle(item.Name);
|
|
|
|
|
});
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
|
|
|
|
|
2016-03-16 22:04:32 -07:00
|
|
|
|
} else {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
view.setAttribute('data-title', Globalize.translate('TabShows'));
|
2016-03-16 22:04:32 -07:00
|
|
|
|
LibraryMenu.setTitle(Globalize.translate('TabShows'));
|
|
|
|
|
}
|
2015-09-21 10:46:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 22:04:32 -07:00
|
|
|
|
Events.on(MediaController, 'playbackstop', onPlaybackStop);
|
|
|
|
|
});
|
2015-09-21 10:46:02 -07:00
|
|
|
|
|
2016-03-16 22:04:32 -07:00
|
|
|
|
view.addEventListener('viewbeforehide', function (e) {
|
2013-04-01 18:28:01 -07:00
|
|
|
|
|
2016-03-16 22:04:32 -07:00
|
|
|
|
Events.off(MediaController, 'playbackstop', onPlaybackStop);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
});
|