use shared play menu

This commit is contained in:
Luke Pulverenti 2016-07-17 16:08:04 -04:00
parent f3cde16786
commit 83adc06fa2
15 changed files with 222 additions and 164 deletions

View file

@ -2,19 +2,6 @@
var ItemsContainerProtoType = Object.create(HTMLDivElement.prototype);
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
function parentWithAttribute(elem, name) {
while (!elem.getAttribute(name)) {
@ -28,75 +15,11 @@
return elem;
}
function getItem(button) {
button = parentWithAttribute(button, 'data-id');
var serverId = button.getAttribute('data-serverid');
var id = button.getAttribute('data-id');
var type = button.getAttribute('data-type');
var apiClient = connectionManager.getApiClient(serverId);
return apiClient.getItem(apiClient.getCurrentUserId(), id);
}
function showContextMenu(button, itemsContainer) {
getItem(button).then(function (item) {
var playlistId = itemsContainer.getAttribute('data-playlistid');
var collectionId = itemsContainer.getAttribute('data-collectionid');
if (playlistId) {
var elem = parentWithAttribute(button, 'data-playlistitemid');
item.PlaylistItemId = elem ? elem.getAttribute('data-playlistitemid') : null;
}
require(['itemContextMenu'], function (itemContextMenu) {
itemContextMenu.show({
positionTo: button,
item: item,
play: true,
queue: true,
playAllFromHere: !item.IsFolder,
queueAllFromHere: !item.IsFolder,
identify: false,
playlistId: playlistId,
collectionId: collectionId
}).then(function (result) {
if (result.command == 'playallfromhere' || result.command == 'queueallfromhere') {
itemShortcuts.execute(button, result.command);
}
else if (result.command == 'removefromplaylist' || result.command == 'removefromcollection') {
itemsContainer.dispatchEvent(new CustomEvent('needsrefresh', {
detail: {},
cancelable: false,
bubbles: true
}));
}
});
});
});
}
function onClick(e) {
var itemsContainer = this;
var target = e.target;
var menuButton = parentWithClass(target, 'menuButton');
if (menuButton) {
var card = parentWithAttribute(target, 'data-id');
if (card) {
showContextMenu(card, target);
e.stopPropagation();
return false;
}
}
itemShortcuts.onClick.call(this, e);
}
@ -107,28 +30,6 @@
return false;
}
function showContextMenu(card, target, options) {
var itemId = card.getAttribute('data-id');
var serverId = card.getAttribute('data-serverid');
var type = card.getAttribute('data-type');
var apiClient = connectionManager.getApiClient(serverId);
var promise = type == 'Timer' ? apiClient.getLiveTvTimer(itemId) : apiClient.getItem(apiClient.getCurrentUserId(), itemId);
promise.then(function (item) {
require(['itemContextMenu'], function (itemContextMenu) {
itemContextMenu.show(Object.assign(options || {}, {
item: item,
positionTo: target
}));
});
});
}
function onContextMenu(e) {
var itemsContainer = this;
@ -143,8 +44,10 @@
// showContextMenu(card, {});
//}
showContextMenu(card, target, {
identify: false
itemShortcuts.showContextMenu(card, {
identify: false,
positionTo: target,
itemsContainer: itemsContainer
});
}