diff options
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/js/fileactions.js | 54 | ||||
-rw-r--r-- | apps/files/js/files.js | 5 | ||||
-rw-r--r-- | apps/files/templates/part.list.php | 3 |
3 files changed, 37 insertions, 25 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 4dc05088eed..d54dd466469 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -1,19 +1,28 @@ FileActions={ + PERMISSION_CREATE:4, + PERMISSION_READ:1, + PERMISSION_UPDATE:2, + PERMISSION_DELETE:8, + PERMISSION_SHARE:16, actions:{}, defaults:{}, icons:{}, currentFile:null, - register:function(mime,name,icon,action){ + register:function(mime,name,permissions,icon,action){ if(!FileActions.actions[mime]){ FileActions.actions[mime]={}; } - FileActions.actions[mime][name]=action; + if (!FileActions.actions[mime][name]) { + FileActions.actions[mime][name] = {}; + } + FileActions.actions[mime][name]['action'] = action; + FileActions.actions[mime][name]['permissions'] = permissions; FileActions.icons[name]=icon; }, setDefault:function(mime,name){ FileActions.defaults[mime]=name; }, - get:function(mime,type){ + get:function(mime,type,permissions){ var actions={}; if(FileActions.actions.all){ actions=$.extend( actions, FileActions.actions.all ) @@ -32,9 +41,15 @@ FileActions={ actions=$.extend( actions, FileActions.actions[type] ) } } - return actions; + var filteredActions = {}; + $.each(actions, function(name, action) { + if (action.permissions & permissions) { + filteredActions[name] = action.action; + } + }); + return filteredActions; }, - getDefault:function(mime,type){ + getDefault:function(mime,type,permissions){ if(mime){ var mimePart=mime.substr(0,mime.indexOf('/')); } @@ -48,22 +63,20 @@ FileActions={ }else{ name=FileActions.defaults.all; } - var actions=this.get(mime,type); + var actions=this.get(mime,type,permissions); return actions[name]; }, - display:function(parent, filename, type){ + display:function(parent){ FileActions.currentFile=parent; $('#fileList span.fileactions, #fileList td.date a.action').remove(); - var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType()); + var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions()); var file=FileActions.getCurrentFile(); if($('tr').filterAttr('data-file',file).data('renaming')){ return; } parent.children('a.name').append('<span class="fileactions" />'); - var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType()); + var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions()); for(name in actions){ - // no rename and share action for the 'Shared' dir - if((name=='Rename' || name =='Share') && type=='dir' && filename=='Shared') { continue; } if((name=='Download' || actions[name]!=defaultAction) && name!='Delete'){ var img=FileActions.icons[name]; if(img.call){ @@ -86,16 +99,12 @@ FileActions={ parent.find('a.name>span.fileactions').append(element); } } - if(actions['Delete'] && (type!='dir' || filename != 'Shared')){ // no delete action for the 'Shared' dir + if(actions['Delete']){ var img=FileActions.icons['Delete']; if(img.call){ img=img(file); } - if ($('#dir').val().indexOf('Shared') != -1) { - var html='<a href="#" original-title="' + t('files', 'Unshare') + '" class="action delete" style="display:none" />'; - } else { - var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />'; - } + var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />'; var element=$(html); if(img){ element.append($('<img src="'+img+'"/>')); @@ -131,6 +140,9 @@ FileActions={ }, getCurrentType:function(){ return FileActions.currentFile.parent().attr('data-type'); + }, + getCurrentPermissions:function() { + return FileActions.currentFile.parent().data('permissions'); } } @@ -140,12 +152,12 @@ $(document).ready(function(){ } else { var downloadScope = 'file'; } - FileActions.register(downloadScope,'Download',function(){return OC.imagePath('core','actions/download')},function(filename){ + FileActions.register(downloadScope,'Download', FileActions.PERMISSION_READ, function(){return OC.imagePath('core','actions/download')},function(filename){ window.location=OC.filePath('files', 'ajax', 'download.php') + encodeURIComponent('?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val())); }); }); -FileActions.register('all','Delete',function(){return OC.imagePath('core','actions/delete')},function(filename){ +FileActions.register('all','Delete', FileActions.PERMISSION_DELETE, function(){return OC.imagePath('core','actions/delete')},function(filename){ if(Files.cancelUpload(filename)) { if(filename.substr){ filename=[filename]; @@ -162,11 +174,11 @@ FileActions.register('all','Delete',function(){return OC.imagePath('core','actio } }); -FileActions.register('all','Rename',function(){return OC.imagePath('core','actions/rename')},function(filename){ +FileActions.register('all','Rename', FileActions.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/rename')},function(filename){ FileList.rename(filename); }); -FileActions.register('dir','Open','',function(filename){ +FileActions.register('dir','Open', FileActions.PERMISSION_READ, '', function(filename){ window.location=OC.linkTo('files', 'index.php') + '&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8d52b742c1b..2f06f15f896 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -56,7 +56,7 @@ $(document).ready(function() { // Sets the file-action buttons behaviour : $('tr').live('mouseenter',function(event) { - FileActions.display($(this).children('td.filename'), $(this).attr('data-file'), $(this).attr('data-type')); + FileActions.display($(this).children('td.filename')); }); $('tr').live('mouseleave',function(event) { FileActions.hide(); @@ -106,7 +106,8 @@ $(document).ready(function() { if(!renaming && !FileList.isLoading(filename)){ var mime=$(this).parent().parent().data('mime'); var type=$(this).parent().parent().data('type'); - var action=FileActions.getDefault(mime,type); + var permissions = $(this).parent().parent().data('permissions'); + var action=FileActions.getDefault(mime,type, permissions); if(action){ action(filename); } diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 4506630c16d..6667b5488af 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -1,5 +1,4 @@ <?php foreach($_['files'] as $file): - $write = ($file['writable']) ? 'true' : 'false'; $simple_file_size = OCP\simple_file_size($file['size']); $simple_size_color = intval(200-$file['size']/(1024*1024)*2); // the bigger the file, the darker the shade of grey; megabytes*2 if($simple_size_color<0) $simple_size_color = 0; @@ -10,7 +9,7 @@ $name = str_replace('%2F','/', $name); $directory = str_replace('+','%20',urlencode($file['directory'])); $directory = str_replace('%2F','/', $directory); ?> - <tr data-file="<?php echo $name;?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>' data-write='<?php echo $write;?>'> + <tr data-file="<?php echo $name;?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>' data-permissions='<?php echo $file['permissions']; ?>'> <td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo OCP\mimetype_icon('dir'); else echo OCP\mimetype_icon($file['mimetype']); ?>)"> <?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" /><?php } ?> <a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseURL'].$directory.'/'.$name; else echo $_['downloadURL'].$directory.'/'.$name; ?>" title=""> |