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

290 lines
9.2 KiB
JavaScript
Raw Normal View History

2013-12-27 14:10:06 -07:00
(function (window, document, $) {
var itemCountsPromise;
2014-01-14 13:03:35 -07:00
var liveTvInfoPromise;
2014-05-01 19:54:33 -07:00
var itemsPromise;
2013-12-27 14:10:06 -07:00
function ensurePromises() {
2014-05-01 19:54:33 -07:00
itemsPromise = itemsPromise || ApiClient.getItems(Dashboard.getCurrentUserId(), {
SortBy: "SortName"
});
2013-12-27 14:10:06 -07:00
itemCountsPromise = itemCountsPromise || ApiClient.getItemCounts(Dashboard.getCurrentUserId());
2014-01-14 13:03:35 -07:00
liveTvInfoPromise = liveTvInfoPromise || ApiClient.getLiveTvInfo();
2013-12-27 14:10:06 -07:00
}
2014-05-03 16:38:23 -07:00
function renderHeader(page, user) {
2013-12-27 14:10:06 -07:00
2013-12-28 00:09:05 -07:00
var html = '<div class="viewMenuBar ui-bar-b">';
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
html += '<button type="button" data-role="none" title="Menu" onclick="LibraryMenu.showLibraryMenu();" class="headerButton libraryMenuButton headerButtonLeft"><img src="css/images/menu.png" /></button>';
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
html += '<a class="desktopHomeLink headerButton headerButtonLeft" href="index.html"><span>MEDIA</span><span class="mediaBrowserAccent">BROWSER</span></a>';
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
//html += '<a class="viewMenuRemoteControlButton" href="nowplaying.html" data-role="button" data-icon="play" data-inline="true" data-iconpos="notext" title="Now Playing">Remote Control</a>';
2013-12-27 14:10:06 -07:00
html += '<div class="viewMenuSecondary">';
2014-05-10 22:11:53 -07:00
html += '<a href="nowplaying.html" class="headerButton headerButtonRight headerRemoteButton"><img src="css/images/remote.png" /></a>';
2014-02-23 10:29:02 -07:00
2014-05-10 22:11:53 -07:00
html += '<button id="btnCast" class="btnCast btnDefaultCast headerButton headerButtonRight" type="button" data-role="none"><div class="btnCastImage"></div></button>';
html += '<button onclick="Search.showSearchPanel($.mobile.activePage);" type="button" data-role="none" class="headerButton headerButtonRight headerSearchButton"><img src="css/images/headersearch.png" /></button>';
if (user.Configuration.IsAdministrator) {
html += '<a href="dashboard.html" class="headerButton headerButtonRight headerSettingsButton"><img src="css/images/items/folders/settings.png" /></a>';
}
html += '<a class="headerButton headerButtonRight" href="#" onclick="Dashboard.showUserFlyout(this);">';
2013-12-27 14:10:06 -07:00
if (user.PrimaryImageTag) {
var url = ApiClient.getUserImageUrl(user.Id, {
2014-05-10 22:11:53 -07:00
height: 18,
2013-12-27 14:10:06 -07:00
tag: user.PrimaryImageTag,
type: "Primary"
});
html += '<img src="' + url + '" />';
} else {
html += '<img src="css/images/currentuserdefaultwhite.png" />';
}
html += '</a>';
html += '</div>';
html += '</div>';
2014-05-03 16:38:23 -07:00
var $page = $(page);
$page.prepend(html);
2014-02-23 13:35:58 -07:00
2014-05-03 16:38:23 -07:00
$page.trigger('headercreated');
2013-12-27 14:10:06 -07:00
}
2014-05-01 19:54:33 -07:00
function getItemHref(item) {
2013-12-27 14:10:06 -07:00
2014-05-06 19:28:19 -07:00
return LibraryBrowser.getHref(item);
2014-05-01 19:54:33 -07:00
}
2014-05-10 22:11:53 -07:00
2014-05-10 10:28:03 -07:00
function getViewsHtml(user, counts, items, liveTvInfo) {
2014-05-10 22:11:53 -07:00
2014-05-01 19:54:33 -07:00
var html = '';
html += items.map(function (i) {
2014-05-03 16:38:23 -07:00
var viewMenuCssClass = (i.CollectionType || 'general') + 'ViewMenu';
return '<a data-itemid="' + i.Id + '" class="lnkMediaFolder viewMenuLink viewMenuTextLink ' + viewMenuCssClass + '" href="' + getItemHref(i) + '">' + i.Name + '</a>';
2014-05-01 19:54:33 -07:00
}).join('');
2014-05-03 16:38:23 -07:00
var showChannels = counts.ChannelCount;
2014-05-10 10:28:03 -07:00
var showLiveTv = liveTvInfo.EnabledUsers.indexOf(user.Id) != -1;
2014-05-03 16:38:23 -07:00
if (showChannels || showLiveTv) {
2014-05-09 12:43:06 -07:00
html += '<div class="libraryMenuDivider"></div>';
2014-03-18 10:05:57 -07:00
}
2014-05-03 16:38:23 -07:00
if (showChannels) {
html += '<a class="viewMenuLink viewMenuTextLink lnkMediaFolder channelsViewMenu" data-itemid="channels" href="channels.html">Channels</a>';
2014-05-01 19:54:33 -07:00
}
2014-03-13 02:00:47 -07:00
2014-05-03 16:38:23 -07:00
if (showLiveTv) {
html += '<a class="viewMenuLink viewMenuTextLink lnkMediaFolder tvshowsViewMenu" data-itemid="livetv" href="livetvsuggested.html">Live TV</a>';
}
2014-05-10 10:28:03 -07:00
if (user.Configuration.IsAdministrator) {
html += '<div class="libraryMenuDivider"></div>';
2014-05-12 11:04:25 -07:00
html += '<a class="viewMenuLink viewMenuTextLink lnkMediaFolder dashboardViewMenu" data-itemid="dashboard" href="dashboard.html">Dashboard</a>';
2014-05-10 22:11:53 -07:00
html += '<a class="viewMenuLink viewMenuTextLink lnkMediaFolder editorViewMenu" data-itemid="editor" href="edititemmetadata.html">Metadata Manager</a>';
2014-05-12 11:04:25 -07:00
html += '<a class="viewMenuLink viewMenuTextLink lnkMediaFolder reportsViewMenu" data-itemid="reports" href="reports.html">Reports</a>';
2014-05-10 10:28:03 -07:00
}
2014-05-09 12:43:06 -07:00
return html;
2013-12-27 14:10:06 -07:00
}
2014-05-01 19:54:33 -07:00
function showLibraryMenu() {
2013-12-27 14:10:06 -07:00
ensurePromises();
2014-05-10 10:28:03 -07:00
var userPromise = Dashboard.getCurrentUser();
$.when(itemCountsPromise, itemsPromise, liveTvInfoPromise, userPromise).done(function (response1, response2, response3, response4) {
2013-12-27 14:10:06 -07:00
var counts = response1[0];
2014-05-01 19:54:33 -07:00
var items = response2[0].Items;
var liveTvInfo = response3[0];
2014-05-10 10:28:03 -07:00
var user = response4[0];
2013-12-27 14:10:06 -07:00
2014-05-01 19:54:33 -07:00
var page = $.mobile.activePage;
2014-05-10 10:28:03 -07:00
var panel = getLibraryMenu(page, user, counts, items, liveTvInfo);
2013-12-27 14:10:06 -07:00
$(panel).panel('toggle');
});
}
2014-05-10 10:28:03 -07:00
function getLibraryMenu(page, user, counts, items, liveTvInfo) {
2013-12-27 14:10:06 -07:00
2014-05-12 11:04:25 -07:00
var panel = $('#libraryPanel');
2013-12-27 14:10:06 -07:00
if (!panel.length) {
var html = '';
html += '<div data-role="panel" id="libraryPanel" class="libraryPanel" data-position="left" data-display="overlay" data-position-fixed="true" data-theme="b">';
html += '<p class="libraryPanelHeader"><a href="index.html" class="imageLink"><img src="css/images/mblogoicon.png" /><span>MEDIA</span><span class="mediaBrowserAccent">BROWSER</span></a></p>';
2014-05-09 12:43:06 -07:00
html += '<div style="margin: 0 -1em;">';
2014-05-10 10:28:03 -07:00
html += getViewsHtml(user, counts, items, liveTvInfo);
2014-05-09 12:43:06 -07:00
html += '</div>';
2013-12-27 14:10:06 -07:00
html += '</div>';
2014-05-12 11:04:25 -07:00
$(document.body).append(html);
2013-12-27 14:10:06 -07:00
2014-05-12 11:04:25 -07:00
panel = $('#libraryPanel').panel({}).trigger('create');
2013-12-27 14:10:06 -07:00
}
2014-05-09 12:43:06 -07:00
updateLibraryNavLinks(page);
2014-05-10 22:11:53 -07:00
2013-12-27 14:10:06 -07:00
return panel;
}
2014-05-01 19:54:33 -07:00
function getTopParentId() {
return getParameterByName('topParentId') || sessionStorage.getItem('topParentId') || null;
}
2014-03-13 02:00:47 -07:00
window.LibraryMenu = {
2014-05-01 19:54:33 -07:00
showLibraryMenu: showLibraryMenu,
getTopParentId: getTopParentId
2014-03-13 02:00:47 -07:00
};
2014-05-01 19:54:33 -07:00
2014-03-29 11:20:42 -07:00
function updateCastIcon() {
2014-05-01 19:54:33 -07:00
2014-03-29 11:20:42 -07:00
var info = MediaController.getPlayerInfo();
if (info.isLocalPlayer) {
$('.btnCast').addClass('btnDefaultCast').removeClass('btnActiveCast');
} else {
$('.btnCast').removeClass('btnDefaultCast').addClass('btnActiveCast');
}
}
2013-12-27 14:10:06 -07:00
2014-05-12 11:04:25 -07:00
function updateLibraryNavLinks(page) {
2014-05-01 19:54:33 -07:00
page = $(page);
var isLiveTvPage = page.hasClass('liveTvPage');
2014-05-02 21:20:04 -07:00
var isChannelsPage = page.hasClass('channelsPage');
2014-05-12 11:04:25 -07:00
var isEditorPage = page.hasClass('metadataEditorPage');
var isReportsPage = page.hasClass('reportsPage');
2014-05-03 16:38:23 -07:00
2014-05-12 11:04:25 -07:00
var id = isLiveTvPage || isChannelsPage || isEditorPage || isReportsPage || page.hasClass('allLibraryPage') ?
2014-05-01 19:54:33 -07:00
'' :
getTopParentId() || '';
sessionStorage.setItem('topParentId', id);
2014-05-09 12:43:06 -07:00
$('.lnkMediaFolder').each(function () {
2014-05-01 19:54:33 -07:00
var itemId = this.getAttribute('data-itemid');
2014-05-02 21:20:04 -07:00
if (isChannelsPage && itemId == 'channels') {
$(this).addClass('selectedMediaFolder');
}
else if (isLiveTvPage && itemId == 'livetv') {
2014-05-01 19:54:33 -07:00
$(this).addClass('selectedMediaFolder');
}
2014-05-12 11:04:25 -07:00
else if (isEditorPage && itemId == 'editor') {
$(this).addClass('selectedMediaFolder');
}
else if (isReportsPage && itemId == 'reports') {
$(this).addClass('selectedMediaFolder');
}
2014-05-01 19:54:33 -07:00
else if (id && itemId == id) {
$(this).addClass('selectedMediaFolder');
}
else {
$(this).removeClass('selectedMediaFolder');
}
});
$('.scopedLibraryViewNav a', page).each(function () {
var src = this.href;
if (src.indexOf('#') != -1) {
return;
}
src = replaceQueryString(src, 'topParentId', id);
this.href = src;
});
}
2014-03-13 02:00:47 -07:00
$(document).on('pageinit', ".libraryPage", function () {
2013-12-27 14:10:06 -07:00
2014-03-13 02:00:47 -07:00
var page = this;
2013-12-28 09:58:13 -07:00
2014-03-13 02:00:47 -07:00
$('.libraryViewNav', page).wrapInner('<div class="libraryViewNavInner"></div>');
2014-03-13 02:00:47 -07:00
$('.libraryViewNav a', page).each(function () {
2013-12-27 14:10:06 -07:00
2014-03-13 02:00:47 -07:00
this.innerHTML = '<span class="libraryViewNavLinkContent">' + this.innerHTML + '</span>';
2013-12-27 14:10:06 -07:00
2014-03-13 02:00:47 -07:00
});
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
}).on('pagebeforeshow', ".libraryPage", function () {
2013-12-27 14:10:06 -07:00
var page = this;
2014-05-10 22:11:53 -07:00
updateLibraryNavLinks(page);
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
if (!$('.viewMenuBar', page).length) {
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
Dashboard.getCurrentUser().done(function (user) {
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
renderHeader(page, user);
2014-05-01 19:54:33 -07:00
2014-05-10 22:11:53 -07:00
updateCastIcon();
updateLibraryNavLinks(page);
});
2014-05-01 19:54:33 -07:00
}
2014-03-29 11:20:42 -07:00
2014-03-14 21:14:07 -07:00
}).on('pageshow', ".libraryPage", function () {
var page = this;
var elem = $('.libraryViewNavInner .ui-btn-active:visible', page);
if (elem.length) {
elem[0].scrollIntoView();
2014-03-16 09:15:10 -07:00
// Scroll back up so in case vertical scroll was messed with
$(document).scrollTop(0);
2014-03-14 21:14:07 -07:00
}
2014-05-01 19:54:33 -07:00
2013-12-27 14:10:06 -07:00
});
2014-05-01 19:54:33 -07:00
$(function () {
2014-03-29 09:58:49 -07:00
$(MediaController).on('playerchange', function () {
2014-03-29 11:20:42 -07:00
updateCastIcon();
2014-03-29 09:58:49 -07:00
});
});
2013-12-27 14:10:06 -07:00
})(window, document, jQuery);