2020-05-04 03:44:12 -07: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-22 15:05:09 -07:00
|
|
|
|
|
|
|
function getCommands(options) {
|
2019-01-10 05:39:37 -07:00
|
|
|
var item = options.item;
|
2019-12-07 02:20:32 -07:00
|
|
|
var user = options.user;
|
|
|
|
|
2019-01-10 05:39:37 -07:00
|
|
|
var canPlay = playbackManager.canPlay(item);
|
2019-08-19 02:35:57 -07:00
|
|
|
var restrictOptions = (browser.operaTv || browser.web0s) && !user.Policy.IsAdministrator;
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2019-08-19 02:35:57 -07:00
|
|
|
var commands = [];
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (canPlay && item.MediaType !== 'Photo') {
|
2019-01-10 05:39:37 -07:00
|
|
|
if (options.play !== false) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('Play'),
|
|
|
|
id: 'resume',
|
|
|
|
icon: 'play_arrow'
|
2019-08-19 02:35:57 -07:00
|
|
|
});
|
2019-01-10 05:39:37 -07:00
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (options.playAllFromHere && item.Type !== 'Program' && item.Type !== 'TvChannel') {
|
2019-01-10 05:39:37 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('PlayAllFromHere'),
|
|
|
|
id: 'playallfromhere',
|
|
|
|
icon: 'play_arrow'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playbackManager.canQueue(item)) {
|
|
|
|
if (options.queue !== false) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('AddToPlayQueue'),
|
|
|
|
id: 'queue',
|
|
|
|
icon: 'playlist_add'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.queue !== false) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('PlayNext'),
|
|
|
|
id: 'queuenext',
|
|
|
|
icon: 'playlist_add'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (options.queueAllFromHere) {
|
|
|
|
// commands.push({
|
2019-10-15 11:13:33 -07:00
|
|
|
// name: globalize.translate("QueueAllFromHere"),
|
|
|
|
// id: "queueallfromhere"
|
2019-01-10 05:39:37 -07:00
|
|
|
// });
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (item.IsFolder || item.Type === 'MusicArtist' || item.Type === 'MusicGenre') {
|
|
|
|
if (item.CollectionType !== 'livetv') {
|
2019-01-10 05:39:37 -07:00
|
|
|
if (options.shuffle !== false) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('Shuffle'),
|
|
|
|
id: 'shuffle',
|
|
|
|
icon: 'shuffle'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (item.MediaType === 'Audio' || item.Type === 'MusicAlbum' || item.Type === 'MusicArtist' || item.Type === 'MusicGenre') {
|
2019-01-10 05:39:37 -07:00
|
|
|
if (options.instantMix !== false && !itemHelper.isLocalItem(item)) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('InstantMix'),
|
|
|
|
id: 'instantmix',
|
|
|
|
icon: 'explore'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commands.length) {
|
|
|
|
commands.push({
|
|
|
|
divider: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!restrictOptions) {
|
|
|
|
if (itemHelper.supportsAddingToCollection(item)) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('AddToCollection'),
|
|
|
|
id: 'addtocollection',
|
|
|
|
icon: 'playlist_add'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-10 09:17:57 -07:00
|
|
|
if (itemHelper.supportsAddingToPlaylist(item) && options.playlist !== false) {
|
2019-01-10 05:39:37 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('AddToPlaylist'),
|
|
|
|
id: 'addtoplaylist',
|
|
|
|
icon: 'playlist_add'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if ((item.Type === 'Timer') && user.Policy.EnableLiveTvManagement && options.cancelTimer !== false) {
|
2019-01-10 05:39:37 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('CancelRecording'),
|
|
|
|
id: 'canceltimer',
|
|
|
|
icon: 'cancel'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if ((item.Type === 'Recording' && item.Status === 'InProgress') && user.Policy.EnableLiveTvManagement && options.cancelTimer !== false) {
|
2019-01-10 05:39:37 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('CancelRecording'),
|
|
|
|
id: 'canceltimer',
|
|
|
|
icon: 'cancel'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if ((item.Type === 'SeriesTimer') && user.Policy.EnableLiveTvManagement && options.cancelTimer !== false) {
|
2019-01-10 05:39:37 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('CancelSeries'),
|
|
|
|
id: 'cancelseriestimer',
|
|
|
|
icon: 'cancel'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.CanDelete && options.deleteItem !== false) {
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (item.Type === 'Playlist' || item.Type === 'BoxSet') {
|
2019-01-10 05:39:37 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('Delete'),
|
|
|
|
id: 'delete',
|
|
|
|
icon: 'delete'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('DeleteMedia'),
|
|
|
|
id: 'delete',
|
|
|
|
icon: 'delete'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-28 06:51:02 -07:00
|
|
|
// Books are promoted to major download Button and therefor excluded in the context menu
|
2020-05-04 03:44:12 -07:00
|
|
|
if ((item.CanDownload && appHost.supports('filedownload')) && item.Type !== 'Book') {
|
2019-01-10 05:39:37 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('Download'),
|
|
|
|
id: 'download',
|
|
|
|
icon: 'file_download'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
2019-08-27 02:32:35 -07:00
|
|
|
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('CopyStreamURL'),
|
|
|
|
id: 'copy-stream',
|
|
|
|
icon: 'content_copy'
|
2019-10-12 11:32:05 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commands.length) {
|
|
|
|
commands.push({
|
|
|
|
divider: true
|
2019-08-27 02:32:35 -07:00
|
|
|
});
|
2019-01-10 05:39:37 -07:00
|
|
|
}
|
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
var canEdit = itemHelper.canEdit(user, item);
|
2019-01-10 05:39:37 -07:00
|
|
|
if (canEdit) {
|
2020-05-04 03:44:12 -07:00
|
|
|
if (options.edit !== false && item.Type !== 'SeriesTimer') {
|
|
|
|
var text = (item.Type === 'Timer' || item.Type === 'SeriesTimer') ? globalize.translate('Edit') : globalize.translate('EditMetadata');
|
2019-08-19 02:35:57 -07:00
|
|
|
commands.push({
|
|
|
|
name: text,
|
2020-05-04 03:44:12 -07:00
|
|
|
id: 'edit',
|
|
|
|
icon: 'edit'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
2019-08-19 02:35:57 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (itemHelper.canEditImages(user, item)) {
|
|
|
|
if (options.editImages !== false) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('EditImages'),
|
|
|
|
id: 'editimages',
|
|
|
|
icon: 'image'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canEdit) {
|
2020-05-04 03:44:12 -07:00
|
|
|
if (item.MediaType === 'Video' && item.Type !== 'TvChannel' && item.Type !== 'Program' && item.LocationType !== 'Virtual' && !(item.Type === 'Recording' && item.Status !== 'Completed')) {
|
2019-01-10 05:39:37 -07:00
|
|
|
if (options.editSubtitles !== false) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('EditSubtitles'),
|
|
|
|
id: 'editsubtitles',
|
|
|
|
icon: 'closed_caption'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.identify !== false) {
|
|
|
|
if (itemHelper.canIdentify(user, item)) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('Identify'),
|
|
|
|
id: 'identify',
|
|
|
|
icon: 'edit'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 02:35:57 -07:00
|
|
|
if (item.MediaSources) {
|
|
|
|
if (options.moremediainfo !== false) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('MoreMediaInfo'),
|
|
|
|
id: 'moremediainfo',
|
|
|
|
icon: 'info'
|
2019-08-19 02:35:57 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (item.Type === 'Program' && options.record !== false) {
|
2019-01-10 05:39:37 -07:00
|
|
|
if (item.TimerId) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('ManageRecording'),
|
|
|
|
id: 'record',
|
|
|
|
icon: 'fiber_manual_record'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (item.Type === 'Program' && options.record !== false) {
|
2019-01-10 05:39:37 -07:00
|
|
|
if (!item.TimerId) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('Record'),
|
|
|
|
id: 'record',
|
|
|
|
icon: 'fiber_manual_record'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemHelper.canRefreshMetadata(item, user)) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('RefreshMetadata'),
|
|
|
|
id: 'refresh',
|
|
|
|
icon: 'refresh'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.PlaylistItemId && options.playlistId) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('RemoveFromPlaylist'),
|
|
|
|
id: 'removefromplaylist',
|
|
|
|
icon: 'remove'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.collectionId) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('RemoveFromCollection'),
|
|
|
|
id: 'removefromcollection',
|
|
|
|
icon: 'remove'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!restrictOptions) {
|
|
|
|
if (options.share === true) {
|
|
|
|
if (itemHelper.canShare(item, user)) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('Share'),
|
|
|
|
id: 'share',
|
|
|
|
icon: 'share'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.sync !== false) {
|
|
|
|
if (itemHelper.canSync(user, item)) {
|
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('Sync'),
|
|
|
|
id: 'sync',
|
|
|
|
icon: 'sync'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (options.openAlbum !== false && item.AlbumId && item.MediaType !== 'Photo') {
|
2019-01-10 05:39:37 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('ViewAlbum'),
|
|
|
|
id: 'album',
|
|
|
|
icon: 'album'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.openArtist !== false && item.ArtistItems && item.ArtistItems.length) {
|
2018-10-22 15:05:09 -07:00
|
|
|
commands.push({
|
2020-05-04 03:44:12 -07:00
|
|
|
name: globalize.translate('ViewArtist'),
|
|
|
|
id: 'artist',
|
|
|
|
icon: 'person'
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
|
|
|
|
return commands;
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function getResolveFunction(resolve, id, changed, deleted) {
|
2019-01-10 05:39:37 -07:00
|
|
|
return function () {
|
2018-10-22 15:05:09 -07:00
|
|
|
resolve({
|
|
|
|
command: id,
|
|
|
|
updated: changed,
|
|
|
|
deleted: deleted
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
};
|
2019-08-19 02:35:57 -07:00
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
|
|
|
|
function executeCommand(item, id, options) {
|
2019-01-10 05:39:37 -07:00
|
|
|
var itemId = item.Id;
|
|
|
|
var serverId = item.ServerId;
|
|
|
|
var apiClient = connectionManager.getApiClient(serverId);
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
2018-10-22 15:05:09 -07:00
|
|
|
switch (id) {
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'addtocollection':
|
|
|
|
require(['collectionEditor'], function (collectionEditor) {
|
2019-08-19 02:35:57 -07:00
|
|
|
new collectionEditor().show({
|
2019-01-10 05:41:25 -07:00
|
|
|
items: [itemId],
|
|
|
|
serverId: serverId
|
2019-08-19 02:35:57 -07:00
|
|
|
}).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 05:41:25 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'addtoplaylist':
|
|
|
|
require(['playlistEditor'], function (playlistEditor) {
|
2019-08-19 02:35:57 -07:00
|
|
|
new playlistEditor().show({
|
2019-01-10 05:41:25 -07:00
|
|
|
items: [itemId],
|
|
|
|
serverId: serverId
|
2019-08-19 02:35:57 -07:00
|
|
|
}).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 05:41:25 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'download':
|
|
|
|
require(['fileDownloader'], function (fileDownloader) {
|
2019-01-10 05:41:25 -07:00
|
|
|
var downloadHref = apiClient.getItemDownloadUrl(itemId);
|
2019-08-19 02:35:57 -07:00
|
|
|
fileDownloader.download([{
|
|
|
|
url: downloadHref,
|
|
|
|
itemId: itemId,
|
2020-04-12 07:53:30 -07:00
|
|
|
serverId: serverId,
|
|
|
|
title: item.Name,
|
|
|
|
filename: item.Path.replace(/^.*[\\\/]/, '')
|
2019-08-19 02:35:57 -07:00
|
|
|
}]);
|
|
|
|
getResolveFunction(getResolveFunction(resolve, id), id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'copy-stream':
|
2019-08-27 02:32:35 -07:00
|
|
|
var downloadHref = apiClient.getItemDownloadUrl(itemId);
|
2020-03-12 01:12:01 -07:00
|
|
|
var textAreaCopy = function () {
|
2020-05-04 03:44:12 -07:00
|
|
|
var textArea = document.createElement('textarea');
|
2020-02-02 06:13:43 -07:00
|
|
|
textArea.value = downloadHref;
|
|
|
|
document.body.appendChild(textArea);
|
|
|
|
textArea.focus();
|
|
|
|
textArea.select();
|
2020-04-04 12:29:53 -07:00
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (document.execCommand('copy')) {
|
|
|
|
require(['toast'], function (toast) {
|
|
|
|
toast(globalize.translate('CopyStreamURLSuccess'));
|
2020-02-02 06:13:43 -07:00
|
|
|
});
|
|
|
|
} else {
|
2020-05-04 03:44:12 -07:00
|
|
|
prompt(globalize.translate('CopyStreamURL'), downloadHref);
|
2020-02-02 06:13:43 -07:00
|
|
|
}
|
|
|
|
document.body.removeChild(textArea);
|
2020-03-12 00:50:18 -07:00
|
|
|
};
|
2020-04-04 12:29:53 -07:00
|
|
|
|
|
|
|
/* eslint-disable-next-line compat/compat */
|
2020-03-12 00:50:18 -07:00
|
|
|
if (navigator.clipboard === undefined) {
|
2020-03-12 01:22:04 -07:00
|
|
|
textAreaCopy();
|
2020-03-12 00:50:18 -07:00
|
|
|
} else {
|
2020-04-04 12:29:53 -07:00
|
|
|
/* eslint-disable-next-line compat/compat */
|
2020-03-12 00:50:18 -07:00
|
|
|
navigator.clipboard.writeText(downloadHref).then(function () {
|
2020-05-04 03:44:12 -07:00
|
|
|
require(['toast'], function (toast) {
|
|
|
|
toast(globalize.translate('CopyStreamURLSuccess'));
|
2020-03-12 00:50:18 -07:00
|
|
|
});
|
2020-04-04 12:29:53 -07:00
|
|
|
}).catch(function () {
|
|
|
|
textAreaCopy();
|
|
|
|
});
|
2020-03-12 00:50:18 -07:00
|
|
|
}
|
2019-08-27 02:32:35 -07:00
|
|
|
getResolveFunction(resolve, id)();
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'editsubtitles':
|
|
|
|
require(['subtitleEditor'], function (subtitleEditor) {
|
2019-08-19 02:35:57 -07:00
|
|
|
subtitleEditor.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 05:41:25 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'edit':
|
2019-08-19 02:35:57 -07:00
|
|
|
editItem(apiClient, item).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'editimages':
|
|
|
|
require(['imageEditor'], function (imageEditor) {
|
2019-01-10 05:41:25 -07:00
|
|
|
imageEditor.show({
|
|
|
|
itemId: itemId,
|
|
|
|
serverId: serverId
|
2019-08-19 02:35:57 -07:00
|
|
|
}).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2019-01-10 05:41:25 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'identify':
|
|
|
|
require(['itemIdentifier'], function (itemIdentifier) {
|
2019-08-19 02:35:57 -07:00
|
|
|
itemIdentifier.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'moremediainfo':
|
|
|
|
require(['itemMediaInfo'], function (itemMediaInfo) {
|
2020-06-19 05:45:29 -07:00
|
|
|
itemMediaInfo.show(itemId, serverId).then(getResolveFunction(resolve, id), getResolveFunction(resolve, id));
|
2019-01-10 05:41:25 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'refresh':
|
2019-08-19 02:35:57 -07:00
|
|
|
refresh(apiClient, item);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'open':
|
2019-08-19 02:35:57 -07:00
|
|
|
appRouter.showItem(item);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'play':
|
2019-08-19 02:35:57 -07:00
|
|
|
play(item, false);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'resume':
|
2019-08-19 02:35:57 -07:00
|
|
|
play(item, true);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'queue':
|
2019-08-19 02:35:57 -07:00
|
|
|
play(item, false, true);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'queuenext':
|
2019-08-19 02:35:57 -07:00
|
|
|
play(item, false, true, true);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'record':
|
|
|
|
require(['recordingCreator'], function (recordingCreator) {
|
2019-01-10 05:39:37 -07:00
|
|
|
recordingCreator.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
|
2018-10-22 15:05:09 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'shuffle':
|
2019-08-19 02:35:57 -07:00
|
|
|
playbackManager.shuffle(item);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'instantmix':
|
2019-08-19 02:35:57 -07:00
|
|
|
playbackManager.instantMix(item);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'delete':
|
2019-08-19 02:35:57 -07:00
|
|
|
deleteItem(apiClient, item).then(getResolveFunction(resolve, id, true, true), getResolveFunction(resolve, id));
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'share':
|
2019-01-10 05:41:25 -07:00
|
|
|
navigator.share({
|
|
|
|
title: item.Name,
|
|
|
|
text: item.Overview,
|
2020-05-20 14:03:01 -07:00
|
|
|
url: `${apiClient.serverAddress()}/web/index.html#!/${appRouter.getRouteUrl(item)}`
|
2019-01-10 05:41:25 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'album':
|
2019-03-18 22:22:48 -07:00
|
|
|
appRouter.showItem(item.AlbumId, item.ServerId);
|
|
|
|
getResolveFunction(resolve, id)();
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'artist':
|
2019-03-18 22:22:48 -07:00
|
|
|
appRouter.showItem(item.ArtistItems[0].Id, item.ServerId);
|
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'playallfromhere':
|
2019-03-18 22:22:48 -07:00
|
|
|
getResolveFunction(resolve, id)();
|
2019-01-10 05:41:25 -07:00
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'queueallfromhere':
|
2019-01-10 05:41:25 -07:00
|
|
|
getResolveFunction(resolve, id)();
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'removefromplaylist':
|
2018-10-22 15:05:09 -07:00
|
|
|
apiClient.ajax({
|
2020-05-04 03:44:12 -07:00
|
|
|
url: apiClient.getUrl('Playlists/' + options.playlistId + '/Items', {
|
|
|
|
EntryIds: [item.PlaylistItemId].join(',')
|
2018-10-22 15:05:09 -07:00
|
|
|
}),
|
2020-05-04 03:44:12 -07:00
|
|
|
type: 'DELETE'
|
2019-01-10 05:39:37 -07:00
|
|
|
}).then(function () {
|
|
|
|
getResolveFunction(resolve, id, true)();
|
2018-10-22 15:05:09 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'removefromcollection':
|
2018-10-22 15:05:09 -07:00
|
|
|
apiClient.ajax({
|
2020-05-04 03:44:12 -07:00
|
|
|
type: 'DELETE',
|
|
|
|
url: apiClient.getUrl('Collections/' + options.collectionId + '/Items', {
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
Ids: [item.Id].join(',')
|
2018-10-22 15:05:09 -07:00
|
|
|
})
|
2019-01-10 05:39:37 -07:00
|
|
|
}).then(function () {
|
|
|
|
getResolveFunction(resolve, id, true)();
|
2018-10-22 15:05:09 -07:00
|
|
|
});
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'canceltimer':
|
2018-10-22 15:05:09 -07:00
|
|
|
deleteTimer(apiClient, item, resolve, id);
|
|
|
|
break;
|
2020-05-04 03:44:12 -07:00
|
|
|
case 'cancelseriestimer':
|
2018-10-22 15:05:09 -07:00
|
|
|
deleteSeriesTimer(apiClient, item, resolve, id);
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-10 05:39:37 -07:00
|
|
|
reject();
|
|
|
|
break;
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteTimer(apiClient, item, resolve, command) {
|
2020-05-04 03:44:12 -07:00
|
|
|
require(['recordingHelper'], function (recordingHelper) {
|
2018-10-22 15:05:09 -07:00
|
|
|
var timerId = item.TimerId || item.Id;
|
2019-01-10 05:39:37 -07:00
|
|
|
recordingHelper.cancelTimerWithConfirmation(timerId, item.ServerId).then(function () {
|
|
|
|
getResolveFunction(resolve, command, true)();
|
|
|
|
});
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSeriesTimer(apiClient, item, resolve, command) {
|
2020-05-04 03:44:12 -07:00
|
|
|
require(['recordingHelper'], function (recordingHelper) {
|
2019-01-10 05:39:37 -07:00
|
|
|
recordingHelper.cancelSeriesTimerWithConfirmation(item.Id, item.ServerId).then(function () {
|
|
|
|
getResolveFunction(resolve, command, true)();
|
|
|
|
});
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function play(item, resume, queue, queueNext) {
|
2020-05-04 03:44:12 -07:00
|
|
|
var method = queue ? (queueNext ? 'queueNext' : 'queue') : 'play';
|
2019-01-10 05:39:37 -07:00
|
|
|
|
|
|
|
var startPosition = 0;
|
|
|
|
if (resume && item.UserData && item.UserData.PlaybackPositionTicks) {
|
|
|
|
startPosition = item.UserData.PlaybackPositionTicks;
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (item.Type === 'Program') {
|
2019-01-10 05:39:37 -07:00
|
|
|
playbackManager[method]({
|
2019-08-19 02:35:57 -07:00
|
|
|
ids: [item.ChannelId],
|
|
|
|
startPositionTicks: startPosition,
|
|
|
|
serverId: item.ServerId
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
playbackManager[method]({
|
2019-08-19 02:35:57 -07:00
|
|
|
items: [item],
|
|
|
|
startPositionTicks: startPosition
|
2019-01-10 05:39:37 -07:00
|
|
|
});
|
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function editItem(apiClient, item) {
|
2019-01-10 05:39:37 -07:00
|
|
|
return new Promise(function (resolve, reject) {
|
2018-10-22 15:05:09 -07:00
|
|
|
var serverId = apiClient.serverInfo().Id;
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2020-05-04 03:44:12 -07:00
|
|
|
if (item.Type === 'Timer') {
|
|
|
|
require(['recordingEditor'], function (recordingEditor) {
|
2019-01-10 05:39:37 -07:00
|
|
|
recordingEditor.show(item.Id, serverId).then(resolve, reject);
|
|
|
|
});
|
2020-05-04 03:44:12 -07:00
|
|
|
} else if (item.Type === 'SeriesTimer') {
|
|
|
|
require(['seriesRecordingEditor'], function (recordingEditor) {
|
2019-01-10 05:39:37 -07:00
|
|
|
recordingEditor.show(item.Id, serverId).then(resolve, reject);
|
|
|
|
});
|
|
|
|
} else {
|
2020-05-04 03:44:12 -07:00
|
|
|
require(['metadataEditor'], function (metadataEditor) {
|
2019-01-10 05:39:37 -07:00
|
|
|
metadataEditor.show(item.Id, serverId).then(resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteItem(apiClient, item) {
|
2019-01-10 05:39:37 -07:00
|
|
|
return new Promise(function (resolve, reject) {
|
2020-05-04 03:44:12 -07:00
|
|
|
require(['deleteHelper'], function (deleteHelper) {
|
2018-10-22 15:05:09 -07:00
|
|
|
deleteHelper.deleteItem({
|
|
|
|
item: item,
|
2019-01-10 05:39:37 -07:00
|
|
|
navigate: false
|
|
|
|
}).then(function () {
|
|
|
|
resolve(true);
|
|
|
|
}, reject);
|
|
|
|
});
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function refresh(apiClient, item) {
|
2020-05-04 03:44:12 -07:00
|
|
|
require(['refreshDialog'], function (refreshDialog) {
|
2018-10-22 15:05:09 -07:00
|
|
|
new refreshDialog({
|
|
|
|
itemIds: [item.Id],
|
|
|
|
serverId: apiClient.serverInfo().Id,
|
2020-05-04 03:44:12 -07:00
|
|
|
mode: item.Type === 'CollectionFolder' ? 'scan' : null
|
2019-01-10 05:39:37 -07:00
|
|
|
}).show();
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function show(options) {
|
|
|
|
var commands = getCommands(options);
|
2019-01-10 05:39:37 -07:00
|
|
|
if (!commands.length) {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
return actionsheet.show({
|
2018-10-22 15:05:09 -07:00
|
|
|
items: commands,
|
|
|
|
positionTo: options.positionTo,
|
2020-05-04 03:44:12 -07:00
|
|
|
resolveOnClick: ['share']
|
2019-01-10 05:39:37 -07:00
|
|
|
}).then(function (id) {
|
|
|
|
return executeCommand(options.item, id, options);
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-01-10 05:39:37 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
return {
|
|
|
|
getCommands: getCommands,
|
|
|
|
show: show
|
2019-01-10 05:39:37 -07:00
|
|
|
};
|
2019-08-19 02:35:57 -07:00
|
|
|
});
|