jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/itemcontextmenu.js

611 lines
21 KiB
JavaScript
Raw Normal View History

2016-07-21 13:25:55 -07:00
define(['apphost', 'globalize', 'connectionManager', 'itemHelper', 'embyRouter', 'playbackManager', 'loading', 'appSettings'], function (appHost, globalize, connectionManager, itemHelper, embyRouter, playbackManager, loading, appSettings) {
2016-05-13 11:28:05 -07:00
2016-07-21 13:25:55 -07:00
var isMobileApp = window.Dashboard != null;
2016-07-16 18:58:51 -07:00
2016-05-13 11:28:05 -07:00
function getCommands(options) {
var item = options.item;
var serverId = item.ServerId;
var apiClient = connectionManager.getApiClient(serverId);
2016-07-17 09:59:14 -07:00
var canPlay = playbackManager.canPlay(item);
2016-05-13 11:28:05 -07:00
return apiClient.getCurrentUser().then(function (user) {
var commands = [];
2016-05-21 23:08:44 -07:00
if (itemHelper.supportsAddingToCollection(item)) {
commands.push({
name: globalize.translate('sharedcomponents#AddToCollection'),
id: 'addtocollection'
});
}
if (itemHelper.supportsAddingToPlaylist(item)) {
commands.push({
name: globalize.translate('sharedcomponents#AddToPlaylist'),
id: 'addtoplaylist'
});
}
2016-05-21 21:17:28 -07:00
2016-07-19 12:51:22 -07:00
if (item.Type == 'Timer' && user.Policy.EnableLiveTvManagement) {
commands.push({
name: globalize.translate('sharedcomponents#ButtonCancel'),
id: 'canceltimer'
});
}
2016-05-19 07:37:59 -07:00
if (item.CanDelete) {
commands.push({
name: globalize.translate('sharedcomponents#Delete'),
id: 'delete'
});
}
2016-07-17 11:55:07 -07:00
if (itemHelper.canEdit(user, item.Type)) {
2016-07-16 18:58:51 -07:00
2016-07-24 11:25:32 -07:00
if (options.edit !== false) {
2016-07-24 11:25:32 -07:00
var text = item.Type == 'Timer' ? globalize.translate('sharedcomponents#Edit') : globalize.translate('sharedcomponents#EditInfo');
2016-07-24 11:25:32 -07:00
commands.push({
name: text,
id: 'edit'
});
}
}
if (itemHelper.canEditImages(user, item.Type)) {
2016-07-21 13:25:55 -07:00
if (isMobileApp) {
2016-07-17 11:55:07 -07:00
if (options.editImages !== false) {
2016-07-16 18:58:51 -07:00
commands.push({
name: globalize.translate('sharedcomponents#EditImages'),
id: 'editimages'
});
}
2016-07-17 11:55:07 -07:00
}
}
if (itemHelper.canEdit(user, item.Type)) {
2016-07-17 11:55:07 -07:00
if (item.MediaType == 'Video' && item.Type != 'TvChannel' && item.Type != 'Program' && item.LocationType != 'Virtual') {
if (options.editSubtitles !== false) {
2016-07-16 18:58:51 -07:00
commands.push({
name: globalize.translate('sharedcomponents#EditSubtitles'),
id: 'editsubtitles'
});
}
2016-05-31 08:29:00 -07:00
}
}
2016-05-19 07:37:59 -07:00
if (item.CanDownload && appHost.supports('filedownload')) {
2016-05-13 11:28:05 -07:00
commands.push({
name: globalize.translate('sharedcomponents#Download'),
id: 'download'
});
}
2016-07-30 21:11:23 -07:00
if (options.identify !== false) {
2016-07-16 18:58:51 -07:00
if (itemHelper.canIdentify(user, item.Type)) {
commands.push({
name: globalize.translate('sharedcomponents#Identify'),
id: 'identify'
});
}
}
2016-07-16 16:08:21 -07:00
if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist" || item.Type == "MusicGenre" || item.CollectionType == "music") {
if (options.instantMix !== false) {
commands.push({
name: globalize.translate('sharedcomponents#InstantMix'),
id: 'instantmix'
});
}
}
if (appHost.supports('sync') && options.syncLocal !== false) {
if (itemHelper.canSync(user, item)) {
commands.push({
name: globalize.translate('sharedcomponents#MakeAvailableOffline'),
id: 'synclocal'
});
}
}
2016-08-11 13:28:49 -07:00
//if (options.open !== false) {
// if (item.Type != 'Timer' && item.Type != 'Audio') {
// commands.push({
// name: globalize.translate('sharedcomponents#Open'),
// id: 'open'
// });
// }
//}
2016-07-16 15:26:21 -07:00
2016-07-17 09:59:14 -07:00
if (canPlay) {
if (options.play !== false) {
2016-07-16 16:08:21 -07:00
commands.push({
2016-07-17 09:59:14 -07:00
name: globalize.translate('sharedcomponents#Play'),
id: 'resume'
2016-07-16 16:08:21 -07:00
});
2016-07-21 13:25:55 -07:00
if (isMobileApp && appSettings.enableExternalPlayers()) {
commands.push({
name: globalize.translate('ButtonPlayExternalPlayer'),
id: 'externalplayer'
});
}
2016-07-16 16:08:21 -07:00
}
2016-07-18 10:13:29 -07:00
if (options.playAllFromHere && item.Type != 'Program' && item.Type != 'TvChannel') {
2016-07-16 16:08:21 -07:00
commands.push({
2016-07-17 09:59:14 -07:00
name: globalize.translate('sharedcomponents#PlayAllFromHere'),
id: 'playallfromhere'
2016-07-16 16:08:21 -07:00
});
}
2016-07-17 09:59:14 -07:00
2016-08-06 19:11:39 -07:00
if (playbackManager.canQueue(item)) {
2016-07-17 09:59:14 -07:00
if (options.queue !== false) {
commands.push({
name: globalize.translate('sharedcomponents#Queue'),
id: 'queue'
});
}
if (options.queueAllFromHere) {
commands.push({
name: globalize.translate('sharedcomponents#QueueAllFromHere'),
id: 'queueallfromhere'
});
}
}
2016-07-16 16:08:21 -07:00
}
2016-07-16 21:20:36 -07:00
if (item.Type == 'Program' && (!item.TimerId && !item.SeriesTimerId)) {
2016-05-14 11:02:06 -07:00
commands.push({
2016-07-16 21:20:36 -07:00
name: Globalize.translate('sharedcomponents#Record'),
id: 'record'
2016-05-14 11:02:06 -07:00
});
}
2016-07-16 21:20:36 -07:00
if (user.Policy.IsAdministrator) {
2016-07-18 22:09:14 -07:00
if (item.Type != 'Timer' && item.Type != 'Program') {
2016-07-16 21:20:36 -07:00
commands.push({
name: globalize.translate('sharedcomponents#Refresh'),
id: 'refresh'
});
}
}
2016-07-17 09:59:14 -07:00
if (item.PlaylistItemId && options.playlistId) {
commands.push({
name: globalize.translate('sharedcomponents#RemoveFromPlaylist'),
id: 'removefromplaylist'
});
}
if (options.collectionId) {
commands.push({
name: globalize.translate('sharedcomponents#RemoveFromCollection'),
id: 'removefromcollection'
});
}
2016-07-16 21:20:36 -07:00
if (options.share !== false) {
if (itemHelper.canShare(user, item)) {
commands.push({
name: globalize.translate('sharedcomponents#Share'),
id: 'share'
});
}
2016-05-13 11:28:05 -07:00
}
2016-07-16 16:08:21 -07:00
if (item.IsFolder || item.Type == "MusicArtist" || item.Type == "MusicGenre") {
if (options.shuffle !== false) {
commands.push({
name: globalize.translate('sharedcomponents#Shuffle'),
id: 'shuffle'
});
}
}
2016-07-21 13:25:55 -07:00
if (isMobileApp && options.sync !== false) {
2016-07-16 18:58:51 -07:00
if (itemHelper.canSync(user, item)) {
commands.push({
2016-08-12 08:54:37 -07:00
name: globalize.translate('sharedcomponents#SyncToOtherDevice'),
2016-07-16 18:58:51 -07:00
id: 'sync'
});
}
}
2016-07-16 15:26:21 -07:00
if (options.openAlbum !== false && item.AlbumId) {
commands.push({
2016-07-16 16:08:21 -07:00
name: Globalize.translate('sharedcomponents#ViewAlbum'),
2016-07-16 15:26:21 -07:00
id: 'album'
});
}
if (options.openArtist !== false && item.ArtistItems && item.ArtistItems.length) {
commands.push({
2016-07-16 16:08:21 -07:00
name: Globalize.translate('sharedcomponents#ViewArtist'),
2016-07-16 15:26:21 -07:00
id: 'artist'
});
}
2016-05-13 11:28:05 -07:00
return commands;
});
}
2016-07-16 16:08:21 -07:00
function getResolveFunction(resolve, id, changed, deleted) {
return function () {
resolve({
command: id,
updated: changed,
deleted: deleted
});
};
}
2016-07-17 09:59:14 -07:00
function executeCommand(item, id, options) {
2016-05-13 11:28:05 -07:00
var itemId = item.Id;
var serverId = item.ServerId;
var apiClient = connectionManager.getApiClient(serverId);
return new Promise(function (resolve, reject) {
switch (id) {
2016-05-21 21:17:28 -07:00
case 'addtocollection':
{
require(['collectionEditor'], function (collectionEditor) {
new collectionEditor().show({
items: [itemId],
serverId: serverId
2016-07-16 16:08:21 -07:00
}).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
2016-05-21 21:17:28 -07:00
});
break;
}
2016-05-21 23:08:44 -07:00
case 'addtoplaylist':
{
require(['playlistEditor'], function (playlistEditor) {
new playlistEditor().show({
items: [itemId],
serverId: serverId
2016-07-16 16:08:21 -07:00
}).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
2016-05-21 23:08:44 -07:00
});
break;
}
2016-05-13 11:28:05 -07:00
case 'download':
{
require(['fileDownloader'], function (fileDownloader) {
var downloadHref = apiClient.getUrl("Items/" + itemId + "/Download", {
api_key: apiClient.accessToken()
});
fileDownloader.download([
{
url: downloadHref,
itemId: itemId,
serverId: serverId
}]);
2016-07-16 16:08:21 -07:00
getResolveFunction(getResolveFunction(resolve, id), id)();
2016-05-13 11:28:05 -07:00
});
2016-05-31 08:29:00 -07:00
break;
}
case 'editsubtitles':
{
require(['subtitleEditor'], function (subtitleEditor) {
2016-07-16 16:08:21 -07:00
subtitleEditor.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
2016-05-31 08:29:00 -07:00
});
2016-05-14 11:02:06 -07:00
break;
}
2016-07-16 18:58:51 -07:00
case 'edit':
{
2016-07-16 21:20:36 -07:00
editItem(apiClient, item).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
2016-07-16 18:58:51 -07:00
break;
}
case 'editimages':
{
require(['components/imageeditor/imageeditor'], function (ImageEditor) {
ImageEditor.show(itemId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
});
break;
}
case 'identify':
{
2016-07-30 21:11:23 -07:00
require(['itemIdentifier'], function (itemIdentifier) {
2016-07-16 18:58:51 -07:00
2016-07-30 21:11:23 -07:00
itemIdentifier.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
2016-07-16 18:58:51 -07:00
});
break;
}
2016-05-14 11:02:06 -07:00
case 'refresh':
{
refresh(apiClient, itemId);
2016-07-16 16:08:21 -07:00
getResolveFunction(resolve, id)();
2016-05-19 07:37:59 -07:00
break;
}
2016-07-16 15:26:21 -07:00
case 'open':
{
embyRouter.showItem(item);
2016-07-16 16:08:21 -07:00
getResolveFunction(resolve, id)();
2016-07-16 15:26:21 -07:00
break;
}
2016-07-16 16:08:21 -07:00
case 'play':
{
2016-07-16 21:20:36 -07:00
play(item, false);
2016-07-16 16:08:21 -07:00
getResolveFunction(resolve, id)();
break;
}
case 'resume':
2016-05-19 07:37:59 -07:00
{
2016-07-16 21:20:36 -07:00
play(item, true);
2016-07-16 16:08:21 -07:00
getResolveFunction(resolve, id)();
break;
}
case 'queue':
{
2016-07-16 21:20:36 -07:00
play(item, false, true);
2016-07-16 16:08:21 -07:00
getResolveFunction(resolve, id)();
break;
}
2016-07-16 21:20:36 -07:00
case 'record':
require(['recordingCreator'], function (recordingCreator) {
recordingCreator.show(itemId, serverId).then(getResolveFunction(resolve, id, true), getResolveFunction(resolve, id));
});
break;
2016-07-16 16:08:21 -07:00
case 'shuffle':
{
playbackManager.shuffle(item);
getResolveFunction(resolve, id)();
break;
}
case 'instantmix':
{
playbackManager.instantMix(item);
getResolveFunction(resolve, id)();
break;
}
case 'delete':
{
deleteItem(apiClient, itemId).then(getResolveFunction(resolve, id, true, true), getResolveFunction(resolve, id));
2016-05-13 11:28:05 -07:00
break;
}
case 'share':
{
require(['sharingmanager'], function (sharingManager) {
sharingManager.showMenu({
serverId: serverId,
itemId: itemId
2016-07-16 16:08:21 -07:00
}).then(getResolveFunction(resolve, id));
2016-05-13 11:28:05 -07:00
});
break;
}
2016-07-21 13:25:55 -07:00
case 'externalplayer':
LibraryBrowser.playInExternalPlayer(itemId);
getResolveFunction(resolve, id)();
break;
2016-07-16 15:26:21 -07:00
case 'album':
{
embyRouter.showItem(item.AlbumId, item.ServerId);
2016-07-16 16:08:21 -07:00
getResolveFunction(resolve, id)();
2016-07-16 15:26:21 -07:00
break;
}
case 'artist':
{
embyRouter.showItem(item.ArtistItems[0].Id, item.ServerId);
2016-07-16 16:08:21 -07:00
getResolveFunction(resolve, id)();
break;
}
case 'playallfromhere':
{
getResolveFunction(resolve, id)();
break;
}
case 'queueallfromhere':
{
getResolveFunction(resolve, id)();
2016-07-16 15:26:21 -07:00
break;
}
2016-07-16 18:58:51 -07:00
case 'sync':
{
require(['syncDialog'], function (syncDialog) {
syncDialog.showMenu({
items: [
{
Id: itemId
}]
});
});
getResolveFunction(resolve, id)();
break;
}
2016-08-12 08:54:37 -07:00
case 'synclocal':
{
require(['syncDialog'], function (syncDialog) {
syncDialog.showMenu({
items: [
{
Id: itemId
}]
});
});
getResolveFunction(resolve, id)();
break;
}
2016-07-17 09:59:14 -07:00
case 'removefromplaylist':
apiClient.ajax({
url: apiClient.getUrl('Playlists/' + options.playlistId + '/Items', {
EntryIds: [item.PlaylistItemId].join(',')
}),
type: 'DELETE'
}).then(function () {
getResolveFunction(resolve, id, true)();
});
break;
case 'removefromcollection':
apiClient.ajax({
type: "DELETE",
url: apiClient.getUrl("Collections/" + options.collectionId + "/Items", {
Ids: [item.Id].join(',')
})
}).then(function () {
getResolveFunction(resolve, id, true)();
});
2016-07-18 11:50:00 -07:00
break;
case 'canceltimer':
2016-07-19 12:51:22 -07:00
deleteTimer(apiClient, item, resolve, id);
2016-07-17 09:59:14 -07:00
break;
2016-05-13 11:28:05 -07:00
default:
2016-05-19 07:37:59 -07:00
reject();
2016-05-13 11:28:05 -07:00
break;
}
});
}
2016-07-19 12:51:22 -07:00
function deleteTimer(apiClient, item, resolve, command) {
require(['confirm'], function (confirm) {
confirm(globalize.translate('sharedcomponents#MessageConfirmRecordingCancellation'), globalize.translate('sharedcomponents#HeaderConfirmRecordingCancellation')).then(function () {
loading.show();
apiClient.cancelLiveTvTimer(item.Id).then(function () {
require(['toast'], function (toast) {
toast(globalize.translate('sharedcomponents#RecordingCancelled'));
});
loading.hide();
getResolveFunction(resolve, command, true)();
});
});
});
}
2016-07-16 21:20:36 -07:00
function play(item, resume, queue) {
var method = queue ? 'queue' : 'play';
2016-07-18 20:57:55 -07:00
var startPosition = 0;
if (resume && item.UserData && item.UserData.PlaybackPositionTicks) {
startPosition = item.UserData.PlaybackPositionTicks;
}
2016-07-16 21:20:36 -07:00
if (item.Type == 'Program') {
playbackManager[method]({
2016-07-18 20:57:55 -07:00
ids: [item.ChannelId],
startPositionTicks: startPosition
2016-07-16 21:20:36 -07:00
});
} else {
playbackManager[method]({
2016-07-18 20:57:55 -07:00
items: [item],
startPositionTicks: startPosition
2016-07-16 21:20:36 -07:00
});
}
}
function editItem(apiClient, item) {
return new Promise(function (resolve, reject) {
var serverId = apiClient.serverInfo().Id;
2016-07-16 21:20:36 -07:00
if (item.Type == 'Timer') {
require(['recordingEditor'], function (recordingEditor) {
recordingEditor.show(item.Id, serverId).then(resolve, reject);
});
} else {
2016-07-24 11:25:32 -07:00
require(['metadataEditor'], function (metadataEditor) {
2016-07-16 21:20:36 -07:00
2016-07-24 11:25:32 -07:00
metadataEditor.show(item.Id, serverId).then(resolve, reject);
2016-07-16 21:20:36 -07:00
});
}
});
}
2016-05-19 07:37:59 -07:00
function deleteItem(apiClient, itemId) {
return new Promise(function (resolve, reject) {
var msg = globalize.translate('sharedcomponents#ConfirmDeleteItem');
var title = globalize.translate('sharedcomponents#HeaderDeleteItem');
require(['confirm'], function (confirm) {
confirm(msg, title).then(function () {
apiClient.deleteItem(itemId).then(function () {
resolve(true);
});
}, reject);
});
});
}
2016-05-14 11:02:06 -07:00
function refresh(apiClient, itemId) {
2016-06-15 09:45:45 -07:00
require(['refreshDialog'], function (refreshDialog) {
new refreshDialog({
itemIds: [itemId],
serverId: apiClient.serverInfo().Id
}).show();
2016-05-14 11:02:06 -07:00
});
}
2016-05-13 11:28:05 -07:00
function show(options) {
return getCommands(options).then(function (commands) {
return new Promise(function (resolve, reject) {
require(['actionsheet'], function (actionSheet) {
actionSheet.show({
2016-07-16 14:28:15 -07:00
items: commands,
positionTo: options.positionTo
2016-05-13 11:28:05 -07:00
}).then(function (id) {
2016-07-17 09:59:14 -07:00
executeCommand(options.item, id, options).then(resolve);
2016-05-13 11:28:05 -07:00
}, reject);
});
});
});
}
return {
getCommands: getCommands,
show: show
};
});