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-01 19:54:33 -07:00
|
|
|
|
function renderHeader(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-01 19:54:33 -07:00
|
|
|
|
html += '<button type="button" data-icon="bars" data-iconpos="notext" data-inline="true" title="Menu" class="libraryMenuButton" onclick="LibraryMenu.showLibraryMenu();">Menu</button>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
html += '<a class="desktopHomeLink" href="index.html"><img src="css/images/mblogoicon.png" /></a>';
|
|
|
|
|
|
2014-04-30 08:07:02 -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
|
|
|
|
|
|
|
|
|
if (user.Configuration.IsAdministrator) {
|
|
|
|
|
html += '<a class="editorMenuLink" href="edititemmetadata.html" data-role="button" data-icon="edit" data-inline="true" data-iconpos="notext" title="Metadata Manager">Metadata Manager</a>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '<div class="viewMenuSecondary">';
|
|
|
|
|
|
2014-03-31 21:16:35 -07:00
|
|
|
|
html += '<button id="btnCast" class="btnCast btnDefaultCast" type="button" data-role="none"></button>';
|
2014-02-23 10:29:02 -07:00
|
|
|
|
|
2013-12-27 14:10:06 -07:00
|
|
|
|
html += '<a class="viewMenuLink btnCurrentUser" href="#" onclick="Dashboard.showUserFlyout(this);">';
|
|
|
|
|
|
|
|
|
|
if (user.PrimaryImageTag) {
|
|
|
|
|
|
|
|
|
|
var url = ApiClient.getUserImageUrl(user.Id, {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
height: 24,
|
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 += '<button onclick="Search.showSearchPanel($.mobile.activePage);" type="button" data-icon="search" data-inline="true" data-iconpos="notext">Search</button>';
|
|
|
|
|
|
|
|
|
|
if (user.Configuration.IsAdministrator) {
|
|
|
|
|
html += '<a href="dashboard.html" data-role="button" data-icon="gear" data-inline="true" data-iconpos="notext">Dashboard</a>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
$(document.body).prepend(html);
|
2014-02-23 13:35:58 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
$('.viewMenuBar').trigger('create');
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
$(document).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-02 07:49:28 -07:00
|
|
|
|
if (item.Type == 'ManualCollectionsFolder' || item.CollectionType == 'boxsets') {
|
2014-05-01 19:54:33 -07:00
|
|
|
|
return 'collections.html?topParentId=' + item.Id;
|
|
|
|
|
}
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-02 07:49:28 -07:00
|
|
|
|
if (item.CollectionType == 'trailers' || item.Type == 'TrailerCollectionFolder') {
|
2014-05-01 19:54:33 -07:00
|
|
|
|
return 'movietrailers.html?topParentId=' + item.Id;
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
if (item.CollectionType == 'movies') {
|
|
|
|
|
return 'movieslatest.html?topParentId=' + item.Id;
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
if (item.CollectionType == 'tvshows') {
|
|
|
|
|
return 'tvrecommended.html?topParentId=' + item.Id;
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
if (item.CollectionType == 'music') {
|
|
|
|
|
return 'musicrecommended.html?topParentId=' + item.Id;
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
if (item.CollectionType == 'games') {
|
|
|
|
|
return 'gamesrecommended.html?topParentId=' + item.Id;
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
return 'itemlist.html?topParentId=' + item.Id + '&parentid=' + item.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function insertViews(user, counts, items, liveTvInfo) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
html += items.map(function (i) {
|
|
|
|
|
|
|
|
|
|
return '<a data-itemid="' + i.Id + '" class="lnkMediaFolder viewMenuLink viewMenuTextLink desktopViewMenuLink" href="' + getItemHref(i) + '"><span class="viewName">' + i.Name + '</span></a>';
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
2014-03-18 10:05:57 -07:00
|
|
|
|
if (counts.ChannelCount) {
|
2014-05-01 19:54:33 -07:00
|
|
|
|
html += '<a class="viewMenuLink viewMenuTextLink desktopViewMenuLink lnkMediaFolder" href="channels.html"><span class="viewName">Channels</span></a>';
|
2014-03-18 10:05:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
if (liveTvInfo.EnabledUsers.indexOf(user.Id) != -1) {
|
|
|
|
|
html += '<a class="viewMenuLink viewMenuTextLink desktopViewMenuLink lnkMediaFolder" data-itemid="livetv" href="livetvsuggested.html"><span class="viewName">Live TV</span></a>';
|
|
|
|
|
}
|
2014-03-13 02:00:47 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
$('.viewMenuRemoteControlButton').before(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-01 19:54:33 -07:00
|
|
|
|
$.when(itemCountsPromise, itemsPromise, liveTvInfoPromise).done(function (response1, response2, response3) {
|
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];
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
|
|
|
|
var panel = getLibraryMenu(page, counts, items, liveTvInfo);
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
$(panel).panel('toggle');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
function getLibraryMenu(page, counts, items, liveTvInfo) {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
var panel = $('#libraryPanel', page);
|
|
|
|
|
|
|
|
|
|
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-03-13 02:00:47 -07:00
|
|
|
|
html += '<ul data-role="listview">';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
html += items.map(function (i) {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
return '<li><a data-itemid="' + i.Id + '" class="libraryPanelLink lnkMediaFolder" href="' + getItemHref(i) + '">' + i.Name + '</a></li>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
}).join('');
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-03-18 10:05:57 -07:00
|
|
|
|
if (counts.ChannelCount) {
|
2014-05-01 19:54:33 -07:00
|
|
|
|
html += '<li><a class="libraryPanelLink lnkMediaFolder" href="channels.html">Channels</a></li>';
|
2014-03-18 10:05:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
if (liveTvInfo.EnabledUsers.indexOf(Dashboard.getCurrentUserId()) != -1) {
|
|
|
|
|
html += '<li><a class="libraryPanelLink lnkMediaFolder" data-itemid="livetv" href="livetvsuggested.html">Live TV</a></li>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 02:00:47 -07:00
|
|
|
|
html += '</ul>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
$(page).append(html);
|
|
|
|
|
|
|
|
|
|
panel = $('#libraryPanel', page).panel({}).trigger('create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-01 19:54:33 -07:00
|
|
|
|
function updateLibraryNavLinks(page) {
|
|
|
|
|
|
|
|
|
|
page = $(page);
|
|
|
|
|
|
|
|
|
|
var isLiveTvPage = page.hasClass('liveTvPage');
|
|
|
|
|
|
|
|
|
|
var id = isLiveTvPage || page.hasClass('noLibraryMenuSelectionPage') ?
|
|
|
|
|
'' :
|
|
|
|
|
getTopParentId() || '';
|
|
|
|
|
|
|
|
|
|
sessionStorage.setItem('topParentId', id);
|
|
|
|
|
|
|
|
|
|
$('.lnkMediaFolder').each(function () {
|
|
|
|
|
|
|
|
|
|
var itemId = this.getAttribute('data-itemid');
|
|
|
|
|
|
|
|
|
|
if (isLiveTvPage && itemId == 'livetv') {
|
|
|
|
|
$(this).addClass('selectedMediaFolder');
|
|
|
|
|
}
|
|
|
|
|
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-01-23 14:09:00 -07:00
|
|
|
|
|
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-01 19:54:33 -07:00
|
|
|
|
}).on('pagebeforeshow', ".page", function () {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
if ($(page).hasClass('libraryPage')) {
|
|
|
|
|
|
|
|
|
|
if (!$('.viewMenuBar').length) {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
renderHeader(user);
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
ensurePromises();
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
$.when(itemCountsPromise, itemsPromise, liveTvInfoPromise).done(function (response1, response2, response3) {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
var counts = response1[0];
|
|
|
|
|
var items = response2[0].Items;
|
|
|
|
|
var liveTvInfo = response3[0];
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
insertViews(user, counts, items, liveTvInfo);
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
updateLibraryNavLinks(page);
|
2013-12-27 14:10:06 -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
|
|
|
|
} else {
|
2014-03-29 09:58:49 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
$('.viewMenuBar').show();
|
|
|
|
|
updateLibraryNavLinks(page);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$('.viewMenuBar').hide();
|
|
|
|
|
}
|
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);
|