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

319 lines
11 KiB
JavaScript
Raw Normal View History

2014-10-15 20:26:39 -07:00
(function ($, document) {
2013-02-20 18:33:05 -07:00
2015-06-07 14:21:30 -07:00
var defaultFirstSection = 'smalllibrarytiles';
2015-04-14 20:41:29 -07:00
2014-06-23 09:05:19 -07:00
function getDefaultSection(index) {
2015-12-14 08:43:03 -07:00
if (AppInfo.isNativeApp && browserInfo.safari) {
2015-09-24 22:15:29 -07:00
switch (index) {
case 0:
return defaultFirstSection;
case 1:
return 'resume';
case 2:
return 'nextup';
case 3:
return 'latestmovies';
case 4:
return 'latestepisodes';
case 5:
return 'latesttvrecordings';
default:
return '';
}
}
2014-06-23 09:05:19 -07:00
switch (index) {
case 0:
2015-04-14 20:41:29 -07:00
return defaultFirstSection;
2014-06-23 09:05:19 -07:00
case 1:
return 'resume';
case 2:
2014-07-11 19:31:08 -07:00
return 'latestmedia';
2014-06-23 09:05:19 -07:00
case 3:
2015-06-25 18:10:56 -07:00
return 'latesttvrecordings';
2014-06-23 09:05:19 -07:00
default:
return '';
}
}
2015-03-24 18:14:24 -07:00
function loadSection(page, user, displayPreferences, index) {
var userId = user.Id;
2014-05-21 12:33:46 -07:00
var section = displayPreferences.CustomPrefs['home' + index] || getDefaultSection(index);
2015-04-11 14:34:05 -07:00
if (section == 'folders') {
2015-04-14 20:41:29 -07:00
section = defaultFirstSection;
2015-04-11 14:34:05 -07:00
}
2015-03-14 18:58:06 -07:00
var showLibraryTileNames = displayPreferences.CustomPrefs.enableLibraryTileNames != '0';
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('.section' + index);
2014-06-19 21:50:30 -07:00
2014-05-21 12:33:46 -07:00
if (section == 'latestmedia') {
2015-04-12 09:46:29 -07:00
return Sections.loadRecentlyAdded(elem, user);
2014-05-21 12:33:46 -07:00
}
2015-09-24 22:15:29 -07:00
else if (section == 'latestmovies') {
return Sections.loadLatestMovies(elem, user);
}
else if (section == 'latestepisodes') {
return Sections.loadLatestEpisodes(elem, user);
}
2014-05-21 12:33:46 -07:00
else if (section == 'librarytiles') {
2015-04-12 09:46:29 -07:00
return Sections.loadLibraryTiles(elem, user, 'backdrop', index, false, showLibraryTileNames);
2014-06-07 12:46:24 -07:00
}
2014-06-24 14:45:21 -07:00
else if (section == 'smalllibrarytiles') {
2015-04-12 09:46:29 -07:00
return Sections.loadLibraryTiles(elem, user, 'homePageSmallBackdrop', index, false, showLibraryTileNames);
2014-07-11 19:31:08 -07:00
}
else if (section == 'smalllibrarytiles-automobile') {
2015-04-12 09:46:29 -07:00
return Sections.loadLibraryTiles(elem, user, 'homePageSmallBackdrop', index, true, showLibraryTileNames);
2015-03-13 21:50:23 -07:00
}
else if (section == 'librarytiles-automobile') {
2015-04-12 09:46:29 -07:00
return Sections.loadLibraryTiles(elem, user, 'backdrop', index, true, showLibraryTileNames);
2014-05-21 12:33:46 -07:00
}
2014-06-24 14:45:21 -07:00
else if (section == 'librarybuttons') {
2015-04-12 09:46:29 -07:00
return Sections.loadlibraryButtons(elem, userId, index);
2014-06-24 14:45:21 -07:00
}
2014-05-21 12:33:46 -07:00
else if (section == 'resume') {
2015-04-12 09:46:29 -07:00
return Sections.loadResume(elem, userId);
2014-06-23 09:05:19 -07:00
}
2015-09-24 22:15:29 -07:00
else if (section == 'nextup') {
return Sections.loadNextUp(elem, userId);
}
2014-06-23 09:05:19 -07:00
else if (section == 'latesttvrecordings') {
2015-04-12 09:46:29 -07:00
return Sections.loadLatestLiveTvRecordings(elem, userId);
2014-05-21 12:33:46 -07:00
}
2015-04-11 14:34:05 -07:00
else if (section == 'latestchannelmedia') {
2015-04-12 09:46:29 -07:00
return Sections.loadLatestChannelMedia(elem, userId);
2014-05-21 20:35:18 -07:00
} else {
2015-07-06 19:25:23 -07:00
elem.innerHTML = '';
2015-04-12 09:46:29 -07:00
2015-12-30 10:02:11 -07:00
return new Promise(function (resolve, reject) {
resolve();
});
2014-05-21 12:33:46 -07:00
}
}
2015-03-24 18:14:24 -07:00
function loadSections(page, user, displayPreferences) {
2014-05-21 12:33:46 -07:00
var i, length;
2015-09-24 22:15:29 -07:00
var sectionCount = 6;
2014-05-21 12:33:46 -07:00
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('.sections');
2015-06-28 07:45:21 -07:00
if (!elem.innerHTML.length) {
2014-05-21 20:35:18 -07:00
var html = '';
for (i = 0, length = sectionCount; i < length; i++) {
2014-05-21 12:33:46 -07:00
2014-05-21 20:35:18 -07:00
html += '<div class="homePageSection section' + i + '"></div>';
}
2014-05-21 12:33:46 -07:00
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
2014-05-21 20:35:18 -07:00
}
2014-05-21 12:33:46 -07:00
2015-04-12 09:46:29 -07:00
var promises = [];
2014-05-21 12:33:46 -07:00
for (i = 0, length = sectionCount; i < length; i++) {
2015-04-12 09:46:29 -07:00
promises.push(loadSection(page, user, displayPreferences, i));
2014-05-21 12:33:46 -07:00
}
2015-04-12 09:46:29 -07:00
2015-12-14 08:43:03 -07:00
return Promise.all(promises);
2014-05-21 12:33:46 -07:00
}
2015-04-20 11:04:02 -07:00
var homePageDismissValue = '14';
2014-09-25 20:47:46 -07:00
var homePageTourKey = 'homePageTour';
2014-06-07 12:46:24 -07:00
2014-05-30 14:06:57 -07:00
function dismissWelcome(page, userId) {
2015-12-14 08:43:03 -07:00
getDisplayPreferences('home', userId).then(function (result) {
2014-05-30 14:06:57 -07:00
2014-09-25 20:47:46 -07:00
result.CustomPrefs[homePageTourKey] = homePageDismissValue;
2015-07-03 10:55:29 -07:00
ApiClient.updateDisplayPreferences('home', result, userId, AppSettings.displayPreferencesKey());
2014-09-25 20:47:46 -07:00
});
}
2014-06-07 12:46:24 -07:00
2015-01-11 11:36:26 -07:00
function showWelcomeIfNeeded(page, displayPreferences) {
if (displayPreferences.CustomPrefs[homePageTourKey] == homePageDismissValue) {
$('.welcomeMessage', page).hide();
} else {
2015-06-29 11:45:42 -07:00
Dashboard.hideLoadingMsg();
2015-01-11 11:36:26 -07:00
var elem = $('.welcomeMessage', page).show();
if (displayPreferences.CustomPrefs[homePageTourKey]) {
$('.tourHeader', elem).html(Globalize.translate('HeaderWelcomeBack'));
$('.tourButtonText', elem).html(Globalize.translate('ButtonTakeTheTourToSeeWhatsNew'));
} else {
2015-03-21 11:12:12 -07:00
$('.tourHeader', elem).html(Globalize.translate('HeaderWelcomeToProjectWebClient'));
2015-01-11 11:36:26 -07:00
$('.tourButtonText', elem).html(Globalize.translate('ButtonTakeTheTour'));
}
}
2014-10-04 11:05:24 -07:00
}
2014-09-25 20:47:46 -07:00
function takeTour(page, userId) {
2015-12-14 08:43:03 -07:00
require(['swipebox'], function () {
2015-05-08 20:48:43 -07:00
$.swipebox([
{ href: 'css/images/tour/web/tourcontent.jpg', title: Globalize.translate('WebClientTourContent') },
{ href: 'css/images/tour/web/tourmovies.jpg', title: Globalize.translate('WebClientTourMovies') },
{ href: 'css/images/tour/web/tourmouseover.jpg', title: Globalize.translate('WebClientTourMouseOver') },
{ href: 'css/images/tour/web/tourtaphold.jpg', title: Globalize.translate('WebClientTourTapHold') },
{ href: 'css/images/tour/web/tourmysync.png', title: Globalize.translate('WebClientTourMySync') },
{ href: 'css/images/tour/web/toureditor.png', title: Globalize.translate('WebClientTourMetadataManager') },
{ href: 'css/images/tour/web/tourplaylist.png', title: Globalize.translate('WebClientTourPlaylists') },
{ href: 'css/images/tour/web/tourcollections.jpg', title: Globalize.translate('WebClientTourCollections') },
{ href: 'css/images/tour/web/tourusersettings1.png', title: Globalize.translate('WebClientTourUserPreferences1') },
{ href: 'css/images/tour/web/tourusersettings2.png', title: Globalize.translate('WebClientTourUserPreferences2') },
{ href: 'css/images/tour/web/tourusersettings3.png', title: Globalize.translate('WebClientTourUserPreferences3') },
{ href: 'css/images/tour/web/tourusersettings4.png', title: Globalize.translate('WebClientTourUserPreferences4') },
{ href: 'css/images/tour/web/tourmobile1.jpg', title: Globalize.translate('WebClientTourMobile1') },
{ href: 'css/images/tour/web/tourmobile2.png', title: Globalize.translate('WebClientTourMobile2') },
{ href: 'css/images/tour/enjoy.jpg', title: Globalize.translate('MessageEnjoyYourStay') }
], {
afterClose: function () {
dismissWelcome(page, userId);
$('.welcomeMessage', page).hide();
},
hideBarsDelay: 30000
});
2014-05-30 14:06:57 -07:00
});
}
2015-08-18 08:35:51 -07:00
function loadHomeTab(page, tabContent) {
2014-05-30 14:06:57 -07:00
2015-07-01 08:47:41 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
2015-06-29 19:52:23 -07:00
if (window.ApiClient) {
var userId = Dashboard.getCurrentUserId();
2014-05-21 12:33:46 -07:00
2015-06-29 19:52:23 -07:00
Dashboard.showLoadingMsg();
2015-06-29 11:45:42 -07:00
2015-12-14 08:43:03 -07:00
getDisplayPreferences('home', userId).then(function (result) {
2014-05-21 12:33:46 -07:00
2015-12-14 08:43:03 -07:00
Dashboard.getCurrentUser().then(function (user) {
2015-03-24 18:14:24 -07:00
2015-12-14 08:43:03 -07:00
loadSections(tabContent, user, result).then(function () {
2015-06-07 14:21:30 -07:00
2015-06-29 19:52:23 -07:00
if (!AppInfo.isNativeApp) {
showWelcomeIfNeeded(page, result);
}
Dashboard.hideLoadingMsg();
2015-06-29 22:45:20 -07:00
2015-07-01 08:47:41 -07:00
LibraryBrowser.setLastRefreshed(tabContent);
2015-06-29 19:52:23 -07:00
});
2015-04-12 09:46:29 -07:00
2015-06-29 19:52:23 -07:00
});
2015-05-19 12:15:40 -07:00
});
2015-06-29 19:52:23 -07:00
}
2015-05-19 12:15:40 -07:00
}
2015-07-01 08:47:41 -07:00
}
function loadTab(page, index) {
2015-08-18 08:35:51 -07:00
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
var depends = [];
var scope = 'HomePage';
var method = '';
2015-07-01 08:47:41 -07:00
switch (index) {
case 0:
2015-08-18 08:35:51 -07:00
depends.push('scripts/sections');
method = 'renderHomeTab';
break;
case 1:
depends.push('scripts/homenextup');
method = 'renderNextUp';
break;
case 2:
depends.push('scripts/favorites');
method = 'renderFavorites';
break;
case 3:
depends.push('scripts/homeupcoming');
method = 'renderUpcoming';
2015-07-01 08:47:41 -07:00
break;
default:
break;
}
2015-08-18 08:35:51 -07:00
require(depends, function () {
window[scope][method](page, tabContent);
});
2015-07-01 08:47:41 -07:00
}
2015-09-06 12:09:36 -07:00
pageIdOn('pageinit', "indexPage", function () {
2015-07-01 08:47:41 -07:00
var page = this;
var tabs = page.querySelector('paper-tabs');
2015-07-14 13:29:51 -07:00
var pages = page.querySelector('neon-animated-pages');
2015-09-01 08:31:50 -07:00
LibraryBrowser.configurePaperLibraryTabs(page, tabs, pages, 'index.html');
2015-07-01 08:47:41 -07:00
2015-12-14 08:43:03 -07:00
pages.addEventListener('tabchange', function (e) {
loadTab(page, parseInt(e.target.selected));
2015-07-01 08:47:41 -07:00
});
2015-12-14 08:43:03 -07:00
page.querySelector('.btnTakeTour').addEventListener('click', function () {
2015-07-01 22:08:05 -07:00
takeTour(page, Dashboard.getCurrentUserId());
});
2015-09-24 22:15:29 -07:00
if (AppInfo.enableHomeTabs) {
page.classList.remove('noSecondaryNavPage');
page.querySelector('.libraryViewNav').classList.remove('hide');
} else {
page.classList.add('noSecondaryNavPage');
page.querySelector('.libraryViewNav').classList.add('hide');
}
2015-09-19 19:06:56 -07:00
});
2015-09-24 10:08:10 -07:00
pageIdOn('pageshow', "indexPage", function () {
2015-09-19 19:06:56 -07:00
var page = this;
2015-12-23 10:46:01 -07:00
Events.on(MediaController, 'playbackstop', onPlaybackStop);
2015-09-19 19:06:56 -07:00
});
pageIdOn('pagebeforehide', "indexPage", function () {
var page = this;
2015-12-23 10:46:01 -07:00
Events.off(MediaController, 'playbackstop', onPlaybackStop);
2013-07-23 05:29:28 -07:00
});
2015-09-20 11:17:57 -07:00
function onPlaybackStop(e, state) {
if (state.NowPlayingItem && state.NowPlayingItem.MediaType == 'Video') {
var page = $($.mobile.activePage)[0];
var pages = page.querySelector('neon-animated-pages');
2015-12-14 08:43:03 -07:00
pages.dispatchEvent(new CustomEvent("tabchange", {}));
2015-09-20 11:17:57 -07:00
}
}
2015-05-12 21:55:19 -07:00
function getDisplayPreferences(key, userId) {
2015-12-14 08:43:03 -07:00
return ApiClient.getDisplayPreferences(key, userId, AppSettings.displayPreferencesKey());
2015-05-12 21:55:19 -07:00
}
2015-08-18 08:35:51 -07:00
window.HomePage = {
renderHomeTab: loadHomeTab
};
2014-10-25 11:32:58 -07:00
})(jQuery, document);