define(['apphost', 'connectionManager', 'events', 'globalize', 'browser', 'require', 'dom', 'emby-tabs'], function (appHost, connectionManager, events, globalize, browser, require, dom) { // Make sure this is pulled in after button and tab css require(['css!./dockedtabs']); var currentUser = {}; var currentUserViews = []; function showUserView(id) { var view = currentUserViews.filter(function (current) { return current.Id == id; })[0]; if (view) { Emby.Page.showItem(view); } } function executeCommand(id) { switch (id) { case 'settings': Emby.Page.showSettings(); break; case 'signout': Dashboard.logout(); break; case 'selectserver': Emby.Page.showSelectServer(); break; case 'reports': Dashboard.navigate('reports.html'); break; case 'metadatamanager': Dashboard.navigate('edititemmetadata.html'); break; case 'manageserver': Dashboard.navigate('dashboard.html'); break; case 'sync': Dashboard.navigate('mysync.html'); break; default: showUserView(id); break; } } function showMenu(menuItems, button, tabIndex) { var actionSheetType = browser.safari ? 'actionsheet' : 'webActionSheet'; require([actionSheetType], function (actionSheet) { actionSheet.show({ items: menuItems, positionTo: button, entryAnimation: 'slideup', exitAnimation: 'fadeout', entryAnimationDuration: 160, exitAnimationDuration: 100, offsetTop: -35, positionY: 'top', dialogClass: 'dockedtabs-dlg', menuItemClass: 'dockedtabs-dlg-menuitem' }).then(function (id) { executeCommand(id); if (id) { var tabs = dom.parentWithClass(button, 'dockedtabs-tabs'); tabs.selectedIndex(tabIndex, false); } }); }); } function showLibrariesMenu(button) { var commands = currentUserViews.map(function (view) { return { name: view.Name, id: view.Id }; }); showMenu(commands, button, 1); } function showMoreMenu(button) { var commands = []; // manage server, metadata manager, reports, sync to other devices if (currentUser.Policy.IsAdministrator) { commands.push({ name: globalize.translate('ButtonManageServer'), id: 'manageserver' }); if (dom.getWindowSize().innerWidth >= 800) { commands.push({ name: globalize.translate('MetadataManager'), id: 'metadatamanager' }); } commands.push({ name: globalize.translate('ButtonReports'), id: 'reports' }); } if (Dashboard.isConnectMode()) { commands.push({ name: globalize.translate('HeaderSelectServer'), id: 'selectserver' }); } commands.push({ name: globalize.translate('TabSettings'), id: 'settings' }); if (currentUser.Policy.EnableSync) { commands.push({ name: globalize.translate('SyncToOtherDevices'), id: 'sync' }); } commands.push({ name: globalize.translate('ButtonSignOut'), id: 'signout' }); showMenu(commands, button, 5); } function onTabClick(e) { var index = parseInt(this.getAttribute('data-index')); switch (index) { case 0: Emby.Page.goHome(); break; case 1: showLibrariesMenu(this); e.preventDefault(); e.stopPropagation(); break; case 2: Emby.Page.showLiveTV(); break; case 3: Emby.Page.showFavorites(); break; case 4: Dashboard.navigate('mysync.html?mode=offline'); break; case 5: showMoreMenu(this); e.preventDefault(); e.stopPropagation(); break; case 6: Dashboard.navigate('dashboard.html'); break; default: break; } } function addNoFlexClass(buttons) { setTimeout(function () { for (var i = 0, length = buttons.length; i < length; i++) { var button = buttons[i]; if (button.classList.contains('emby-button-noflex')) { button.classList.add('dockedtabs-tab-button-noflex'); } } }, 300); } function render(options) { var elem = document.createElement('div'); elem.classList.add('hide'); elem.classList.add('dockedtabs'); elem.classList.add('dockedtabs-bottom'); // tabs: // home // favorites // live tv // now playing var html = ''; var liveTVButtonClass = appHost.supports('sync') ? ' dockedtab-midsize' : ''; html += '