2019-01-10 15:39:37 +03:00
|
|
|
define(['apphost', 'globalize', 'connectionManager', 'itemHelper', 'appRouter', 'playbackManager', 'loading', 'appSettings', 'browser', 'actionsheet'], function (appHost, globalize, connectionManager, itemHelper, appRouter, playbackManager, loading, appSettings, browser, actionsheet) {
|
|
|
|
'use strict';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function getCommands(options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var item = options.item;
|
|
|
|
|
|
|
|
var canPlay = playbackManager.canPlay(item);
|
|
|
|
|
|
|
|
var commands = [];
|
|
|
|
|
|
|
|
var user = options.user;
|
|
|
|
|
|
|
|
var restrictOptions = (browser.operaTv || browser.web0s) && !user.Policy.IsAdministrator;
|
|
|
|
|
|
|
|
if (canPlay && item.MediaType !== 'Photo') {
|
|
|
|
if (options.play !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Play'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'resume'
|
2019-01-10 15:41:25 +03:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.playAllFromHere && item.Type !== 'Program' && item.Type !== 'TvChannel') {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('PlayAllFromHere'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'playallfromhere'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playbackManager.canQueue(item)) {
|
|
|
|
|
|
|
|
if (options.queue !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('AddToPlayQueue'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'queue'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.queue !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('PlayNext'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'queuenext'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (options.queueAllFromHere) {
|
|
|
|
// commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
// name: globalize.translate('QueueAllFromHere'),
|
2019-01-10 15:39:37 +03:00
|
|
|
// id: 'queueallfromhere'
|
|
|
|
// });
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.IsFolder || item.Type === "MusicArtist" || item.Type === "MusicGenre") {
|
|
|
|
if (item.CollectionType !== 'livetv') {
|
|
|
|
if (options.shuffle !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Shuffle'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'shuffle'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.MediaType === "Audio" || item.Type === "MusicAlbum" || item.Type === "MusicArtist" || item.Type === "MusicGenre") {
|
|
|
|
if (options.instantMix !== false && !itemHelper.isLocalItem(item)) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('InstantMix'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'instantmix'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commands.length) {
|
|
|
|
commands.push({
|
|
|
|
divider: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!restrictOptions) {
|
|
|
|
if (itemHelper.supportsAddingToCollection(item)) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('AddToCollection'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'addtocollection'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemHelper.supportsAddingToPlaylist(item)) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('AddToPlaylist'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'addtoplaylist'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((item.Type === 'Timer') && user.Policy.EnableLiveTvManagement && options.cancelTimer !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('CancelRecording'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'canceltimer'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((item.Type === 'Recording' && item.Status === 'InProgress') && user.Policy.EnableLiveTvManagement && options.cancelTimer !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('CancelRecording'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'canceltimer'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((item.Type === 'SeriesTimer') && user.Policy.EnableLiveTvManagement && options.cancelTimer !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('CancelSeries'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'cancelseriestimer'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemHelper.canConvert(item, user, connectionManager.getApiClient(item))) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Convert'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'convert'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.CanDelete && options.deleteItem !== false) {
|
|
|
|
|
|
|
|
if (item.Type === 'Playlist' || item.Type === 'BoxSet') {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Delete'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'delete'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('DeleteMedia'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'delete'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.CanDownload && appHost.supports('filedownload')) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Download'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'download'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appHost.supports('sync') && options.syncLocal !== false) {
|
|
|
|
if (itemHelper.canSync(user, item)) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Download'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'synclocal'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var canEdit = itemHelper.canEdit(user, item);
|
2019-01-10 15:39:37 +03:00
|
|
|
if (canEdit) {
|
|
|
|
|
|
|
|
if (options.edit !== false && item.Type !== 'SeriesTimer') {
|
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
var text = (item.Type === 'Timer' || item.Type === 'SeriesTimer') ? globalize.translate('Edit') : globalize.translate('EditMetadata');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-01-10 15:41:25 +03:00
|
|
|
commands.push({
|
|
|
|
name: text,
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'edit'
|
|
|
|
});
|
|
|
|
}
|
2019-01-10 15:41:25 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (itemHelper.canEditImages(user, item)) {
|
|
|
|
|
|
|
|
if (options.editImages !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('EditImages'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'editimages'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canEdit) {
|
|
|
|
|
|
|
|
if (item.MediaType === 'Video' && item.Type !== 'TvChannel' && item.Type !== 'Program' && item.LocationType !== 'Virtual' && !(item.Type === 'Recording' && item.Status !== 'Completed')) {
|
|
|
|
if (options.editSubtitles !== false) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('EditSubtitles'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'editsubtitles'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.identify !== false) {
|
|
|
|
if (itemHelper.canIdentify(user, item)) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Identify'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'identify'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.Type === 'Program' && options.record !== false) {
|
|
|
|
|
|
|
|
if (item.TimerId) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: Globalize.translate('ManageRecording'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'record'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.Type === 'Program' && options.record !== false) {
|
|
|
|
|
|
|
|
if (!item.TimerId) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: Globalize.translate('Record'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'record'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemHelper.canRefreshMetadata(item, user)) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('RefreshMetadata'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'refresh'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.PlaylistItemId && options.playlistId) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('RemoveFromPlaylist'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'removefromplaylist'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.collectionId) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('RemoveFromCollection'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'removefromcollection'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!restrictOptions) {
|
|
|
|
if (options.share === true) {
|
|
|
|
if (itemHelper.canShare(item, user)) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Share'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'share'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.sync !== false) {
|
|
|
|
if (itemHelper.canSync(user, item)) {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Sync'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'sync'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.openAlbum !== false && item.AlbumId && item.MediaType !== 'Photo') {
|
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: Globalize.translate('ViewAlbum'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'album'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.openArtist !== false && item.ArtistItems && item.ArtistItems.length) {
|
2018-10-23 01:05:09 +03:00
|
|
|
commands.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: Globalize.translate('ViewArtist'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'artist'
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return commands;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getResolveFunction(resolve, id, changed, deleted) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
resolve({
|
|
|
|
command: id,
|
|
|
|
updated: changed,
|
|
|
|
deleted: deleted
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
};
|
2019-01-10 15:41:25 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function executeCommand(item, id, options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var itemId = item.Id;
|
|
|
|
var serverId = item.ServerId;
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
switch (id) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
case 'addtocollection':
|
|
|
|
{
|
|
|
|
require(['collectionEditor'], function (collectionEditor) {
|
|
|
|
|
|
|
|
new collectionEditor().show({
|
2019-01-10 15:41:25 +03:00
|
|
|
items: [itemId],
|
|
|
|
serverId: serverId
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 15:41:25 +03:00
|
|
|
});
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'addtoplaylist':
|
|
|
|
{
|
|
|
|
require(['playlistEditor'], function (playlistEditor) {
|
|
|
|
|
|
|
|
new playlistEditor().show({
|
2019-01-10 15:41:25 +03:00
|
|
|
items: [itemId],
|
|
|
|
serverId: serverId
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 15:41:25 +03:00
|
|
|
});
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'download':
|
|
|
|
{
|
|
|
|
require(['fileDownloader'], function (fileDownloader) {
|
2019-01-10 15:41:25 +03:00
|
|
|
var downloadHref = apiClient.getItemDownloadUrl(itemId);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
fileDownloader.download([
|
|
|
|
{
|
2019-01-10 15:41:25 +03:00
|
|
|
url: downloadHref,
|
|
|
|
itemId: itemId,
|
|
|
|
serverId: serverId
|
2019-01-10 15:39:37 +03:00
|
|
|
}]);
|
|
|
|
|
|
|
|
getResolveFunction(getResolveFunction(resolve, id), id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'editsubtitles':
|
|
|
|
{
|
|
|
|
require(['subtitleEditor'], function (subtitleEditor) {
|
|
|
|
|
|
|
|
subtitleEditor.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 15:41:25 +03:00
|
|
|
});
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'edit':
|
|
|
|
{
|
|
|
|
editItem(apiClient, item).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'editimages':
|
|
|
|
{
|
|
|
|
require(['imageEditor'], function (imageEditor) {
|
|
|
|
|
2019-01-10 15:41:25 +03:00
|
|
|
imageEditor.show({
|
|
|
|
itemId: itemId,
|
|
|
|
serverId: serverId
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 15:41:25 +03:00
|
|
|
});
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'identify':
|
|
|
|
{
|
|
|
|
require(['itemIdentifier'], function (itemIdentifier) {
|
|
|
|
|
|
|
|
itemIdentifier.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 15:41:25 +03:00
|
|
|
});
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'refresh':
|
|
|
|
{
|
|
|
|
refresh(apiClient, item);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'open':
|
|
|
|
{
|
|
|
|
appRouter.showItem(item);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'play':
|
|
|
|
{
|
|
|
|
play(item, false);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'resume':
|
|
|
|
{
|
|
|
|
play(item, true);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'queue':
|
|
|
|
{
|
|
|
|
play(item, false, true);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'queuenext':
|
|
|
|
{
|
|
|
|
play(item, false, true, true);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'record':
|
|
|
|
require(['recordingCreator'], function (recordingCreator) {
|
|
|
|
recordingCreator.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'shuffle':
|
|
|
|
{
|
|
|
|
playbackManager.shuffle(item);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'instantmix':
|
|
|
|
{
|
|
|
|
playbackManager.instantMix(item);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'delete':
|
|
|
|
{
|
|
|
|
deleteItem(apiClient, item).then(getResolveFunction(resolve, id, true, true), getResolveFunction(resolve, id));
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'share':
|
|
|
|
{
|
2019-01-10 15:41:25 +03:00
|
|
|
navigator.share({
|
|
|
|
title: item.Name,
|
|
|
|
text: item.Overview,
|
|
|
|
url: "https://github.com/jellyfin/jellyfin"
|
|
|
|
});
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'album':
|
|
|
|
{
|
|
|
|
appRouter.showItem(item.AlbumId, item.ServerId);
|
|
|
|
getResolveFunction(resolve, id)();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'artist':
|
|
|
|
{
|
|
|
|
appRouter.showItem(item.ArtistItems[0].Id, item.ServerId);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'playallfromhere':
|
|
|
|
{
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'queueallfromhere':
|
|
|
|
{
|
2019-01-10 15:41:25 +03:00
|
|
|
getResolveFunction(resolve, id)();
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'convert':
|
|
|
|
{
|
|
|
|
require(['syncDialog'], function (syncDialog) {
|
2019-01-10 15:41:25 +03:00
|
|
|
syncDialog.showMenu({
|
|
|
|
items: [item],
|
|
|
|
serverId: serverId,
|
2019-01-10 15:39:37 +03:00
|
|
|
mode: 'convert'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'sync':
|
|
|
|
{
|
|
|
|
require(['syncDialog'], function (syncDialog) {
|
2019-01-10 15:41:25 +03:00
|
|
|
syncDialog.showMenu({
|
|
|
|
items: [item],
|
|
|
|
serverId: serverId,
|
2019-01-10 15:39:37 +03:00
|
|
|
mode: 'sync'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'synclocal':
|
|
|
|
{
|
|
|
|
require(['syncDialog'], function (syncDialog) {
|
2019-01-10 15:41:25 +03:00
|
|
|
syncDialog.showMenu({
|
|
|
|
items: [item],
|
|
|
|
serverId: serverId,
|
2019-01-10 15:39:37 +03:00
|
|
|
mode: 'download'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 15:41:25 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
case 'removefromplaylist':
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
apiClient.ajax({
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
url: apiClient.getUrl('Playlists/' + options.playlistId + '/Items', {
|
|
|
|
EntryIds: [item.PlaylistItemId].join(',')
|
2018-10-23 01:05:09 +03:00
|
|
|
}),
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
type: 'DELETE'
|
|
|
|
|
|
|
|
}).then(function () {
|
|
|
|
|
|
|
|
getResolveFunction(resolve, id, true)();
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'removefromcollection':
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
apiClient.ajax({
|
|
|
|
type: "DELETE",
|
|
|
|
url: apiClient.getUrl("Collections/" + options.collectionId + "/Items", {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
Ids: [item.Id].join(',')
|
2018-10-23 01:05:09 +03:00
|
|
|
})
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
}).then(function () {
|
|
|
|
|
|
|
|
getResolveFunction(resolve, id, true)();
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'canceltimer':
|
2018-10-23 01:05:09 +03:00
|
|
|
deleteTimer(apiClient, item, resolve, id);
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'cancelseriestimer':
|
2018-10-23 01:05:09 +03:00
|
|
|
deleteSeriesTimer(apiClient, item, resolve, id);
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-10 15:39:37 +03:00
|
|
|
reject();
|
|
|
|
break;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteTimer(apiClient, item, resolve, command) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
require(['recordingHelper'], function (recordingHelper) {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var timerId = item.TimerId || item.Id;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
recordingHelper.cancelTimerWithConfirmation(timerId, item.ServerId).then(function () {
|
|
|
|
getResolveFunction(resolve, command, true)();
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSeriesTimer(apiClient, item, resolve, command) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
require(['recordingHelper'], function (recordingHelper) {
|
|
|
|
|
|
|
|
recordingHelper.cancelSeriesTimerWithConfirmation(item.Id, item.ServerId).then(function () {
|
|
|
|
getResolveFunction(resolve, command, true)();
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function play(item, resume, queue, queueNext) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var method = queue ? (queueNext ? 'queueNext' : 'queue') : 'play';
|
|
|
|
|
|
|
|
var startPosition = 0;
|
|
|
|
if (resume && item.UserData && item.UserData.PlaybackPositionTicks) {
|
|
|
|
startPosition = item.UserData.PlaybackPositionTicks;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.Type === 'Program') {
|
|
|
|
playbackManager[method]({
|
2019-01-10 15:41:25 +03:00
|
|
|
ids: [item.ChannelId],
|
|
|
|
startPositionTicks: startPosition,
|
|
|
|
serverId: item.ServerId
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
playbackManager[method]({
|
2019-01-10 15:41:25 +03:00
|
|
|
items: [item],
|
|
|
|
startPositionTicks: startPosition
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function editItem(apiClient, item) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var serverId = apiClient.serverInfo().Id;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (item.Type === 'Timer') {
|
|
|
|
require(['recordingEditor'], function (recordingEditor) {
|
|
|
|
|
|
|
|
recordingEditor.show(item.Id, serverId).then(resolve, reject);
|
|
|
|
});
|
|
|
|
} else if (item.Type === 'SeriesTimer') {
|
|
|
|
require(['seriesRecordingEditor'], function (recordingEditor) {
|
|
|
|
|
|
|
|
recordingEditor.show(item.Id, serverId).then(resolve, reject);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
require(['metadataEditor'], function (metadataEditor) {
|
|
|
|
|
|
|
|
metadataEditor.show(item.Id, serverId).then(resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteItem(apiClient, item) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
|
|
|
require(['deleteHelper'], function (deleteHelper) {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
deleteHelper.deleteItem({
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
item: item,
|
2019-01-10 15:39:37 +03:00
|
|
|
navigate: false
|
|
|
|
|
|
|
|
}).then(function () {
|
|
|
|
|
|
|
|
resolve(true);
|
|
|
|
|
|
|
|
}, reject);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function refresh(apiClient, item) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
require(['refreshDialog'], function (refreshDialog) {
|
2018-10-23 01:05:09 +03:00
|
|
|
new refreshDialog({
|
|
|
|
itemIds: [item.Id],
|
|
|
|
serverId: apiClient.serverInfo().Id,
|
2019-01-10 15:39:37 +03:00
|
|
|
mode: item.Type === 'CollectionFolder' ? 'scan' : null
|
|
|
|
}).show();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function show(options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var commands = getCommands(options);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (!commands.length) {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
return actionsheet.show({
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
items: commands,
|
|
|
|
positionTo: options.positionTo,
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
resolveOnClick: ['share']
|
|
|
|
|
|
|
|
}).then(function (id) {
|
|
|
|
return executeCommand(options.item, id, options);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
return {
|
|
|
|
getCommands: getCommands,
|
|
|
|
show: show
|
2019-01-10 15:39:37 +03:00
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|