(function (window, document, $) { function renderHeader(user) { var html = '
'; html += ''; html += '
'; html += ''; html += ''; html += ''; if (user.Configuration.IsAdministrator) { html += ''; } html += ''; if (user.PrimaryImageTag) { var url = ApiClient.getUserImageUrl(user.Id, { height: 18, tag: user.PrimaryImageTag, type: "Primary" }); html += ''; } else { html += ''; } html += ''; html += '
'; html += '
'; $(document.body).prepend(html); $(document).trigger('headercreated'); } function getItemHref(item) { return LibraryBrowser.getHref(item); } function getViewsHtml() { var html = ''; html += '
'; html += '
'; html += ''; html += ''; html += ''; html += '
'; html += '
'; html += 'Dashboard'; html += 'Metadata Manager'; html += 'Reports'; html += '
'; return html; } function showLibraryMenu() { var panel = getLibraryMenu(); updateLibraryNavLinks($.mobile.activePage); $(panel).panel('toggle'); } function updateLibraryMenu(panel) { var userId = Dashboard.getCurrentUserId(); ApiClient.getItems(userId, { SortBy: "SortName" }).done(function (result) { var items = result.Items; var html = items.map(function (i) { var viewMenuCssClass = (i.CollectionType || 'general') + 'ViewMenu'; return '' + i.Name + ''; }).join(''); var elem = $('.libraryMenuOptions').html(html); $('.viewMenuTextLink', elem).on('click', function () { $('.libraryMenuButtonText').html(this.innerHTML); }); }); ApiClient.getLiveTvInfo().done(function (liveTvInfo) { var showLiveTv = liveTvInfo.EnabledUsers.indexOf(userId) != -1; if (showLiveTv) { $('.liveTvMenuOption').show(); $('.secondaryDivider').show(); } }); $.getJSON(ApiClient.getUrl("Channels", { userId: userId, // We just want the total record count limit: 0 })).done(function (response) { if (response.TotalRecordCount) { $('.channelsMenuOption').show(); $('.secondaryDivider').show(); } }); Dashboard.getCurrentUser().done(function (user) { if (user.Configuration.IsAdministrator) { $('.adminMenuOptions').show(); } else { $('.adminMenuOptions').hide(); } }); } function getLibraryMenu(user, channelCount, items, liveTvInfo) { var panel = $('#libraryPanel'); if (!panel.length) { var html = ''; html += '
'; html += '
'; html += 'Home'; html += '
'; html += getViewsHtml(user, channelCount, items, liveTvInfo); html += '
'; html += '
'; $(document.body).append(html); panel = $('#libraryPanel').panel({}).trigger('create'); updateLibraryMenu(); } return panel; } function getTopParentId() { return getParameterByName('topParentId') || sessionStorage.getItem('topParentId') || null; } window.LibraryMenu = { showLibraryMenu: showLibraryMenu, getTopParentId: getTopParentId }; function updateCastIcon() { var info = MediaController.getPlayerInfo(); if (info.isLocalPlayer) { $('.btnCast').addClass('btnDefaultCast').removeClass('btnActiveCast'); } else { $('.btnCast').removeClass('btnDefaultCast').addClass('btnActiveCast'); } } function updateLibraryNavLinks(page) { page = $(page); var isLiveTvPage = page.hasClass('liveTvPage'); var isChannelsPage = page.hasClass('channelsPage'); var isEditorPage = page.hasClass('metadataEditorPage'); var isReportsPage = page.hasClass('reportsPage'); var id = isLiveTvPage || isChannelsPage || isEditorPage || isReportsPage || page.hasClass('allLibraryPage') ? '' : getTopParentId() || ''; sessionStorage.setItem('topParentId', id); $('.lnkMediaFolder').each(function () { var itemId = this.getAttribute('data-itemid'); if (isChannelsPage && itemId == 'channels') { $(this).addClass('selectedMediaFolder'); } else if (isLiveTvPage && itemId == 'livetv') { $(this).addClass('selectedMediaFolder'); } else if (isEditorPage && itemId == 'editor') { $(this).addClass('selectedMediaFolder'); } else if (isReportsPage && itemId == 'reports') { $(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; }); } function updateContextText(page) { var name = page.getAttribute('data-contextname'); if (name) { $('.libraryMenuButtonText').html('' + name + ''); } else if ($(page).hasClass('allLibraryPage')) { $('.libraryMenuButtonText').html('MEDIABROWSER'); } } $(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').length) { Dashboard.getCurrentUser().done(function (user) { renderHeader(user); updateCastIcon(); updateLibraryNavLinks(page); updateContextText(page); }); } else { updateContextText(page); updateLibraryNavLinks(page); } }).on('pageshow', ".libraryPage", function () { var page = this; var elem = $('.libraryViewNavInner .ui-btn-active:visible', page); if (elem.length) { elem[0].scrollIntoView(); // Scroll back up so in case vertical scroll was messed with $(document).scrollTop(0); } }); $(function () { $(MediaController).on('playerchange', function () { updateCastIcon(); }); }); })(window, document, jQuery);