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

302 lines
9.5 KiB
JavaScript
Raw Normal View History

2016-06-06 22:42:26 -07:00
define(['libraryBrowser', '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() {
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() {
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 query = {
2016-05-22 15:37:50 -07:00
Limit: 24,
2016-03-18 12:43:17 -07:00
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,
2016-05-22 15:37:50 -07:00
shape: "backdrop",
2016-03-18 12:43:17 -07:00
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,
2016-05-22 15:37:50 -07:00
shape: "backdrop",
2016-03-18 12:43:17 -07:00
showTitle: true,
showParentTitle: true,
overlayText: false,
lazy: true,
preferThumb: true,
showDetailsMenu: true,
centerText: true,
overlayPlayButton: AppInfo.enableAppLayouts
});
}
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;
}
2016-03-18 12:43:17 -07:00
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
2016-03-18 12:43:17 -07:00
function loadResume() {
2016-03-18 12:43:17 -07:00
var parentId = LibraryMenu.getTopParentId();
2016-05-22 15:37:50 -07:00
var limit = 6;
2016-03-18 12:43:17 -07:00
var options = {
2016-03-18 12:43:17 -07:00
SortBy: "DatePlayed",
SortOrder: "Descending",
IncludeItemTypes: "Episode",
Filters: "IsResumable",
2016-05-22 15:37:50 -07:00
Limit: limit,
2016-03-18 12:43:17 -07:00
Recursive: true,
Fields: "PrimaryImageAspectRatio,SeriesInfo,UserData,SyncInfo",
ExcludeLocationTypes: "Virtual",
ParentId: parentId,
ImageTypeLimit: 1,
2016-05-08 20:13:38 -07:00
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
2016-05-19 10:27:39 -07:00
EnableTotalRecordCount: false
2016-03-18 12:43:17 -07:00
};
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()) {
2016-05-22 15:37:50 -07:00
tabContent.querySelector('#resumableItems').classList.add('hiddenScrollX');
2016-03-18 12:43:17 -07:00
} else {
2016-05-22 15:37:50 -07:00
tabContent.querySelector('#resumableItems').classList.remove('hiddenScrollX');
2016-03-18 12:43:17 -07:00
}
2016-05-22 15:37:50 -07:00
libraryBrowser.createCardMenus(tabContent.querySelector('#resumableItems'));
2016-03-18 12:43:17 -07:00
};
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) {
2016-05-15 09:30:32 -07:00
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
2016-03-18 12:43:17 -07:00
var depends = [];
switch (index) {
case 0:
break;
case 1:
2016-05-22 15:37:50 -07:00
depends.push('scripts/tvlatest');
2016-03-18 12:43:17 -07:00
break;
2016-05-22 11:09:09 -07:00
case 2:
2016-05-22 15:37:50 -07:00
depends.push('scripts/tvupcoming');
2016-03-18 12:43:17 -07:00
break;
2016-05-22 11:09:09 -07:00
case 3:
2016-05-22 15:37:50 -07:00
depends.push('scripts/tvshows');
2016-03-18 12:43:17 -07:00
break;
2016-05-22 11:09:09 -07:00
case 4:
2016-05-22 15:37:50 -07:00
depends.push('scripts/episodes');
2016-03-18 12:43:17 -07:00
break;
2016-05-22 11:09:09 -07:00
case 5:
2016-05-22 15:37:50 -07:00
depends.push('scripts/tvgenres');
break;
case 6:
2016-03-18 12:43:17 -07:00
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-05-15 09:30:32 -07:00
var mdlTabs = view.querySelector('.libraryViewNav');
2016-05-09 12:27:38 -07:00
2016-03-18 12:43:17 -07:00
function onPlaybackStop(e, state) {
if (state.NowPlayingItem && state.NowPlayingItem.MediaType == 'Video') {
2016-05-25 10:03:52 -07:00
renderedTabs = [];
2016-05-09 12:27:38 -07:00
mdlTabs.dispatchEvent(new CustomEvent("tabchange", {
2016-03-24 11:11:03 -07:00
detail: {
2016-05-09 12:27:38 -07:00
selectedTabIndex: libraryBrowser.selectedTab(mdlTabs)
2016-03-24 11:11:03 -07:00
}
}));
2016-03-18 12:43:17 -07:00
}
}
2016-03-16 22:04:32 -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;
}
2016-05-22 15:37:50 -07:00
if (enableScrollX()) {
view.querySelector('#resumableItems').classList.add('hiddenScrollX');
} else {
view.querySelector('#resumableItems').classList.remove('hiddenScrollX');
}
2016-03-16 22:04:32 -07:00
libraryBrowser.createCardMenus(view.querySelector('#resumableItems'));
2016-05-16 10:11:49 -07:00
libraryBrowser.configurePaperLibraryTabs(view, mdlTabs, view.querySelectorAll('.pageTabContent'), [0, 1, 2, 4, 5, 6]);
2015-09-28 20:35:50 -07:00
2016-05-09 12:27:38 -07:00
mdlTabs.addEventListener('tabchange', function (e) {
2016-03-24 11:11:03 -07:00
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);
});
view.addEventListener('viewdestroy', function (e) {
tabControllers.forEach(function (t) {
if (t.destroy) {
t.destroy();
}
});
});
2016-03-16 22:04:32 -07:00
};
});