2013-12-27 14:10:06 -07:00
|
|
|
|
(function (window, document, $) {
|
|
|
|
|
|
|
|
|
|
var itemCountsPromise;
|
2014-01-14 13:03:35 -07:00
|
|
|
|
var liveTvInfoPromise;
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
function ensurePromises() {
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderHeader(page, user) {
|
|
|
|
|
|
2013-12-28 00:09:05 -07:00
|
|
|
|
var html = '<div class="viewMenuBar ui-bar-b">';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
html += '<button type="button" data-icon="bars" data-iconpos="notext" data-inline="true" title="Menu" class="libraryMenuButton" onclick="LibraryMenu.showLibraryMenu($(this).parents(\'.page\'));">Menu</button>';
|
|
|
|
|
|
|
|
|
|
html += '<a class="desktopHomeLink" href="index.html"><img src="css/images/mblogoicon.png" /></a>';
|
|
|
|
|
|
2014-01-16 20:13:12 -07:00
|
|
|
|
html += '<button class="viewMenuRemoteControlButton" onclick="RemoteControl.showMenu();" type="button" data-icon="wireless" data-inline="true" data-iconpos="notext" title="Remote Control">Remote Control</button>';
|
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-02-23 10:29:02 -07:00
|
|
|
|
html += '<button class="btnCast btnDefaultCast" type="button" data-role="none" style="display:none;"></button>';
|
|
|
|
|
|
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, {
|
|
|
|
|
height: 40,
|
|
|
|
|
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-02-23 13:35:58 -07:00
|
|
|
|
var $page = $(page);
|
|
|
|
|
|
|
|
|
|
$page.prepend(html);
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
$('.viewMenuBar', page).trigger('create');
|
2014-02-23 13:35:58 -07:00
|
|
|
|
|
|
|
|
|
$page.trigger('headercreated');
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-14 13:03:35 -07:00
|
|
|
|
function insertViews(page, user, counts, liveTvInfo) {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
var selectedCssClass = ' selectedViewLink';
|
|
|
|
|
var selectedHtml = "<span class='selectedViewIndicator'>▶</span>";
|
|
|
|
|
|
|
|
|
|
var view = page.getAttribute('data-view') || getParameterByName('context');
|
|
|
|
|
|
|
|
|
|
if (counts.MovieCount) {
|
|
|
|
|
|
2014-03-13 02:00:47 -07:00
|
|
|
|
html += '<a class="viewMenuLink viewMenuTextLink desktopViewMenuLink' + (view == 'movies' ? selectedCssClass : '') + '" href="movieslatest.html">' + (view == 'movies' ? selectedHtml : '') + '<span class="viewName">Movies</span></a>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (counts.SeriesCount) {
|
|
|
|
|
html += '<a class="viewMenuLink viewMenuTextLink desktopViewMenuLink' + (view == 'tv' ? selectedCssClass : '') + '" href="tvrecommended.html">' + (view == 'tv' ? selectedHtml : '') + '<span class="viewName">TV</span></a>';
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 14:09:00 -07:00
|
|
|
|
if (liveTvInfo.EnabledUsers.indexOf(user.Id) != -1) {
|
2014-01-06 09:48:43 -07:00
|
|
|
|
html += '<a class="viewMenuLink viewMenuTextLink desktopViewMenuLink' + (view == 'livetv' ? selectedCssClass : '') + '" href="livetvsuggested.html">' + (view == 'livetv' ? selectedHtml : '') + '<span class="viewName">Live TV</span></a>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (counts.SongCount || counts.MusicVideoCount) {
|
|
|
|
|
html += '<a class="viewMenuLink viewMenuTextLink desktopViewMenuLink' + (view == 'music' ? selectedCssClass : '') + '" href="musicrecommended.html">' + (view == 'music' ? selectedHtml : '') + '<span class="viewName">Music</span></a>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (counts.GameCount) {
|
|
|
|
|
html += '<a class="viewMenuLink viewMenuTextLink desktopViewMenuLink' + (view == 'games' ? selectedCssClass : '') + '" href="gamesrecommended.html">' + (view == 'games' ? selectedHtml : '') + '<span class="viewName">Games</span></a>';
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 02:00:47 -07:00
|
|
|
|
if (counts.BoxSetCount) {
|
|
|
|
|
html += '<a class="viewMenuLink viewMenuTextLink desktopViewMenuLink' + (view == 'boxsets' ? selectedCssClass : '') + '" href="collections.html">' + (view == 'boxsets' ? selectedHtml : '') + '<span class="viewName">Collections</span></a>';
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 14:10:06 -07:00
|
|
|
|
$('.viewMenuRemoteControlButton', page).before(html);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showLibraryMenu(page) {
|
|
|
|
|
|
|
|
|
|
ensurePromises();
|
|
|
|
|
|
2014-01-14 13:03:35 -07:00
|
|
|
|
$.when(itemCountsPromise, liveTvInfoPromise).done(function (response1, response2) {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
var counts = response1[0];
|
2014-01-14 13:03:35 -07:00
|
|
|
|
var liveTvInfo = response2[0];
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-01-14 13:03:35 -07:00
|
|
|
|
var panel = getLibraryMenu(page, counts, liveTvInfo);
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
$(panel).panel('toggle');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-14 13:03:35 -07:00
|
|
|
|
function getLibraryMenu(page, counts, 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
|
|
|
|
|
|
|
|
|
if (counts.MovieCount) {
|
2014-03-13 02:00:47 -07:00
|
|
|
|
html += '<li><a class="libraryPanelLink" href="movieslatest.html">Movies</a></li>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (counts.SeriesCount) {
|
2014-03-13 02:00:47 -07:00
|
|
|
|
html += '<li><a class="libraryPanelLink" href="tvrecommended.html">TV</a></li>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 14:09:00 -07:00
|
|
|
|
if (liveTvInfo.EnabledUsers.indexOf(Dashboard.getCurrentUserId()) != -1) {
|
2014-03-13 02:00:47 -07:00
|
|
|
|
html += '<li><a class="libraryPanelLink" href="livetvsuggested.html">Live TV</a></li>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (counts.SongCount || counts.MusicVideoCount) {
|
2014-03-13 02:00:47 -07:00
|
|
|
|
html += '<li><a class="libraryPanelLink" href="musicrecommended.html">Music</a></li>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (counts.GameCount) {
|
2014-03-13 02:00:47 -07:00
|
|
|
|
html += '<li><a class="libraryPanelLink" href="gamesrecommended.html">Games</a></li>';
|
2013-12-27 14:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 02:00:47 -07:00
|
|
|
|
if (counts.BoxSetCount) {
|
|
|
|
|
html += '<li><a class="libraryPanelLink" href="collections.html">Collections</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-03-13 02:00:47 -07:00
|
|
|
|
window.LibraryMenu = {
|
|
|
|
|
showLibraryMenu: showLibraryMenu
|
|
|
|
|
};
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
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-03-13 02:00:47 -07:00
|
|
|
|
}).on('pagebeforeshow', ".libraryPage", function () {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
if (!$('.viewMenuBar', page).length) {
|
|
|
|
|
|
|
|
|
|
Dashboard.getCurrentUser().done(function (user) {
|
|
|
|
|
|
|
|
|
|
renderHeader(page, user);
|
|
|
|
|
|
|
|
|
|
ensurePromises();
|
|
|
|
|
|
2014-01-14 13:03:35 -07:00
|
|
|
|
$.when(itemCountsPromise, liveTvInfoPromise).done(function (response1, response2) {
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
var counts = response1[0];
|
2014-01-14 13:03:35 -07:00
|
|
|
|
var liveTvInfo = response2[0];
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
2014-01-14 13:03:35 -07:00
|
|
|
|
insertViews(page, user, counts, liveTvInfo);
|
2013-12-27 14:10:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(window, document, jQuery);
|