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

220 lines
6.8 KiB
JavaScript
Raw Normal View History

2016-05-21 23:08:44 -07:00
define(['apphost', 'globalize', 'connectionManager', 'itemHelper'], function (appHost, globalize, connectionManager, itemHelper) {
2016-05-13 11:28:05 -07:00
function getCommands(options) {
var item = options.item;
var serverId = item.ServerId;
var apiClient = connectionManager.getApiClient(serverId);
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-05-19 07:37:59 -07:00
if (item.CanDelete) {
commands.push({
name: globalize.translate('sharedcomponents#Delete'),
id: 'delete'
});
}
2016-05-31 08:29:00 -07:00
if (user.Policy.IsAdministrator) {
if (item.MediaType == 'Video' && item.Type != 'TvChannel' && item.Type != 'Program' && item.LocationType != 'Virtual') {
commands.push({
name: globalize.translate('sharedcomponents#EditSubtitles'),
id: 'editsubtitles'
});
}
}
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-05-14 11:02:06 -07:00
if (user.Policy.IsAdministrator) {
commands.push({
name: globalize.translate('Refresh'),
id: 'refresh'
});
}
2016-05-13 11:28:05 -07:00
if (item.Type != 'Timer' && user.Policy.EnablePublicSharing && appHost.supports('sharing')) {
commands.push({
name: globalize.translate('Share'),
id: 'share'
});
}
return commands;
});
}
function executeCommand(item, id) {
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
}).then(reject, reject);
});
break;
}
2016-05-21 23:08:44 -07:00
case 'addtoplaylist':
{
require(['playlistEditor'], function (playlistEditor) {
new playlistEditor().show({
items: [itemId],
serverId: serverId
}).then(reject, reject);
});
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
}]);
reject();
});
2016-05-31 08:29:00 -07:00
break;
}
case 'editsubtitles':
{
require(['subtitleEditor'], function (subtitleEditor) {
var serverId = apiClient.serverInfo().Id;
subtitleEditor.show(itemId, serverId).then(resolve, reject);
});
2016-05-14 11:02:06 -07:00
break;
}
case 'refresh':
{
refresh(apiClient, itemId);
2016-05-19 07:37:59 -07:00
reject();
break;
}
case 'delete':
{
deleteItem(apiClient, itemId).then(function () {
resolve(true);
});
2016-05-13 11:28:05 -07:00
break;
}
case 'share':
{
require(['sharingmanager'], function (sharingManager) {
sharingManager.showMenu({
serverId: serverId,
itemId: itemId
}).then(reject);
});
break;
}
default:
2016-05-19 07:37:59 -07:00
reject();
2016-05-13 11:28:05 -07:00
break;
}
});
}
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) {
executeCommand(options.item, id).then(resolve);
}, reject);
});
});
});
}
return {
getCommands: getCommands,
show: show
};
});