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