diff options
Diffstat (limited to 'files/js/fileactions.js')
-rw-r--r-- | files/js/fileactions.js | 100 |
1 files changed, 76 insertions, 24 deletions
diff --git a/files/js/fileactions.js b/files/js/fileactions.js index b683dc0cd3a..359e54dda3c 100644 --- a/files/js/fileactions.js +++ b/files/js/fileactions.js @@ -1,11 +1,14 @@ FileActions={ actions:{}, defaults:{}, - register:function(mime,name,action){ + icons:{}, + currentFile:null, + register:function(mime,name,icon,action){ if(!FileActions.actions[mime]){ FileActions.actions[mime]={}; } FileActions.actions[mime][name]=action; + FileActions.icons[name]=icon; }, setDefault:function(mime,name){ FileActions.defaults[mime]=name; @@ -49,56 +52,105 @@ FileActions={ return actions[name]; }, display:function(parent){ - $('#file_menu ul').empty(); - parent.append($('#file_menu')); + FileActions.currentFile=parent; var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType()); + var file=FileActions.getCurrentFile(); + if($('tr[data-file="'+file+'"]').data('renaming')){ + return; + } + var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType()); for(name in actions){ - var html='<li><a href="" alt="'+name+'">'+name+'</a></li>'; + if((name=='Download' || actions[name]!=defaultAction) && name!='Delete'){ + var img=FileActions.icons[name]; + var html='<a href="#" title="'+name+'" class="file_action"/>'; + var element=$(html); + if(img){ + element.append($('<img src="'+img+'"/>')); + } + element.data('action',name); + element.click(function(event){ + event.stopPropagation(); + event.preventDefault(); + var action=actions[$(this).data('action')]; + var currentFile=FileActions.getCurrentFile(); + FileActions.hide(); + action(currentFile); + }); + parent.children('a.name').append(element); + } + } + if(actions['Delete']){ + var img=FileActions.icons['Delete']; + var html='<a href="#" title="Delete" class="file_action"/>'; var element=$(html); - element.data('action',name); + if(img){ + element.append($('<img src="'+img+'"/>')); + } + element.data('action','Delete'); element.click(function(event){ + event.stopPropagation(); event.preventDefault(); - $('#file_menu').slideToggle(250); var action=actions[$(this).data('action')]; - $('#file_menu ul').empty(); - action(FileActions.getCurrentFile()); + var currentFile=FileActions.getCurrentFile(); + FileActions.hide(); + action(currentFile); }); - $('#file_menu>ul').append(element); + parent.parent().children().last().append(element); } - $('#file_menu').slideToggle(250); return false; }, + hide:function(){ + $('.file_action').remove(); + }, getCurrentFile:function(){ - return $('#file_menu').parents('tr:first').attr('data-file'); + return FileActions.currentFile.parent().attr('data-file'); }, getCurrentMimeType:function(){ - return $('#file_menu').parents('tr:first').attr('data-mime'); + return FileActions.currentFile.parent().attr('data-mime'); }, getCurrentType:function(){ - return $('#file_menu').parents('tr:first').attr('data-type'); + return FileActions.currentFile.parent().attr('data-type'); } } -FileActions.register('all','Download',function(filename){ +FileActions.register('all','Download',OC.imagePath('core','actions/download'),function(filename){ window.location='ajax/download.php?files='+filename+'&dir='+$('#dir').val(); }); -FileActions.register('all','Delete',function(filename){ - $.ajax({ - url: 'ajax/delete.php', - data: "dir="+encodeURIComponent($('#dir').val())+"&file="+encodeURIComponent(filename), - complete: function(data){ - boolOperationFinished(data, function(){ - FileList.remove(filename); - }); +FileActions.register('all','Delete',OC.imagePath('core','actions/delete'),function(filename){ + $( "#delete-confirm" ).dialog({ + resizable: false, + height:200, + title:"Delete "+filename, + modal: true, + buttons: { + "Delete": function() { + $( this ).dialog( "close" ); + $.ajax({ + url: 'ajax/delete.php', + data: "dir="+encodeURIComponent($('#dir').val())+"&file="+encodeURIComponent(filename), + complete: function(data){ + boolOperationFinished(data, function(){ + FileList.remove(filename); + }); + } + }); + }, + Cancel: function() { + $( this ).dialog( "close" ); + } } }); }); +FileActions.register('all','Rename',OC.imagePath('core','actions/rename'),function(filename){ + FileList.rename(filename); +}); + FileActions.setDefault('all','Download'); -FileActions.register('dir','Open',function(filename){ +FileActions.register('dir','Open','',function(filename){ window.location='index.php?dir='+$('#dir').val()+'/'+filename; }); -FileActions.setDefault('dir','Open');
\ No newline at end of file +FileActions.setDefault('dir','Open'); |