server/apps/files_sharing/js/share.js
Vincent Petry 9d38e3602b Namespacing for FileList, FileActions and trashbin app
- FileList is now an instantiable class
- FileActions is now in namespace
- added App class for trashbin app
- moved trashbin overrides into classes extending FileList
- replaced many static calls with "this." or "self." to make the classes
  reusable/extendable
- new URL parameter "view" to specify which view is shown, for example
  "files" or "trashbin"
- added OC.Util.History utility class in core for handling history
- moved URL handling/routing to OCA.Files.App
- popstate will correctly update the current view and notify the view of
  the URL change so it can update the current dir
- added JS unitt tests for the trashbin app
- fixed public app to work with the new namespaces
2014-05-15 17:51:04 +02:00

70 lines
2.1 KiB
JavaScript

/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
/* global OC, t, FileList, FileActions */
$(document).ready(function() {
var sharesLoaded = false;
if (typeof OC.Share !== 'undefined' && typeof FileActions !== 'undefined') {
var oldCreateRow = FileList._createRow;
FileList._createRow = function(fileData) {
var tr = oldCreateRow.apply(this, arguments);
if (fileData.shareOwner) {
tr.attr('data-share-owner', fileData.shareOwner);
}
return tr;
};
$('#fileList').on('fileActionsReady',function(){
var allShared = $('#fileList').find('[data-share-owner] [data-Action="Share"]');
allShared.addClass('permanent');
allShared.find('span').text(function(){
var $owner = $(this).closest('tr').attr('data-share-owner');
return ' ' + t('files_sharing', 'Shared by {owner}', {owner: $owner});
});
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');
}
});
FileActions.register('all', 'Share', OC.PERMISSION_READ, OC.imagePath('core', 'actions/share'), function(filename) {
var tr = FileList.findFileEl(filename);
var itemType = 'file';
if ($(tr).data('type') == 'dir') {
itemType = 'folder';
}
var possiblePermissions = $(tr).data('permissions');
var appendTo = $(tr).find('td.filename');
// Check if drop down is already visible for a different file
if (OC.Share.droppedDown) {
if ($(tr).data('id') != $('#dropdown').attr('data-item-source')) {
OC.Share.hideDropDown(function () {
$(tr).addClass('mouseOver');
OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions, filename);
});
} else {
OC.Share.hideDropDown();
}
} else {
$(tr).addClass('mouseOver');
OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions, filename);
}
});
}
});