(function (window, document, $) { var itemCountsPromise; var liveTvServicesPromise; function ensurePromises() { itemCountsPromise = itemCountsPromise || ApiClient.getItemCounts(Dashboard.getCurrentUserId()); liveTvServicesPromise = liveTvServicesPromise || ApiClient.getLiveTvServices(); } function renderHeader(page, user) { var html = '
'; html += ''; html += ''; html += ''; if (user.Configuration.IsAdministrator) { html += 'Metadata Manager'; } html += '
'; html += ''; if (user.PrimaryImageTag) { var url = ApiClient.getUserImageUrl(user.Id, { height: 40, tag: user.PrimaryImageTag, type: "Primary" }); html += ''; } else { html += ''; } html += ''; html += ''; if (user.Configuration.IsAdministrator) { html += 'Dashboard'; } html += '
'; html += '
'; $(page).prepend(html); $('.viewMenuBar', page).trigger('create'); } function insertViews(page, user, counts, liveTvServices) { var html = ''; var selectedCssClass = ' selectedViewLink'; var selectedHtml = ""; var view = page.getAttribute('data-view') || getParameterByName('context'); if (counts.MovieCount) { html += '' + (view == 'movies' ? selectedHtml : '') + 'Movies'; } if (counts.SeriesCount) { html += '' + (view == 'tv' ? selectedHtml : '') + 'TV'; } if (liveTvServices.length) { html += '' + (view == 'livetv' ? selectedHtml : '') + 'Live TV'; } if (counts.SongCount || counts.MusicVideoCount) { html += '' + (view == 'music' ? selectedHtml : '') + 'Music'; } if (counts.GameCount) { html += '' + (view == 'games' ? selectedHtml : '') + 'Games'; } $('.viewMenuRemoteControlButton', page).before(html); } function showLibraryMenu(page) { ensurePromises(); $.when(itemCountsPromise, liveTvServicesPromise).done(function (response1, response2) { var counts = response1[0]; var liveTvServices = response2[0]; var panel = getLibraryMenu(page, counts, liveTvServices); $(panel).panel('toggle'); }); } function getLibraryMenu(page, counts, liveTvServices) { var panel = $('#libraryPanel', page); if (!panel.length) { var html = ''; html += '
'; html += '

MEDIABROWSER

'; html += '
'; if (counts.MovieCount) { html += getCollapsibleHtml('Movies', [ { text: 'Suggested', href: 'moviesrecommended.html' }, { text: 'Movies', href: 'movies.html' }, { text: 'Box Sets', href: 'boxsets.html' }, { text: 'Trailers', href: 'movietrailers.html' }, { text: 'Genres', href: 'moviegenres.html' }, { text: 'People', href: 'moviepeople.html' }, { text: 'Studios', href: 'moviestudios.html' } ]); } if (counts.SeriesCount) { html += getCollapsibleHtml('TV', [ { text: 'Suggested', href: 'tvrecommended.html' }, { text: 'Next Up', href: 'tvnextup.html' }, { text: 'Upcoming', href: 'tvupcoming.html' }, { text: 'Shows', href: 'tvshows.html' }, { text: 'Episodes', href: 'episodes.html' }, { text: 'Genres', href: 'tvgenres.html' }, { text: 'People', href: 'tvpeople.html' }, { text: 'Networks', href: 'tvstudios.html' } ]); } if (liveTvServices.length) { html += getCollapsibleHtml('Live TV', [ { text: 'Guide', href: 'livetvguide.html' }, { text: 'Channels', href: 'livetvchannels.html' }, { text: 'Recordings', href: 'livetvrecordings.html' }, { text: 'Scheduled', href: 'livetvtimers.html' }, { text: 'Series', href: 'livetvseriestimers.html' } ]); } if (counts.SongCount || counts.MusicVideoCount) { html += getCollapsibleHtml('Music', [ { text: 'Suggested', href: 'musicrecommended.html' }, { text: 'Songs', href: 'songs.html' }, { text: 'Albums', href: 'musicalbums.html' }, { text: 'Album Artists', href: 'musicalbumartists.html' }, { text: 'Artists', href: 'musicartists.html' }, { text: 'Music Videos', href: 'musicvideos.html' }, { text: 'Genres', href: 'musicgenres.html' } ]); } if (counts.GameCount) { html += getCollapsibleHtml('Games', [ { text: 'Suggested', href: 'gamesrecommended.html' }, { text: 'Games', href: 'games.html' }, { text: 'Game Systems', href: 'gamesystems.html' }, { text: 'Genres', href: 'gamegenres.html' }, { text: 'Studios', href: 'gamestudios.html' } ]); } html += '
'; html += '
'; $(page).append(html); panel = $('#libraryPanel', page).panel({}).trigger('create'); } return panel; } function getCollapsibleHtml(title, links) { var i, length; var selectedIndex = -1; var collapsed = 'true'; var currentUrl = window.location.toString().toLowerCase(); for (i = 0, length = links.length; i < length; i++) { if (currentUrl.indexOf(links[i].href.toLowerCase()) != -1) { collapsed = 'false'; selectedIndex = i; break; } } var html = ''; html += '
'; html += '

' + title + '

'; html += ''; html += '
'; return html; } window.LibraryMenu = { showLibraryMenu: showLibraryMenu }; $(document).on('pagebeforeshow', ".libraryPage", function () { var page = this; if (!$('.viewMenuBar', page).length) { Dashboard.getCurrentUser().done(function (user) { renderHeader(page, user); ensurePromises(); $.when(itemCountsPromise, liveTvServicesPromise).done(function (response1, response2) { var counts = response1[0]; var liveTvServices = response2[0]; insertViews(page, user, counts, liveTvServices); }); }); } }); })(window, document, jQuery);