2016-07-18 11:50:00 -07:00
|
|
|
define(['playbackManager', 'inputManager', 'connectionManager', 'embyRouter', 'globalize', 'loading', 'dom'], function (playbackManager, inputManager, connectionManager, embyRouter, globalize, loading, dom) {
|
2016-04-26 11:28:04 -07:00
|
|
|
|
2016-07-16 16:39:10 -07:00
|
|
|
function playAllFromHere(card, serverId, queue) {
|
2016-07-16 11:02:39 -07:00
|
|
|
|
|
|
|
var parent = card.parentNode;
|
|
|
|
var className = card.classList.length ? ('.' + card.classList[0]) : '';
|
|
|
|
var cards = parent.querySelectorAll(className + '[data-id]');
|
|
|
|
|
2016-04-26 11:28:04 -07:00
|
|
|
var ids = [];
|
|
|
|
|
|
|
|
var foundCard = false;
|
|
|
|
for (var i = 0, length = cards.length; i < length; i++) {
|
|
|
|
if (cards[i] == card) {
|
|
|
|
foundCard = true;
|
|
|
|
}
|
|
|
|
if (foundCard) {
|
|
|
|
ids.push(cards[i].getAttribute('data-id'));
|
|
|
|
}
|
|
|
|
}
|
2016-07-16 11:02:39 -07:00
|
|
|
|
|
|
|
if (!ids.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-16 16:39:10 -07:00
|
|
|
if (queue) {
|
|
|
|
playbackManager.queue({
|
|
|
|
ids: ids,
|
|
|
|
serverId: serverId
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
playbackManager.play({
|
|
|
|
ids: ids,
|
|
|
|
serverId: serverId
|
|
|
|
});
|
|
|
|
}
|
2016-04-26 11:28:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function showSlideshow(startItemId, serverId) {
|
|
|
|
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
var userId = apiClient.getCurrentUserId();
|
|
|
|
|
|
|
|
return apiClient.getItem(userId, startItemId).then(function (item) {
|
|
|
|
|
|
|
|
return apiClient.getItems(userId, {
|
|
|
|
|
|
|
|
MediaTypes: 'Photo',
|
|
|
|
Filters: 'IsNotFolder',
|
|
|
|
ParentId: item.ParentId
|
|
|
|
|
|
|
|
}).then(function (result) {
|
|
|
|
|
|
|
|
var items = result.Items;
|
|
|
|
|
|
|
|
var index = items.map(function (i) {
|
|
|
|
return i.Id;
|
|
|
|
|
|
|
|
}).indexOf(startItemId);
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
require(['slideshow'], function (slideshow) {
|
|
|
|
|
|
|
|
var newSlideShow = new slideshow({
|
|
|
|
showTitle: false,
|
|
|
|
cover: false,
|
|
|
|
items: items,
|
|
|
|
startIndex: index,
|
|
|
|
interval: 8000,
|
|
|
|
interactive: true
|
|
|
|
});
|
|
|
|
|
|
|
|
newSlideShow.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function showItem(options) {
|
|
|
|
|
|
|
|
if (options.Type == 'Photo') {
|
|
|
|
|
|
|
|
showSlideshow(options.Id, options.ServerId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
embyRouter.showItem(options);
|
|
|
|
}
|
|
|
|
|
2016-07-17 13:08:04 -07:00
|
|
|
function getItem(button) {
|
|
|
|
|
2016-07-18 11:50:00 -07:00
|
|
|
button = dom.parentWithAttribute(button, 'data-id');
|
2016-07-17 13:08:04 -07:00
|
|
|
var serverId = button.getAttribute('data-serverid');
|
|
|
|
var id = button.getAttribute('data-id');
|
|
|
|
var type = button.getAttribute('data-type');
|
|
|
|
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
|
2016-07-17 19:55:07 -07:00
|
|
|
if (type == 'Timer') {
|
|
|
|
return apiClient.getLiveTvTimer(id);
|
|
|
|
}
|
2016-07-17 13:08:04 -07:00
|
|
|
return apiClient.getItem(apiClient.getCurrentUserId(), id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showContextMenu(card, options) {
|
|
|
|
|
|
|
|
getItem(card).then(function (item) {
|
|
|
|
|
2016-07-20 13:45:50 -07:00
|
|
|
var playlistId = card.getAttribute('data-playlistid');
|
|
|
|
var collectionId = card.getAttribute('data-collectionid');
|
2016-07-17 13:08:04 -07:00
|
|
|
|
|
|
|
if (playlistId) {
|
2016-07-18 11:50:00 -07:00
|
|
|
var elem = dom.parentWithAttribute(card, 'data-playlistitemid');
|
2016-07-17 13:08:04 -07:00
|
|
|
item.PlaylistItemId = elem ? elem.getAttribute('data-playlistitemid') : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
require(['itemContextMenu'], function (itemContextMenu) {
|
|
|
|
|
|
|
|
itemContextMenu.show(Object.assign({
|
|
|
|
item: item,
|
|
|
|
play: true,
|
|
|
|
queue: true,
|
|
|
|
playAllFromHere: !item.IsFolder,
|
|
|
|
queueAllFromHere: !item.IsFolder,
|
|
|
|
identify: false,
|
|
|
|
playlistId: playlistId,
|
|
|
|
collectionId: collectionId
|
|
|
|
|
|
|
|
}, options || {})).then(function (result) {
|
|
|
|
|
|
|
|
if (result.command == 'playallfromhere' || result.command == 'queueallfromhere') {
|
|
|
|
executeAction(card, options.positionTo, result.command);
|
|
|
|
}
|
|
|
|
else if (result.command == 'removefromplaylist' || result.command == 'removefromcollection') {
|
|
|
|
|
2016-07-20 13:45:50 -07:00
|
|
|
var itemsContainer = options.itemsContainer || dom.parentWithAttribute(card, 'is', 'emby-itemscontainer');
|
|
|
|
|
2016-07-17 13:08:04 -07:00
|
|
|
if (itemsContainer) {
|
|
|
|
itemsContainer.dispatchEvent(new CustomEvent('needsrefresh', {
|
|
|
|
detail: {},
|
|
|
|
cancelable: false,
|
|
|
|
bubbles: true
|
|
|
|
}));
|
2016-07-19 12:51:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (result.command == 'canceltimer') {
|
|
|
|
|
2016-07-20 13:45:50 -07:00
|
|
|
var itemsContainer = options.itemsContainer || dom.parentWithAttribute(card, 'is', 'emby-itemscontainer');
|
|
|
|
|
2016-07-19 12:51:22 -07:00
|
|
|
if (itemsContainer) {
|
|
|
|
itemsContainer.dispatchEvent(new CustomEvent('timercancelled', {
|
|
|
|
detail: {},
|
|
|
|
cancelable: false,
|
|
|
|
bubbles: true
|
|
|
|
}));
|
2016-07-17 13:08:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPlayMenu(card, target) {
|
|
|
|
|
2016-07-18 20:57:55 -07:00
|
|
|
var item = {
|
|
|
|
Type: card.getAttribute('data-type'),
|
|
|
|
Id: card.getAttribute('data-id'),
|
|
|
|
ServerId: card.getAttribute('data-serverid'),
|
|
|
|
MediaType: card.getAttribute('data-mediatype'),
|
|
|
|
IsFolder: card.getAttribute('data-isfolder') == 'true',
|
|
|
|
UserData: {
|
|
|
|
PlaybackPositionTicks: parseInt(card.getAttribute('data-positionticks') || '0')
|
|
|
|
}
|
|
|
|
};
|
2016-07-17 13:08:04 -07:00
|
|
|
|
2016-07-18 20:57:55 -07:00
|
|
|
require(['playMenu'], function (playMenu) {
|
2016-07-17 13:08:04 -07:00
|
|
|
|
2016-07-18 20:57:55 -07:00
|
|
|
playMenu.show({
|
2016-07-17 13:08:04 -07:00
|
|
|
|
2016-07-18 20:57:55 -07:00
|
|
|
item: item,
|
|
|
|
positionTo: target
|
2016-07-17 13:08:04 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function executeAction(card, target, action) {
|
2016-07-16 11:02:39 -07:00
|
|
|
|
2016-07-17 19:55:07 -07:00
|
|
|
target = target || card;
|
|
|
|
|
2016-04-26 11:28:04 -07:00
|
|
|
var id = card.getAttribute('data-id');
|
2016-07-16 11:02:39 -07:00
|
|
|
|
|
|
|
if (!id) {
|
2016-07-18 11:50:00 -07:00
|
|
|
card = dom.parentWithAttribute(card, 'data-id');
|
2016-07-16 11:02:39 -07:00
|
|
|
id = card.getAttribute('data-id');
|
|
|
|
}
|
|
|
|
|
2016-04-26 11:28:04 -07:00
|
|
|
var serverId = card.getAttribute('data-serverid');
|
|
|
|
var type = card.getAttribute('data-type');
|
|
|
|
var isfolder = card.getAttribute('data-isfolder') == 'true';
|
|
|
|
|
|
|
|
if (action == 'link') {
|
|
|
|
showItem({
|
|
|
|
Id: id,
|
|
|
|
Type: type,
|
|
|
|
IsFolder: isfolder,
|
|
|
|
ServerId: serverId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (action == 'instantmix') {
|
|
|
|
playbackManager.instantMix(id, serverId);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (action == 'play') {
|
|
|
|
|
2016-07-18 20:57:55 -07:00
|
|
|
var startPositionTicks = parseInt(card.getAttribute('data-positionticks') || '0');
|
2016-04-26 11:28:04 -07:00
|
|
|
|
|
|
|
playbackManager.play({
|
|
|
|
ids: [id],
|
|
|
|
startPositionTicks: startPositionTicks,
|
|
|
|
serverId: serverId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (action == 'playallfromhere') {
|
|
|
|
playAllFromHere(card, serverId);
|
|
|
|
}
|
|
|
|
|
2016-07-16 16:39:10 -07:00
|
|
|
else if (action == 'queueallfromhere') {
|
|
|
|
playAllFromHere(card, serverId, true);
|
|
|
|
}
|
|
|
|
|
2016-04-26 11:28:04 -07:00
|
|
|
else if (action == 'setplaylistindex') {
|
2016-07-16 14:28:15 -07:00
|
|
|
playbackManager.currentPlaylistIndex(parseInt(card.getAttribute('data-index')));
|
2016-04-26 11:28:04 -07:00
|
|
|
}
|
2016-05-28 11:03:38 -07:00
|
|
|
|
|
|
|
else if (action == 'record') {
|
|
|
|
onRecordCommand(serverId, id, type, card.getAttribute('data-timerid'), card.getAttribute('data-seriestimerid'));
|
|
|
|
}
|
2016-07-17 13:08:04 -07:00
|
|
|
|
|
|
|
else if (action == 'menu') {
|
2016-07-17 19:55:07 -07:00
|
|
|
|
|
|
|
var options = target.getAttribute('data-playoptions') == 'false' ?
|
|
|
|
{
|
|
|
|
shuffle: false,
|
|
|
|
instantMix: false,
|
|
|
|
play: false,
|
|
|
|
playAllFromHere: false,
|
|
|
|
queue: false,
|
|
|
|
queueAllFromHere: false
|
|
|
|
} :
|
|
|
|
{};
|
|
|
|
|
|
|
|
options.identify = false;
|
|
|
|
options.positionTo = target;
|
|
|
|
|
|
|
|
showContextMenu(card, options);
|
2016-07-17 13:08:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (action == 'playmenu') {
|
2016-07-17 19:55:07 -07:00
|
|
|
showPlayMenu(card, target);
|
2016-07-17 13:08:04 -07:00
|
|
|
}
|
2016-07-17 20:33:35 -07:00
|
|
|
|
|
|
|
else if (action == 'edit') {
|
|
|
|
getItem(target).then(function (item) {
|
|
|
|
editItem(item, serverId);
|
|
|
|
});
|
|
|
|
}
|
2016-07-18 10:45:14 -07:00
|
|
|
|
|
|
|
else if (action == 'playtrailer') {
|
|
|
|
getItem(target).then(playTrailer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function playTrailer(item) {
|
|
|
|
|
|
|
|
var apiClient = connectionManager.getApiClient(item.ServerId);
|
|
|
|
|
|
|
|
apiClient.getLocalTrailers(apiClient.getCurrentUserId(), item.Id).then(function (trailers) {
|
|
|
|
playbackManager.play({ items: trailers });
|
|
|
|
});
|
2016-07-17 20:33:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function editItem(item, serverId) {
|
|
|
|
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
|
|
|
if (item.Type == 'Timer') {
|
|
|
|
require(['recordingEditor'], function (recordingEditor) {
|
|
|
|
|
|
|
|
var serverId = apiClient.serverInfo().Id;
|
|
|
|
recordingEditor.show(item.Id, serverId).then(resolve, reject);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
require(['components/metadataeditor/metadataeditor'], function (metadataeditor) {
|
|
|
|
|
|
|
|
metadataeditor.show(item.Id).then(resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-05-28 11:03:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onRecordCommand(serverId, id, type, timerId, seriesTimerId) {
|
|
|
|
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
|
2016-05-28 23:43:00 -07:00
|
|
|
if (seriesTimerId && timerId) {
|
|
|
|
|
|
|
|
// cancel
|
|
|
|
cancelTimer(apiClient, timerId, true);
|
2016-05-28 11:03:38 -07:00
|
|
|
|
|
|
|
} else if (timerId) {
|
|
|
|
|
|
|
|
// change to series recording, if possible
|
|
|
|
// otherwise cancel individual recording
|
2016-05-28 23:43:00 -07:00
|
|
|
changeRecordingToSeries(apiClient, timerId, id);
|
2016-05-28 11:03:38 -07:00
|
|
|
|
|
|
|
} else if (type == 'Program') {
|
|
|
|
// schedule recording
|
|
|
|
createRecording(apiClient, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-28 23:43:00 -07:00
|
|
|
function changeRecordingToSeries(apiClient, timerId, programId) {
|
|
|
|
|
|
|
|
loading.show();
|
|
|
|
|
|
|
|
apiClient.getItem(apiClient.getCurrentUserId(), programId).then(function (item) {
|
|
|
|
|
|
|
|
if (item.IsSeries) {
|
|
|
|
// cancel, then create series
|
|
|
|
cancelTimer(apiClient, timerId, false).then(function () {
|
|
|
|
apiClient.getNewLiveTvTimerDefaults({ programId: programId }).then(function (timerDefaults) {
|
|
|
|
|
|
|
|
apiClient.createLiveTvSeriesTimer(timerDefaults).then(function () {
|
|
|
|
|
|
|
|
loading.hide();
|
|
|
|
sendToast(globalize.translate('sharedcomponents#SeriesRecordingScheduled'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// cancel
|
|
|
|
cancelTimer(apiClient, timerId, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancelTimer(apiClient, timerId, hideLoading) {
|
|
|
|
loading.show();
|
|
|
|
return apiClient.cancelLiveTvTimer(timerId).then(function () {
|
|
|
|
|
|
|
|
if (hideLoading) {
|
|
|
|
loading.hide();
|
|
|
|
sendToast(globalize.translate('sharedcomponents#RecordingCancelled'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-28 11:03:38 -07:00
|
|
|
function createRecording(apiClient, programId) {
|
|
|
|
|
|
|
|
loading.show();
|
|
|
|
apiClient.getNewLiveTvTimerDefaults({ programId: programId }).then(function (item) {
|
|
|
|
|
|
|
|
apiClient.createLiveTvTimer(item).then(function () {
|
|
|
|
|
|
|
|
loading.hide();
|
|
|
|
sendToast(globalize.translate('sharedcomponents#RecordingScheduled'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendToast(msg) {
|
|
|
|
require(['toast'], function (toast) {
|
|
|
|
toast(msg);
|
|
|
|
});
|
2016-04-26 11:28:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onClick(e) {
|
2016-07-17 20:33:35 -07:00
|
|
|
|
2016-07-18 11:50:00 -07:00
|
|
|
var card = dom.parentWithClass(e.target, 'itemAction');
|
2016-04-26 11:28:04 -07:00
|
|
|
|
|
|
|
if (card) {
|
2016-07-16 11:02:39 -07:00
|
|
|
|
|
|
|
var actionElement = card;
|
|
|
|
var action = actionElement.getAttribute('data-action');
|
|
|
|
|
|
|
|
if (!action) {
|
2016-07-18 11:50:00 -07:00
|
|
|
actionElement = dom.parentWithAttribute(actionElement, 'data-action');
|
2016-07-16 11:02:39 -07:00
|
|
|
action = actionElement.getAttribute('data-action');
|
|
|
|
}
|
2016-04-26 11:28:04 -07:00
|
|
|
|
|
|
|
if (action) {
|
2016-07-17 19:55:07 -07:00
|
|
|
executeAction(card, actionElement, action);
|
2016-07-17 11:55:07 -07:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
return false;
|
2016-04-26 11:28:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCommand(e) {
|
|
|
|
var cmd = e.detail.command;
|
|
|
|
|
2016-07-17 19:55:07 -07:00
|
|
|
if (cmd == 'play' || cmd == 'record' || cmd == 'menu' || cmd == 'info') {
|
2016-07-18 11:50:00 -07:00
|
|
|
var card = dom.parentWithClass(e.target, 'itemAction');
|
2016-04-26 11:28:04 -07:00
|
|
|
|
|
|
|
if (card) {
|
2016-07-17 13:08:04 -07:00
|
|
|
executeAction(card, card, cmd);
|
2016-04-26 11:28:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 11:55:07 -07:00
|
|
|
function on(context, options) {
|
|
|
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
if (options.click !== false) {
|
|
|
|
context.addEventListener('click', onClick);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.command !== false) {
|
|
|
|
inputManager.on(context, onCommand);
|
|
|
|
}
|
2016-04-26 11:28:04 -07:00
|
|
|
}
|
|
|
|
|
2016-07-17 11:55:07 -07:00
|
|
|
function off(context, options) {
|
|
|
|
options = options || {};
|
|
|
|
|
2016-04-26 11:28:04 -07:00
|
|
|
context.removeEventListener('click', onClick);
|
2016-07-17 11:55:07 -07:00
|
|
|
|
|
|
|
if (options.command !== false) {
|
|
|
|
inputManager.off(context, onCommand);
|
|
|
|
}
|
2016-04-26 11:28:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
on: on,
|
2016-07-16 16:39:10 -07:00
|
|
|
off: off,
|
2016-07-17 13:08:04 -07:00
|
|
|
onClick: onClick,
|
|
|
|
showContextMenu: showContextMenu
|
2016-04-26 11:28:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
});
|