]> source.dussan.org Git - nextcloud-server.git/commitdiff
merge master into interface
authorRobin Appelman <icewind1991@gmail.com>
Tue, 26 Jul 2011 14:14:20 +0000 (16:14 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Tue, 26 Jul 2011 14:16:47 +0000 (16:16 +0200)
1  2 
files/js/files.js

index 49e2f412d492021c8fbeb030e9cd6bf3d8133c77,7750842dd5a151e12239fef20d34f72f35b381c2..2f1ba907ba596845951ff77f246ea081e70a9bc5
@@@ -112,12 -107,8 +112,8 @@@ $(document).ready(function() 
                }
        });
        
--      $('.download').live('click',function(event) {
-               var files='';
-               $('td.filename input:checkbox:checked').parent().parent().each(function(i,element){
-                       files+=';'+$(element).attr('data-file');
-               });
-               files=files.substr(1);//remove leading ;
++      $('.download').click('click',function(event) {
+               var files=getSelectedFiles('name').join(';');
                
                //send the browser to the download location
                var dir=$('#dir').val()||'/';
                return false;
        });
        
 -      $('.delete').live('click',function(event) {
 +      $('.delete').click(function(event) {
-               var files='';
-               $('td.filename input:checkbox:checked').parent().parent().each(function(i,element){
-                       files+=';'+$(element).attr('data-file');
-               });
-               files=files.substr(1);//remove leading ;
+               var files=getSelectedFiles('name').join(';');
                
                $.ajax({
                        url: 'ajax/delete.php',
@@@ -326,49 -276,28 +318,75 @@@ var folderDropOptions=
        }
  }
  
 +function procesSelection(){
 +      var selectedFiles=$('tr[data-type="file"]>td.filename>input:checkbox:checked').parent().parent();
 +      var selectedFolders=$('tr[data-type="dir"]>td.filename>input:checkbox:checked').parent().parent();
 +      if(selectedFiles.length==0 && selectedFolders.length==0){
 +              $('#headerName>span.name').text('Name');
 +              $('#headerSize').text('Size (MB)');
 +              $('#selectedActions').hide();
 +      }else{
 +              $('#selectedActions').show();
 +              var totalSize=0;
 +              selectedFiles.each(function(){
 +                      totalSize+=parseInt($(this).attr('data-size'));
 +              });
 +              selectedFolders.each(function(){
 +                      totalSize+=parseInt($(this).attr('data-size'));
 +              });
 +              if(totalSize>0){
 +                      totalSize = Math.round(totalSize/(1024*102.4))/10;
 +                      if(totalSize < 0.1) {
 +                              totalSize='<0.1'; 
 +                      }else if(totalSize > 1000) {
 +                              totalSize= '>1000'; 
 +                      }
 +              }
 +              $('#headerSize').text(totalSize+' (MB)');
 +              var selection='';
 +              if(selectedFiles.length>0){
 +                      if(selectedFiles.length==1){
 +                              selection+='1 File';
 +                      }else{
 +                              selection+=selectedFiles.length+' Files';
 +                      }
 +                      if(selectedFolders.length>0){
 +                              selection+=' ,';
 +                      }
 +              }
 +              if(selectedFolders.length>0){
 +                      if(selectedFolders.length==1){
 +                              selection+='1 Folder';
 +                      }else{
 +                              selection+=selectedFolders.length+' Folders';
 +                      }
 +              }
 +              $('#headerName>span.name').text(selection+' Selected');
 +      }
++}
++
+ /**
+  * @brief get a list of selected files
+  * @param string property (option) the property of the file requested
+  * @return array
+  *
+  * possible values for property: name, mime
+  * if property is set, an array with that property for each file is returnd
+  * if it's ommited an array of objects with all properties is returned
+  */
+ function getSelectedFiles(property){
+       var elements=$('td.selection input:checkbox:checked').parent().parent();
+       var files=[];
+       elements.each(function(i,element){
+               var file={
+                       name:$(element).attr('data-file'),
+                                 mime:$(element).attr('data-mime')
+               };
+               if(property){
+                       files.push(file[property]);
+               }else{
+                       files.push();
+               }
+       });
+       return files;
  }