2014-07-03 11:19:14 +00:00
|
|
|
/* global escapeHTML */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
2015-09-15 08:27:33 +00:00
|
|
|
OC.Share = _.extend(OC.Share || {}, {
|
2012-06-25 23:27:57 +00:00
|
|
|
SHARE_TYPE_USER:0,
|
|
|
|
SHARE_TYPE_GROUP:1,
|
2012-08-28 00:05:51 +00:00
|
|
|
SHARE_TYPE_LINK:3,
|
2012-07-31 14:18:26 +00:00
|
|
|
SHARE_TYPE_EMAIL:4,
|
2014-12-04 18:51:04 +00:00
|
|
|
SHARE_TYPE_REMOTE:6,
|
2014-07-03 11:19:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Regular expression for splitting parts of remote share owners:
|
|
|
|
* "user@example.com/path/to/owncloud"
|
|
|
|
* "user@anotherexample.com@example.com/path/to/owncloud
|
|
|
|
*/
|
2015-05-16 12:22:10 +00:00
|
|
|
_REMOTE_OWNER_REGEXP: new RegExp("^([^@]*)@(([^@]*)@)?([^/]*)([/](.*)?)?$"),
|
2014-07-03 11:19:14 +00:00
|
|
|
|
2014-06-04 08:37:04 +00:00
|
|
|
/**
|
|
|
|
* @deprecated use OC.Share.currentShares instead
|
|
|
|
*/
|
2012-07-31 17:06:32 +00:00
|
|
|
itemShares:[],
|
2014-06-04 08:37:04 +00:00
|
|
|
/**
|
|
|
|
* Full list of all share statuses
|
|
|
|
*/
|
2013-10-17 09:59:13 +00:00
|
|
|
statuses:{},
|
2014-06-04 08:37:04 +00:00
|
|
|
/**
|
|
|
|
* Shares for the currently selected file.
|
|
|
|
* (for which the dropdown is open)
|
|
|
|
*
|
|
|
|
* Key is item type and value is an array or
|
|
|
|
* shares of the given item type.
|
|
|
|
*/
|
|
|
|
currentShares: {},
|
|
|
|
/**
|
|
|
|
* Whether the share dropdown is opened.
|
|
|
|
*/
|
2012-08-08 21:50:09 +00:00
|
|
|
droppedDown:false,
|
2013-10-17 09:59:13 +00:00
|
|
|
/**
|
2014-03-01 01:46:27 +00:00
|
|
|
* Loads ALL share statuses from server, stores them in
|
|
|
|
* OC.Share.statuses then calls OC.Share.updateIcons() to update the
|
|
|
|
* files "Share" icon to "Shared" according to their share status and
|
|
|
|
* share type.
|
2014-05-19 13:20:44 +00:00
|
|
|
*
|
2014-07-01 19:32:04 +00:00
|
|
|
* If a callback is specified, the update step is skipped.
|
|
|
|
*
|
2014-05-19 13:20:44 +00:00
|
|
|
* @param itemType item type
|
|
|
|
* @param fileList file list instance, defaults to OCA.Files.App.fileList
|
2014-07-01 19:32:04 +00:00
|
|
|
* @param callback function to call after the shares were loaded
|
2013-10-17 09:59:13 +00:00
|
|
|
*/
|
2014-07-01 19:32:04 +00:00
|
|
|
loadIcons:function(itemType, fileList, callback) {
|
2012-06-24 23:16:50 +00:00
|
|
|
// Load all share icons
|
2014-03-01 01:46:27 +00:00
|
|
|
$.get(
|
|
|
|
OC.filePath('core', 'ajax', 'share.php'),
|
|
|
|
{
|
|
|
|
fetch: 'getItemsSharedStatuses',
|
|
|
|
itemType: itemType
|
|
|
|
}, function(result) {
|
|
|
|
if (result && result.status === 'success') {
|
|
|
|
OC.Share.statuses = {};
|
|
|
|
$.each(result.data, function(item, data) {
|
|
|
|
OC.Share.statuses[item] = data;
|
|
|
|
});
|
2014-07-01 19:32:04 +00:00
|
|
|
if (_.isFunction(callback)) {
|
|
|
|
callback(OC.Share.statuses);
|
|
|
|
} else {
|
|
|
|
OC.Share.updateIcons(itemType, fileList);
|
|
|
|
}
|
2014-03-01 01:46:27 +00:00
|
|
|
}
|
2013-10-17 09:59:13 +00:00
|
|
|
}
|
2014-03-01 01:46:27 +00:00
|
|
|
);
|
2013-10-17 09:59:13 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Updates the files' "Share" icons according to the known
|
|
|
|
* sharing states stored in OC.Share.statuses.
|
|
|
|
* (not reloaded from server)
|
2014-05-19 13:20:44 +00:00
|
|
|
*
|
|
|
|
* @param itemType item type
|
2014-05-21 10:54:34 +00:00
|
|
|
* @param fileList file list instance
|
2014-05-19 13:20:44 +00:00
|
|
|
* defaults to OCA.Files.App.fileList
|
2013-10-17 09:59:13 +00:00
|
|
|
*/
|
2014-05-19 13:20:44 +00:00
|
|
|
updateIcons:function(itemType, fileList){
|
2013-10-17 12:39:20 +00:00
|
|
|
var item;
|
2014-05-28 14:34:00 +00:00
|
|
|
var $fileList;
|
|
|
|
var currentDir;
|
|
|
|
if (!fileList && OCA.Files) {
|
|
|
|
fileList = OCA.Files.App.fileList;
|
|
|
|
}
|
|
|
|
// fileList is usually only defined in the files app
|
|
|
|
if (fileList) {
|
|
|
|
$fileList = fileList.$fileList;
|
|
|
|
currentDir = fileList.getCurrentDirectory();
|
|
|
|
}
|
2014-06-02 15:23:52 +00:00
|
|
|
// TODO: iterating over the files might be more efficient
|
2013-10-17 09:59:13 +00:00
|
|
|
for (item in OC.Share.statuses){
|
2014-06-02 13:59:06 +00:00
|
|
|
var image = OC.imagePath('core', 'actions/share');
|
2013-10-17 09:59:13 +00:00
|
|
|
var data = OC.Share.statuses[item];
|
2014-05-21 10:54:34 +00:00
|
|
|
var hasLink = data.link;
|
2013-10-17 09:59:13 +00:00
|
|
|
// Links override shared in terms of icon display
|
|
|
|
if (hasLink) {
|
2014-05-21 10:54:34 +00:00
|
|
|
image = OC.imagePath('core', 'actions/public');
|
2013-10-17 09:59:13 +00:00
|
|
|
}
|
2014-05-21 10:54:34 +00:00
|
|
|
if (itemType !== 'file' && itemType !== 'folder') {
|
2014-05-28 16:39:29 +00:00
|
|
|
$('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center');
|
2013-10-17 09:59:13 +00:00
|
|
|
} else {
|
2014-05-28 16:39:29 +00:00
|
|
|
// TODO: ultimately this part should be moved to files_sharing app
|
2014-05-19 13:20:44 +00:00
|
|
|
var file = $fileList.find('tr[data-id="'+item+'"]');
|
2014-05-28 10:13:55 +00:00
|
|
|
var shareFolder = OC.imagePath('core', 'filetypes/folder-shared');
|
|
|
|
var img;
|
2013-10-17 09:59:13 +00:00
|
|
|
if (file.length > 0) {
|
2014-06-02 15:23:52 +00:00
|
|
|
this.markFileAsShared(file, true, hasLink);
|
2013-10-17 09:59:13 +00:00
|
|
|
} else {
|
2014-05-21 10:54:34 +00:00
|
|
|
var dir = currentDir;
|
2013-10-17 09:59:13 +00:00
|
|
|
if (dir.length > 1) {
|
|
|
|
var last = '';
|
|
|
|
var path = dir;
|
|
|
|
// Search for possible parent folders that are shared
|
|
|
|
while (path != last) {
|
2014-05-21 10:54:34 +00:00
|
|
|
if (path === data.path && !data.link) {
|
2014-05-19 13:20:44 +00:00
|
|
|
var actions = $fileList.find('.fileactions .action[data-action="Share"]');
|
2014-05-28 10:13:55 +00:00
|
|
|
var files = $fileList.find('.filename');
|
|
|
|
var i;
|
|
|
|
for (i = 0; i < actions.length; i++) {
|
2014-05-28 16:39:29 +00:00
|
|
|
// TODO: use this.markFileAsShared()
|
2014-05-28 10:13:55 +00:00
|
|
|
img = $(actions[i]).find('img');
|
2014-05-21 10:54:34 +00:00
|
|
|
if (img.attr('src') !== OC.imagePath('core', 'actions/public')) {
|
2013-10-17 09:59:13 +00:00
|
|
|
img.attr('src', image);
|
2014-05-28 10:13:55 +00:00
|
|
|
$(actions[i]).addClass('permanent');
|
2015-08-26 08:27:55 +00:00
|
|
|
$(actions[i]).html('<span> '+t('core', 'Shared')+'</span>').prepend(img);
|
2014-05-28 10:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i = 0; i < files.length; i++) {
|
|
|
|
if ($(files[i]).closest('tr').data('type') === 'dir') {
|
2014-12-11 16:36:14 +00:00
|
|
|
$(files[i]).find('.thumbnail').css('background-image', 'url('+shareFolder+')');
|
2012-10-28 20:01:50 +00:00
|
|
|
}
|
2014-05-28 10:13:55 +00:00
|
|
|
}
|
2012-10-28 20:01:50 +00:00
|
|
|
}
|
2013-10-17 09:59:13 +00:00
|
|
|
last = path;
|
|
|
|
path = OC.Share.dirname(path);
|
2012-06-24 23:16:50 +00:00
|
|
|
}
|
2012-05-05 18:56:52 +00:00
|
|
|
}
|
2013-10-17 09:59:13 +00:00
|
|
|
}
|
2012-05-05 18:56:52 +00:00
|
|
|
}
|
2013-10-17 09:59:13 +00:00
|
|
|
}
|
2012-05-05 18:56:52 +00:00
|
|
|
},
|
2012-08-24 19:32:06 +00:00
|
|
|
updateIcon:function(itemType, itemSource) {
|
|
|
|
var shares = false;
|
2012-09-19 05:44:15 +00:00
|
|
|
var link = false;
|
|
|
|
var image = OC.imagePath('core', 'actions/share');
|
2012-08-24 19:32:06 +00:00
|
|
|
$.each(OC.Share.itemShares, function(index) {
|
2012-09-19 05:44:15 +00:00
|
|
|
if (OC.Share.itemShares[index]) {
|
|
|
|
if (index == OC.Share.SHARE_TYPE_LINK) {
|
|
|
|
if (OC.Share.itemShares[index] == true) {
|
|
|
|
shares = true;
|
|
|
|
image = OC.imagePath('core', 'actions/public');
|
|
|
|
link = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (OC.Share.itemShares[index].length > 0) {
|
|
|
|
shares = true;
|
2014-06-02 13:59:06 +00:00
|
|
|
image = OC.imagePath('core', 'actions/share');
|
2012-09-19 05:44:15 +00:00
|
|
|
}
|
2012-08-24 19:32:06 +00:00
|
|
|
}
|
|
|
|
});
|
2012-09-19 05:44:15 +00:00
|
|
|
if (itemType != 'file' && itemType != 'folder') {
|
|
|
|
$('a.share[data-item="'+itemSource+'"]').css('background', 'url('+image+') no-repeat center');
|
2013-01-26 18:25:15 +00:00
|
|
|
} else {
|
2014-05-28 16:39:29 +00:00
|
|
|
var $tr = $('tr').filterAttr('data-id', String(itemSource));
|
|
|
|
if ($tr.length > 0) {
|
2014-06-02 15:23:52 +00:00
|
|
|
// it might happen that multiple lists exist in the DOM
|
|
|
|
// with the same id
|
|
|
|
$tr.each(function() {
|
|
|
|
OC.Share.markFileAsShared($(this), shares, link);
|
2014-05-21 10:54:34 +00:00
|
|
|
});
|
2013-01-26 18:25:15 +00:00
|
|
|
}
|
2012-09-19 05:44:15 +00:00
|
|
|
}
|
2012-08-24 19:32:06 +00:00
|
|
|
if (shares) {
|
2013-07-22 18:02:56 +00:00
|
|
|
OC.Share.statuses[itemSource] = OC.Share.statuses[itemSource] || {};
|
2013-03-08 03:30:12 +00:00
|
|
|
OC.Share.statuses[itemSource]['link'] = link;
|
2012-08-24 19:32:06 +00:00
|
|
|
} else {
|
|
|
|
delete OC.Share.statuses[itemSource];
|
|
|
|
}
|
|
|
|
},
|
2014-07-03 11:19:14 +00:00
|
|
|
/**
|
2015-05-16 12:22:10 +00:00
|
|
|
* Format a remote address
|
2014-07-03 11:19:14 +00:00
|
|
|
*
|
2015-05-16 12:22:10 +00:00
|
|
|
* @param {String} remoteAddress full remote share
|
|
|
|
* @return {String} HTML code to display
|
2014-07-03 11:19:14 +00:00
|
|
|
*/
|
2015-05-16 12:22:10 +00:00
|
|
|
_formatRemoteShare: function(remoteAddress) {
|
|
|
|
var parts = this._REMOTE_OWNER_REGEXP.exec(remoteAddress);
|
2014-07-03 11:19:14 +00:00
|
|
|
if (!parts) {
|
|
|
|
// display as is, most likely to be a simple owner name
|
2015-05-16 12:22:10 +00:00
|
|
|
return escapeHTML(remoteAddress);
|
2014-07-03 11:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var userName = parts[1];
|
|
|
|
var userDomain = parts[3];
|
|
|
|
var server = parts[4];
|
2015-05-16 12:22:10 +00:00
|
|
|
var dir = parts[6];
|
2014-07-03 11:19:14 +00:00
|
|
|
var tooltip = userName;
|
|
|
|
if (userDomain) {
|
|
|
|
tooltip += '@' + userDomain;
|
|
|
|
}
|
|
|
|
if (server) {
|
2015-01-27 10:06:18 +00:00
|
|
|
if (!userDomain) {
|
|
|
|
userDomain = '…';
|
|
|
|
}
|
2014-07-03 11:19:14 +00:00
|
|
|
tooltip += '@' + server;
|
|
|
|
}
|
|
|
|
|
2015-05-16 12:22:10 +00:00
|
|
|
var html = '<span class="remoteAddress" title="' + escapeHTML(tooltip) + '">';
|
2014-07-03 11:19:14 +00:00
|
|
|
html += '<span class="username">' + escapeHTML(userName) + '</span>';
|
|
|
|
if (userDomain) {
|
|
|
|
html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>';
|
|
|
|
}
|
|
|
|
html += '</span>';
|
2014-07-11 13:16:26 +00:00
|
|
|
return html;
|
2014-07-03 11:19:14 +00:00
|
|
|
},
|
2015-05-16 12:22:10 +00:00
|
|
|
/**
|
2015-08-25 12:45:39 +00:00
|
|
|
* Loop over all recipients in the list and format them using
|
2015-05-16 12:22:10 +00:00
|
|
|
* all kind of fancy magic.
|
|
|
|
*
|
|
|
|
* @param {String[]} recipients array of all the recipients
|
|
|
|
* @return {String[]} modified list of recipients
|
|
|
|
*/
|
|
|
|
_formatShareList: function(recipients) {
|
|
|
|
var _parent = this;
|
|
|
|
return $.map(recipients, function(recipient) {
|
|
|
|
recipient = _parent._formatRemoteShare(recipient);
|
|
|
|
return recipient;
|
|
|
|
});
|
|
|
|
},
|
2014-05-28 16:39:29 +00:00
|
|
|
/**
|
2014-06-02 15:23:52 +00:00
|
|
|
* Marks/unmarks a given file as shared by changing its action icon
|
|
|
|
* and folder icon.
|
2014-05-28 16:39:29 +00:00
|
|
|
*
|
|
|
|
* @param $tr file element to mark as shared
|
2014-06-02 15:23:52 +00:00
|
|
|
* @param hasShares whether shares are available
|
|
|
|
* @param hasLink whether link share is available
|
2014-05-28 16:39:29 +00:00
|
|
|
*/
|
2014-06-02 15:23:52 +00:00
|
|
|
markFileAsShared: function($tr, hasShares, hasLink) {
|
2014-05-28 16:39:29 +00:00
|
|
|
var action = $tr.find('.fileactions .action[data-action="Share"]');
|
|
|
|
var type = $tr.data('type');
|
|
|
|
var img = action.find('img');
|
|
|
|
var message;
|
|
|
|
var recipients;
|
2014-06-03 09:04:57 +00:00
|
|
|
var owner = $tr.attr('data-share-owner');
|
2014-05-28 16:39:29 +00:00
|
|
|
var shareFolderIcon;
|
2014-06-02 15:23:52 +00:00
|
|
|
var image = OC.imagePath('core', 'actions/share');
|
2015-08-25 12:45:39 +00:00
|
|
|
action.removeClass('shared-style');
|
2014-06-02 15:23:52 +00:00
|
|
|
// update folder icon
|
2014-08-15 14:19:50 +00:00
|
|
|
if (type === 'dir' && (hasShares || hasLink || owner)) {
|
2014-06-02 15:23:52 +00:00
|
|
|
if (hasLink) {
|
2015-10-28 16:43:36 +00:00
|
|
|
shareFolderIcon = OC.MimeType.getIconUrl('dir-public');
|
2014-06-02 15:23:52 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-10-28 16:43:36 +00:00
|
|
|
shareFolderIcon = OC.MimeType.getIconUrl('dir-shared');
|
2014-06-02 15:23:52 +00:00
|
|
|
}
|
2014-12-11 16:36:14 +00:00
|
|
|
$tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')');
|
2015-10-28 16:43:36 +00:00
|
|
|
$tr.attr('data-icon', shareFolderIcon);
|
2014-05-28 16:39:29 +00:00
|
|
|
} else if (type === 'dir') {
|
2015-10-28 16:43:36 +00:00
|
|
|
var mountType = $tr.attr('data-mounttype');
|
|
|
|
// FIXME: duplicate of FileList._createRow logic for external folder,
|
|
|
|
// need to refactor the icon logic into a single code path eventually
|
|
|
|
if (mountType && mountType.indexOf('external') === 0) {
|
|
|
|
shareFolderIcon = OC.MimeType.getIconUrl('dir-external');
|
|
|
|
$tr.attr('data-icon', shareFolderIcon);
|
|
|
|
} else {
|
|
|
|
shareFolderIcon = OC.MimeType.getIconUrl('dir');
|
|
|
|
// back to default
|
|
|
|
$tr.removeAttr('data-icon');
|
|
|
|
}
|
2014-12-11 16:36:14 +00:00
|
|
|
$tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')');
|
2014-05-28 16:39:29 +00:00
|
|
|
}
|
2014-06-02 15:23:52 +00:00
|
|
|
// update share action text / icon
|
2014-06-03 09:04:57 +00:00
|
|
|
if (hasShares || owner) {
|
2014-05-28 16:39:29 +00:00
|
|
|
recipients = $tr.attr('data-share-recipients');
|
2015-08-25 12:45:39 +00:00
|
|
|
action.addClass('shared-style');
|
2014-05-28 16:39:29 +00:00
|
|
|
|
|
|
|
message = t('core', 'Shared');
|
2014-06-03 09:04:57 +00:00
|
|
|
// even if reshared, only show "Shared by"
|
|
|
|
if (owner) {
|
2015-05-16 12:22:10 +00:00
|
|
|
message = this._formatRemoteShare(owner);
|
2014-05-28 16:39:29 +00:00
|
|
|
}
|
2014-06-03 09:04:57 +00:00
|
|
|
else if (recipients) {
|
2015-05-16 12:22:10 +00:00
|
|
|
message = t('core', 'Shared with {recipients}', {recipients: this._formatShareList(recipients.split(", ")).join(", ")}, 0, {escape: false});
|
2014-05-28 16:39:29 +00:00
|
|
|
}
|
2015-08-26 08:27:55 +00:00
|
|
|
action.html('<span> ' + message + '</span>').prepend(img);
|
2015-05-16 12:22:10 +00:00
|
|
|
if (owner || recipients) {
|
|
|
|
action.find('.remoteAddress').tipsy({gravity: 's'});
|
2014-07-03 11:19:14 +00:00
|
|
|
}
|
2014-05-28 16:39:29 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-08-10 13:57:21 +00:00
|
|
|
action.html('<span></span>').prepend(img);
|
2014-05-28 16:39:29 +00:00
|
|
|
}
|
2014-06-02 15:23:52 +00:00
|
|
|
if (hasLink) {
|
|
|
|
image = OC.imagePath('core', 'actions/public');
|
|
|
|
}
|
2014-05-28 16:39:29 +00:00
|
|
|
img.attr('src', image);
|
|
|
|
},
|
2015-07-30 22:07:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param itemType
|
|
|
|
* @param itemSource
|
2015-08-18 11:04:02 +00:00
|
|
|
* @param callback - optional. If a callback is given this method works
|
|
|
|
* asynchronous and the callback will be provided with data when the request
|
|
|
|
* is done.
|
2015-07-30 22:07:41 +00:00
|
|
|
* @returns {OC.Share.Types.ShareInfo}
|
|
|
|
*/
|
2015-08-11 20:34:08 +00:00
|
|
|
loadItem:function(itemType, itemSource, callback) {
|
2012-06-25 23:27:57 +00:00
|
|
|
var data = '';
|
2012-08-24 14:43:42 +00:00
|
|
|
var checkReshare = true;
|
2015-08-11 20:34:08 +00:00
|
|
|
var async = !_.isUndefined(callback);
|
2013-03-08 03:30:12 +00:00
|
|
|
if (typeof OC.Share.statuses[itemSource] === 'undefined') {
|
2012-09-21 10:05:01 +00:00
|
|
|
// NOTE: Check does not always work and misses some shares, fix later
|
2013-07-31 19:21:02 +00:00
|
|
|
var checkShares = true;
|
2012-08-22 15:35:30 +00:00
|
|
|
} else {
|
2013-07-31 19:21:02 +00:00
|
|
|
var checkShares = true;
|
2012-08-06 17:30:44 +00:00
|
|
|
}
|
2015-08-11 20:34:08 +00:00
|
|
|
$.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemSource: itemSource, checkReshare: checkReshare, checkShares: checkShares }, async: async, success: function(result) {
|
2012-08-21 00:00:29 +00:00
|
|
|
if (result && result.status === 'success') {
|
|
|
|
data = result.data;
|
|
|
|
} else {
|
|
|
|
data = false;
|
|
|
|
}
|
2015-08-11 20:34:08 +00:00
|
|
|
if(async) {
|
|
|
|
callback(data);
|
|
|
|
}
|
2012-08-21 00:00:29 +00:00
|
|
|
}});
|
2013-08-30 13:39:43 +00:00
|
|
|
|
2012-06-25 23:27:57 +00:00
|
|
|
return data;
|
2012-05-05 18:56:52 +00:00
|
|
|
},
|
2015-07-23 07:39:26 +00:00
|
|
|
share:function(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, expirationDate, callback, errorCallback) {
|
2014-05-07 10:17:46 +00:00
|
|
|
// Add a fallback for old share() calls without expirationDate.
|
|
|
|
// We should remove this in a later version,
|
|
|
|
// after the Apps have been updated.
|
|
|
|
if (typeof callback === 'undefined' &&
|
|
|
|
typeof expirationDate === 'function') {
|
|
|
|
callback = expirationDate;
|
|
|
|
expirationDate = '';
|
|
|
|
console.warn(
|
|
|
|
"Call to 'OC.Share.share()' with too few arguments. " +
|
|
|
|
"'expirationDate' was assumed to be 'callback'. " +
|
|
|
|
"Please revisit the call and fix the list of arguments."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:46:30 +00:00
|
|
|
return $.post(OC.filePath('core', 'ajax', 'share.php'),
|
2013-10-23 16:39:37 +00:00
|
|
|
{
|
|
|
|
action: 'share',
|
|
|
|
itemType: itemType,
|
|
|
|
itemSource: itemSource,
|
|
|
|
shareType: shareType,
|
|
|
|
shareWith: shareWith,
|
|
|
|
permissions: permissions,
|
2014-05-07 10:17:46 +00:00
|
|
|
itemSourceName: itemSourceName,
|
|
|
|
expirationDate: expirationDate
|
2013-10-23 16:39:37 +00:00
|
|
|
}, function (result) {
|
2014-03-01 01:46:27 +00:00
|
|
|
if (result && result.status === 'success') {
|
|
|
|
if (callback) {
|
|
|
|
callback(result.data);
|
|
|
|
}
|
2013-07-22 18:02:18 +00:00
|
|
|
} else {
|
2015-07-23 07:39:26 +00:00
|
|
|
if (_.isUndefined(errorCallback)) {
|
2014-03-01 01:46:27 +00:00
|
|
|
var msg = t('core', 'Error');
|
2015-07-23 07:39:26 +00:00
|
|
|
if (result.data && result.data.message) {
|
|
|
|
msg = result.data.message;
|
|
|
|
}
|
|
|
|
OC.dialogs.alert(msg, t('core', 'Error while sharing'));
|
|
|
|
} else {
|
|
|
|
errorCallback(result);
|
2014-03-01 01:46:27 +00:00
|
|
|
}
|
2013-07-22 18:02:18 +00:00
|
|
|
}
|
2012-05-05 18:56:52 +00:00
|
|
|
}
|
2014-03-01 01:46:27 +00:00
|
|
|
);
|
2012-05-05 18:56:52 +00:00
|
|
|
},
|
2012-08-21 00:00:29 +00:00
|
|
|
unshare:function(itemType, itemSource, shareType, shareWith, callback) {
|
|
|
|
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith }, function(result) {
|
2012-05-05 18:56:52 +00:00
|
|
|
if (result && result.status === 'success') {
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
} else {
|
2013-04-09 11:22:34 +00:00
|
|
|
OC.dialogs.alert(t('core', 'Error while unsharing'), t('core', 'Error'));
|
2012-05-05 18:56:52 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-08-21 00:00:29 +00:00
|
|
|
setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) {
|
|
|
|
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
|
2012-05-05 18:56:52 +00:00
|
|
|
if (!result || result.status !== 'success') {
|
2013-04-09 11:22:34 +00:00
|
|
|
OC.dialogs.alert(t('core', 'Error while changing permissions'), t('core', 'Error'));
|
2012-05-05 18:56:52 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-10-23 16:39:37 +00:00
|
|
|
showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) {
|
2015-08-13 00:38:14 +00:00
|
|
|
var configModel = new OC.Share.ShareConfigModel();
|
2015-08-11 21:14:44 +00:00
|
|
|
var attributes = {itemType: itemType, itemSource: itemSource, possiblePermissions: possiblePermissions};
|
2015-08-13 00:38:14 +00:00
|
|
|
var itemModel = new OC.Share.ShareItemModel(attributes, {configModel: configModel});
|
2015-08-07 22:23:06 +00:00
|
|
|
var dialogView = new OC.Share.ShareDialogView({
|
|
|
|
id: 'dropdown',
|
|
|
|
model: itemModel,
|
2015-08-13 00:38:14 +00:00
|
|
|
configModel: configModel,
|
2015-08-07 22:23:06 +00:00
|
|
|
className: 'drop shareDropDown',
|
|
|
|
attributes: {
|
2015-08-11 21:14:44 +00:00
|
|
|
'data-item-source-name': filename,
|
|
|
|
'data-item-type': itemType,
|
2015-09-18 21:19:59 +00:00
|
|
|
'data-item-source': itemSource
|
2015-08-07 22:23:06 +00:00
|
|
|
}
|
|
|
|
});
|
2015-07-30 22:07:41 +00:00
|
|
|
dialogView.setShowLink(link);
|
2015-08-07 22:23:06 +00:00
|
|
|
var $dialog = dialogView.render().$el;
|
2015-07-30 22:07:41 +00:00
|
|
|
$dialog.appendTo(appendTo);
|
|
|
|
$dialog.slideDown(OC.menuSpeed, function() {
|
|
|
|
OC.Share.droppedDown = true;
|
|
|
|
});
|
2015-08-24 21:27:43 +00:00
|
|
|
itemModel.fetch();
|
2012-05-05 18:56:52 +00:00
|
|
|
},
|
|
|
|
hideDropDown:function(callback) {
|
2014-06-04 08:37:04 +00:00
|
|
|
OC.Share.currentShares = null;
|
2015-03-26 11:21:40 +00:00
|
|
|
$('#dropdown').slideUp(OC.menuSpeed, function() {
|
2012-08-08 21:50:09 +00:00
|
|
|
OC.Share.droppedDown = false;
|
2012-05-05 18:56:52 +00:00
|
|
|
$('#dropdown').remove();
|
2012-08-08 21:50:09 +00:00
|
|
|
if (typeof FileActions !== 'undefined') {
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
}
|
2012-05-05 18:56:52 +00:00
|
|
|
if (callback) {
|
|
|
|
callback.call();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-02-08 10:05:56 +00:00
|
|
|
dirname:function(path) {
|
2012-05-05 18:56:52 +00:00
|
|
|
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
|
|
|
|
}
|
2015-07-30 22:07:41 +00:00
|
|
|
});
|
2012-05-05 18:56:52 +00:00
|
|
|
|
2011-07-27 01:27:40 +00:00
|
|
|
$(document).ready(function() {
|
2013-03-27 20:18:19 +00:00
|
|
|
|
2012-11-14 15:47:52 +00:00
|
|
|
if(typeof monthNames != 'undefined'){
|
2014-08-08 09:09:17 +00:00
|
|
|
// min date should always be the next day
|
|
|
|
var minDate = new Date();
|
|
|
|
minDate.setDate(minDate.getDate()+1);
|
2013-02-08 10:05:56 +00:00
|
|
|
$.datepicker.setDefaults({
|
|
|
|
monthNames: monthNames,
|
2015-08-21 07:17:36 +00:00
|
|
|
monthNamesShort: monthNamesShort,
|
2013-02-08 10:05:56 +00:00
|
|
|
dayNames: dayNames,
|
2015-08-21 07:17:36 +00:00
|
|
|
dayNamesMin: dayNamesMin,
|
|
|
|
dayNamesShort: dayNamesShort,
|
2014-06-06 15:40:16 +00:00
|
|
|
firstDay: firstDay,
|
2014-08-08 09:09:17 +00:00
|
|
|
minDate : minDate
|
2013-02-08 10:05:56 +00:00
|
|
|
});
|
|
|
|
}
|
2012-06-24 23:16:50 +00:00
|
|
|
|
2012-08-08 21:50:09 +00:00
|
|
|
$(this).click(function(event) {
|
2012-10-08 19:03:16 +00:00
|
|
|
var target = $(event.target);
|
2013-03-27 20:18:19 +00:00
|
|
|
var isMatched = !target.is('.drop, .ui-datepicker-next, .ui-datepicker-prev, .ui-icon')
|
2013-10-07 11:25:30 +00:00
|
|
|
&& !target.closest('#ui-datepicker-div').length && !target.closest('.ui-autocomplete').length;
|
2015-09-15 08:27:33 +00:00
|
|
|
if (OC.Share && OC.Share.droppedDown && isMatched && $('#dropdown').has(event.target).length === 0) {
|
2012-08-08 21:50:09 +00:00
|
|
|
OC.Share.hideDropDown();
|
|
|
|
}
|
|
|
|
});
|
2012-05-05 18:56:52 +00:00
|
|
|
|
2013-08-30 11:53:49 +00:00
|
|
|
|
2012-12-10 22:22:42 +00:00
|
|
|
|
2012-06-25 18:55:49 +00:00
|
|
|
});
|