(function (window, document, $) { var itemCountsPromise; var liveTvInfoPromise; function ensurePromises() { itemCountsPromise = itemCountsPromise || ApiClient.getItemCounts(Dashboard.getCurrentUserId()); liveTvInfoPromise = liveTvInfoPromise || ApiClient.getLiveTvInfo(); } function renderHeader(page, user) { var html = '
'; html += ''; html += ''; html += ''; if (user.Configuration.IsAdministrator) { html += 'Metadata Manager'; } html += '
'; 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 += '
'; var $page = $(page); $page.prepend(html); $('.viewMenuBar', page).trigger('create'); $page.trigger('headercreated'); } function insertViews(page, user, counts, liveTvInfo) { 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 (liveTvInfo.EnabledUsers.indexOf(user.Id) != -1) { html += '' + (view == 'livetv' ? selectedHtml : '') + 'Live TV'; } if (counts.SongCount || counts.MusicVideoCount) { html += '' + (view == 'music' ? selectedHtml : '') + 'Music'; } if (counts.GameCount) { html += '' + (view == 'games' ? selectedHtml : '') + 'Games'; } if (counts.BoxSetCount) { html += '' + (view == 'boxsets' ? selectedHtml : '') + 'Collections'; } $('.viewMenuRemoteControlButton', page).before(html); } function showLibraryMenu(page) { ensurePromises(); $.when(itemCountsPromise, liveTvInfoPromise).done(function (response1, response2) { var counts = response1[0]; var liveTvInfo = response2[0]; var panel = getLibraryMenu(page, counts, liveTvInfo); $(panel).panel('toggle'); }); } function getLibraryMenu(page, counts, liveTvInfo) { var panel = $('#libraryPanel', page); if (!panel.length) { var html = ''; html += '
'; html += '

MEDIABROWSER

'; html += ''; html += '
'; $(page).append(html); panel = $('#libraryPanel', page).panel({}).trigger('create'); } return panel; } window.LibraryMenu = { showLibraryMenu: showLibraryMenu }; $(document).on('pageinit', ".libraryPage", function () { var page = this; $('.libraryViewNav', page).wrapInner('
'); $('.libraryViewNav a', page).each(function () { this.innerHTML = '' + this.innerHTML + ''; }); }).on('pagebeforeshow', ".libraryPage", function () { var page = this; if (!$('.viewMenuBar', page).length) { Dashboard.getCurrentUser().done(function (user) { renderHeader(page, user); ensurePromises(); $.when(itemCountsPromise, liveTvInfoPromise).done(function (response1, response2) { var counts = response1[0]; var liveTvInfo = response2[0]; insertViews(page, user, counts, liveTvInfo); }); }); } }); })(window, document, jQuery);