2016-05-28 11:03:38 -07:00
|
|
|
define(['playbackManager', 'inputManager', 'connectionManager', 'embyRouter', 'globalize', 'loading'], function (playbackManager, inputManager, connectionManager, embyRouter, globalize, loading) {
|
2016-04-26 11:28:04 -07:00
|
|
|
|
|
|
|
function playAllFromHere(card, serverId) {
|
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-04-26 11:28:04 -07:00
|
|
|
playbackManager.play({
|
|
|
|
ids: ids,
|
|
|
|
serverId: serverId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
function executeAction(card, action) {
|
2016-07-16 11:02:39 -07:00
|
|
|
|
2016-04-26 11:28:04 -07:00
|
|
|
var id = card.getAttribute('data-id');
|
2016-07-16 11:02:39 -07:00
|
|
|
|
|
|
|
if (!id) {
|
|
|
|
card = parentWithAttribute(card, 'data-id');
|
|
|
|
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') {
|
|
|
|
|
|
|
|
var startPositionTicks = parseInt(card.getAttribute('data-startpositionticks') || '0');
|
|
|
|
|
|
|
|
playbackManager.play({
|
|
|
|
ids: [id],
|
|
|
|
startPositionTicks: startPositionTicks,
|
|
|
|
serverId: serverId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (action == 'playallfromhere') {
|
|
|
|
playAllFromHere(card, serverId);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (action == 'setplaylistindex') {
|
|
|
|
|
|
|
|
}
|
2016-05-28 11:03:38 -07:00
|
|
|
|
|
|
|
else if (action == 'record') {
|
|
|
|
onRecordCommand(serverId, id, type, card.getAttribute('data-timerid'), card.getAttribute('data-seriestimerid'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
var card = parentWithClass(e.target, 'itemAction');
|
|
|
|
|
|
|
|
if (card) {
|
2016-07-16 11:02:39 -07:00
|
|
|
|
|
|
|
var actionElement = card;
|
|
|
|
var action = actionElement.getAttribute('data-action');
|
|
|
|
|
|
|
|
if (!action) {
|
|
|
|
actionElement = parentWithAttribute(actionElement, 'data-action');
|
|
|
|
action = actionElement.getAttribute('data-action');
|
|
|
|
}
|
2016-04-26 11:28:04 -07:00
|
|
|
|
|
|
|
if (action) {
|
|
|
|
executeAction(card, action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 11:02:39 -07:00
|
|
|
function parentWithAttribute(elem, name) {
|
|
|
|
|
|
|
|
while (!elem.getAttribute(name)) {
|
|
|
|
elem = elem.parentNode;
|
|
|
|
|
|
|
|
if (!elem) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
2016-04-26 11:28:04 -07:00
|
|
|
function parentWithClass(elem, className) {
|
|
|
|
|
|
|
|
while (!elem.classList || !elem.classList.contains(className)) {
|
|
|
|
elem = elem.parentNode;
|
|
|
|
|
|
|
|
if (!elem) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCommand(e) {
|
|
|
|
var cmd = e.detail.command;
|
|
|
|
|
2016-05-28 11:03:38 -07:00
|
|
|
if (cmd == 'play' || cmd == 'record') {
|
2016-04-26 11:28:04 -07:00
|
|
|
var card = parentWithClass(e.target, 'itemAction');
|
|
|
|
|
|
|
|
if (card) {
|
|
|
|
executeAction(card, cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function on(context) {
|
|
|
|
context.addEventListener('click', onClick);
|
|
|
|
inputManager.on(context, onCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
function off(context) {
|
|
|
|
context.removeEventListener('click', onClick);
|
|
|
|
inputManager.off(context, onCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
on: on,
|
|
|
|
off: off
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|