aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js/fileactions.js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/js/fileactions.js')
-rw-r--r--apps/files/js/fileactions.js54
1 files changed, 33 insertions, 21 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);
});