2013-10-28 23:22:06 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-05-12 21:54:20 +04:00
|
|
|
/* global FileList, FileActions */
|
2012-08-22 20:31:54 +04:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
var sharesLoaded = false;
|
2013-01-26 17:07:35 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
if (typeof OC.Share !== 'undefined' && typeof FileActions !== 'undefined') {
|
2014-05-12 21:54:20 +04:00
|
|
|
// TODO: make a separate class for this or a hook or jQuery event ?
|
2014-05-20 15:37:58 +04:00
|
|
|
if (OCA.Files.FileList) {
|
|
|
|
var oldCreateRow = OCA.Files.FileList.prototype._createRow;
|
|
|
|
OCA.Files.FileList.prototype._createRow = function(fileData) {
|
|
|
|
var tr = oldCreateRow.apply(this, arguments);
|
|
|
|
if (fileData.shareOwner) {
|
|
|
|
tr.attr('data-share-owner', fileData.shareOwner);
|
|
|
|
}
|
|
|
|
return tr;
|
|
|
|
};
|
|
|
|
}
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2013-08-17 15:07:18 +04:00
|
|
|
$('#fileList').on('fileActionsReady',function(){
|
2014-05-13 17:22:18 +04:00
|
|
|
// if no share action exists because the admin disabled sharing for this user
|
|
|
|
// we create a share notification action to inform the user about files
|
|
|
|
// shared with him otherwise we just update the existing share action.
|
2014-05-22 16:28:29 +04:00
|
|
|
var $fileList = $(this);
|
2014-05-23 18:21:15 +04:00
|
|
|
$fileList.find('[data-share-owner]').each(function() {
|
|
|
|
var $tr = $(this);
|
|
|
|
var $action;
|
|
|
|
var owner;
|
|
|
|
var message;
|
|
|
|
var permissions = $tr.data('permissions');
|
|
|
|
if(permissions & OC.PERMISSION_SHARE) {
|
|
|
|
$action = $tr.find('[data-Action="Share"]');
|
|
|
|
$action.addClass('permanent');
|
|
|
|
owner = $tr.closest('tr').attr('data-share-owner');
|
|
|
|
message = ' ' + t('files_sharing', 'Shared by {owner}', {owner: owner});
|
|
|
|
$action.find('span').text(message);
|
|
|
|
} else {
|
|
|
|
var shareNotification = '<a class="action action-share-notification permanent"' +
|
|
|
|
' data-action="Share-Notification" href="#" original-title="">' +
|
|
|
|
' <img class="svg" src="' + OC.imagePath('core', 'actions/share') + '"></img>';
|
|
|
|
$tr.find('.fileactions').append(function() {
|
|
|
|
var owner = $(this).closest('tr').attr('data-share-owner');
|
|
|
|
var shareBy = t('files_sharing', 'Shared by {owner}', {owner: owner});
|
|
|
|
var $result = $(shareNotification + '<span> ' + shareBy + '</span></span>');
|
|
|
|
$result.on('click', function() {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
return $result;
|
2014-05-23 13:16:22 +04:00
|
|
|
});
|
2014-05-23 18:21:15 +04:00
|
|
|
}
|
|
|
|
})
|
2014-01-30 17:47:00 +04:00
|
|
|
|
2014-05-12 21:54:20 +04:00
|
|
|
// FIXME: these calls are also working on hard-coded
|
|
|
|
// list selectors...
|
2013-10-17 13:59:13 +04:00
|
|
|
if (!sharesLoaded){
|
|
|
|
OC.Share.loadIcons('file');
|
|
|
|
// assume that we got all shares, so switching directories
|
|
|
|
// will not invalidate that list
|
|
|
|
sharesLoaded = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
OC.Share.updateIcons('file');
|
|
|
|
}
|
2013-08-08 15:50:04 +04:00
|
|
|
});
|
|
|
|
|
2014-05-13 17:22:18 +04:00
|
|
|
FileActions.register('all', 'Share', OC.PERMISSION_SHARE, OC.imagePath('core', 'actions/share'), function(filename) {
|
2014-01-10 18:02:26 +04:00
|
|
|
var tr = FileList.findFileEl(filename);
|
2014-01-30 17:49:38 +04:00
|
|
|
var itemType = 'file';
|
2012-08-23 22:48:35 +04:00
|
|
|
if ($(tr).data('type') == 'dir') {
|
2014-01-30 17:49:38 +04:00
|
|
|
itemType = 'folder';
|
2012-08-22 20:31:54 +04:00
|
|
|
}
|
2012-08-23 22:48:35 +04:00
|
|
|
var possiblePermissions = $(tr).data('permissions');
|
2013-12-03 18:23:13 +04:00
|
|
|
var appendTo = $(tr).find('td.filename');
|
2012-08-22 20:31:54 +04:00
|
|
|
// Check if drop down is already visible for a different file
|
|
|
|
if (OC.Share.droppedDown) {
|
2012-10-09 20:42:49 +04:00
|
|
|
if ($(tr).data('id') != $('#dropdown').attr('data-item-source')) {
|
2012-08-22 20:31:54 +04:00
|
|
|
OC.Share.hideDropDown(function () {
|
2012-08-24 18:01:01 +04:00
|
|
|
$(tr).addClass('mouseOver');
|
2013-10-23 20:39:37 +04:00
|
|
|
OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions, filename);
|
2012-08-22 20:31:54 +04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
OC.Share.hideDropDown();
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-24 18:01:01 +04:00
|
|
|
$(tr).addClass('mouseOver');
|
2013-10-23 20:39:37 +04:00
|
|
|
OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions, filename);
|
2012-08-22 20:31:54 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-08-18 13:02:08 +04:00
|
|
|
});
|