jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/sharing/sharingmanager.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-04-27 19:46:41 -07:00
define(['connectionManager', 'sharingMenu', 'loading'], function (connectionManager, sharingMenu, loading) {
2016-10-17 22:06:48 -07:00
'use strict';
2016-04-27 19:46:41 -07:00
function onSharingCancel(options, apiClient) {
var shareId = options.share.Id;
console.log('share cancelled. shareId: ' + shareId);
// Delete the share since it was cancelled
apiClient.ajax({
type: 'DELETE',
url: apiClient.getUrl('Social/Shares/' + shareId)
});
}
2016-04-27 21:53:11 -07:00
function showMenu(options) {
2016-04-27 19:46:41 -07:00
loading.show();
2016-04-27 21:53:11 -07:00
var itemId = options.itemId;
2016-04-28 20:10:48 -07:00
var apiClient = connectionManager.getApiClient(options.serverId);
2016-04-27 19:46:41 -07:00
var userId = apiClient.getCurrentUserId();
return apiClient.getItem(userId, itemId).then(function () {
return apiClient.ajax({
type: 'POST',
url: apiClient.getUrl('Social/Shares', {
ItemId: itemId,
UserId: userId
}),
dataType: "json"
}).then(function (share) {
var options = {
share: share
};
loading.hide();
2016-04-28 20:10:48 -07:00
2016-05-13 11:28:05 -07:00
return sharingMenu.showMenu(options).then(function () {
2016-04-28 20:10:48 -07:00
console.log('share success. shareId: ' + options.share.Id);
}, function () {
2016-04-27 19:46:41 -07:00
onSharingCancel(options, apiClient);
});
}, function () {
loading.hide();
});
});
}
return {
showMenu: showMenu
};
});