jellyfin-web/dashboard-ui/components/dockedtabs/dockedtabs.js

336 lines
10 KiB
JavaScript
Raw Normal View History

2016-09-01 09:36:11 -07:00
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']);
2016-08-31 12:17:11 -07:00
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':
2016-09-01 09:36:11 -07:00
Dashboard.navigate('edititemmetadata.html');
2016-08-31 12:17:11 -07:00
break;
case 'manageserver':
Dashboard.navigate('dashboard.html');
break;
case 'sync':
Dashboard.navigate('mysync.html');
break;
default:
showUserView(id);
break;
}
}
2016-09-01 09:36:11 -07:00
function showMenu(menuItems, button, tabIndex) {
2016-08-31 12:17:11 -07:00
2016-08-31 13:46:09 -07:00
var actionSheetType = browser.safari ? 'actionsheet' : 'webActionSheet';
require([actionSheetType], function (actionSheet) {
2016-08-31 12:17:11 -07:00
actionSheet.show({
items: menuItems,
positionTo: button,
entryAnimation: 'slideup',
exitAnimation: 'fadeout',
entryAnimationDuration: 160,
exitAnimationDuration: 100,
2016-09-01 09:36:11 -07:00
offsetTop: -35,
2016-08-31 12:17:11 -07:00
positionY: 'top',
dialogClass: 'dockedtabs-dlg',
menuItemClass: 'dockedtabs-dlg-menuitem'
2016-09-01 09:36:11 -07:00
}).then(function (id) {
executeCommand(id);
if (id) {
var tabs = dom.parentWithClass(button, 'dockedtabs-tabs');
tabs.selectedIndex(tabIndex, false);
}
});
2016-08-31 12:17:11 -07:00
});
}
function showLibrariesMenu(button) {
var commands = currentUserViews.map(function (view) {
return {
name: view.Name,
id: view.Id
};
});
2016-09-01 09:36:11 -07:00
showMenu(commands, button, 1);
2016-08-31 12:17:11 -07:00
}
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'
});
2016-09-01 09:36:11 -07:00
if (dom.getWindowSize().innerWidth >= 800) {
commands.push({
name: globalize.translate('MetadataManager'),
id: 'metadatamanager'
});
}
2016-08-31 12:17:11 -07:00
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'
});
2016-09-01 09:36:11 -07:00
showMenu(commands, button, 5);
2016-08-31 12:17:11 -07:00
}
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;
2016-09-01 18:54:30 -07:00
case 6:
Dashboard.navigate('dashboard.html');
break;
2016-08-31 12:17:11 -07:00
default:
break;
}
}
2016-08-13 23:21:30 -07:00
2016-08-31 13:46:09 -07:00
function addNoFlexClass(buttons) {
2016-09-01 09:36:11 -07:00
setTimeout(function () {
2016-08-31 13:46:09 -07:00
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);
}
2016-08-13 23:21:30 -07:00
function render(options) {
var elem = document.createElement('div');
2016-08-31 12:17:11 -07:00
elem.classList.add('hide');
2016-08-13 23:21:30 -07:00
elem.classList.add('dockedtabs');
elem.classList.add('dockedtabs-bottom');
// tabs:
// home
// favorites
// live tv
// now playing
2016-08-14 21:36:17 -07:00
var html = '';
2016-08-31 12:17:11 -07:00
var liveTVButtonClass = appHost.supports('sync') ? ' dockedtab-midsize' : '';
2016-09-01 18:54:30 -07:00
2016-08-14 21:36:17 -07:00
html += ' <div is="emby-tabs" class="dockedtabs-tabs" data-selectionbar="false">\
<button is="emby-button" class="dockedtabs-tab-button emby-tab-button emby-tab-button-active" data-index="0">\
2016-08-31 12:17:11 -07:00
<div class="dockedtabs-tab-button-foreground emby-button-foreground"><i class="dockedtabs-tab-button-icon md-icon">home</i><div>' + globalize.translate('TabHome') + '</div></div>\
2016-08-14 21:36:17 -07:00
</button>\
<button is="emby-button" class="dockedtabs-tab-button emby-tab-button" data-index="1">\
2016-08-31 12:17:11 -07:00
<div class="dockedtabs-tab-button-foreground emby-button-foreground"><i class="dockedtabs-tab-button-icon md-icon">dvr</i><div>' + globalize.translate('HeaderLibraries') + '</div></div>\
2016-08-14 21:36:17 -07:00
</button>\
2016-09-01 18:54:30 -07:00
<button is="emby-button" class="dockedtabs-tab-button emby-tab-button docked-tab-livetv hide' + liveTVButtonClass + '" data-index="2">\
2016-08-31 12:17:11 -07:00
<div class="dockedtabs-tab-button-foreground emby-button-foreground"><i class="dockedtabs-tab-button-icon md-icon">live_tv</i><div>' + globalize.translate('HeaderLiveTV') + '</div></div>\
2016-08-14 21:36:17 -07:00
</button>\
2016-09-03 10:16:36 -07:00
<button is="emby-button" class="dockedtabs-tab-button emby-tab-button" data-index="3">\
2016-08-31 12:17:11 -07:00
<div class="dockedtabs-tab-button-foreground emby-button-foreground"><i class="dockedtabs-tab-button-icon md-icon">favorite</i><div>' + globalize.translate('TabFavorites') + '</div></div>\
2016-08-14 21:36:17 -07:00
</button>\
2016-08-31 12:17:11 -07:00
';
if (appHost.supports('sync')) {
html += '<button is="emby-button" class="dockedtabs-tab-button emby-tab-button" data-index="4">\
<div class="dockedtabs-tab-button-foreground emby-button-foreground"><i class="dockedtabs-tab-button-icon md-icon">file_download</i><div>' + globalize.translate('Downloads') + '</div></div>\
</button>\
';
}
2016-09-01 18:54:30 -07:00
html += '<button is="emby-button" class="dockedtabs-tab-button emby-tab-button docked-tab-manageserver hide dockedtab-midsize" data-index="6">\
<div class="dockedtabs-tab-button-foreground emby-button-foreground"><i class="dockedtabs-tab-button-icon md-icon">dashboard</i><div>' + globalize.translate('ButtonManageServer') + '</div></div>\
</button>\
';
2016-08-31 12:17:11 -07:00
html += '<button is="emby-button" class="dockedtabs-tab-button emby-tab-button" data-index="5">\
<div class="dockedtabs-tab-button-foreground emby-button-foreground"><i class="dockedtabs-tab-button-icon md-icon">menu</i><div>' + globalize.translate('ButtonMore') + '</div></div>\
2016-08-14 21:36:17 -07:00
</button>\
</div>\
';
elem.innerHTML = html;
2016-08-31 12:17:11 -07:00
var buttons = elem.querySelectorAll('.emby-tab-button');
for (var i = 0, length = buttons.length; i < length; i++) {
2016-08-31 13:46:09 -07:00
var button = buttons[i];
button.addEventListener('click', onTabClick);
2016-08-31 12:17:11 -07:00
}
2016-08-31 13:46:09 -07:00
addNoFlexClass(buttons);
2016-08-31 12:17:11 -07:00
2016-08-15 11:18:05 -07:00
options.appFooter.add(elem);
2016-08-13 23:21:30 -07:00
return elem;
}
2016-08-31 12:17:11 -07:00
function onUserViewResponse(user, views, element) {
if (views.filter(function (v) {
return v.CollectionType == 'livetv';
}).length) {
element.querySelector('.docked-tab-livetv').classList.remove('hide');
} else {
element.querySelector('.docked-tab-livetv').classList.add('hide');
}
2016-09-01 18:54:30 -07:00
if (user.Policy.IsAdministrator) {
element.querySelector('.docked-tab-manageserver').classList.remove('hide');
} else {
element.querySelector('.docked-tab-manageserver').classList.add('hide');
}
2016-08-31 12:17:11 -07:00
}
function showUserTabs(user, element) {
currentUser = user;
var apiClient = ConnectionManager.getApiClient(user.ServerId);
apiClient.getUserViews({}, user.Id).then(function (result) {
currentUserViews = result.Items;
onUserViewResponse(user, result.Items, element);
}, function () {
currentUserViews = [];
onUserViewResponse(user, [], element);
});
}
function showCurrentUserTabs(element) {
if (!Dashboard.getCurrentUserId()) {
return;
}
Dashboard.getCurrentUser().then(function (user) {
showUserTabs(user, element);
});
}
2016-08-13 23:21:30 -07:00
function dockedTabs(options) {
var self = this;
self.element = render(options);
2016-08-31 12:17:11 -07:00
events.on(connectionManager, 'localusersignedin', function (e, user) {
self.element.classList.remove('hide');
showUserTabs(user, self.element);
});
events.on(connectionManager, 'localusersignedout', function () {
self.element.classList.add('hide');
});
showCurrentUserTabs(self.element);
2016-08-13 23:21:30 -07:00
}
2016-08-15 11:18:05 -07:00
dockedTabs.prototype.destroy = function () {
2016-08-13 23:21:30 -07:00
var self = this;
2016-08-31 12:17:11 -07:00
var elem = self.element;
if (elem) {
}
self.element = null;
2016-08-13 23:21:30 -07:00
};
return dockedTabs;
});