diff options
Diffstat (limited to 'files/js/files.js')
-rw-r--r-- | files/js/files.js | 177 |
1 files changed, 133 insertions, 44 deletions
diff --git a/files/js/files.js b/files/js/files.js index d4191215972..49e2f412d49 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -31,11 +31,13 @@ $(document).ready(function() { }); // Sets the file-action buttons behaviour : - $('td.fileaction a').live('click',function(event) { - event.preventDefault(); - FileActions.display($(this).parent()); + $('tr').live('mouseenter',function(event) { + FileActions.display($(this).children('td.filename')); }); - + $('tr').live('mouseleave',function(event) { + FileActions.hide(); + }); + // Sets the file link behaviour : $('td.filename a').live('click',function(event) { event.preventDefault(); @@ -54,24 +56,27 @@ $(document).ready(function() { $('#select_all').click(function() { if($(this).attr('checked')){ // Check all - $('td.selection input:checkbox').attr('checked', true); - $('td.selection input:checkbox').parent().parent().addClass('selected'); + $('td.filename input:checkbox').attr('checked', true); + $('td.filename input:checkbox').parent().parent().addClass('selected'); }else{ // Uncheck all - $('td.selection input:checkbox').attr('checked', false); - $('td.selection input:checkbox').parent().parent().removeClass('selected'); + $('td.filename input:checkbox').attr('checked', false); + $('td.filename input:checkbox').parent().parent().removeClass('selected'); } + procesSelection(); }); - $('td.selection input:checkbox').live('click',function() { + $('td.filename input:checkbox').live('click',function() { + var selectedCount=$('td.filename input:checkbox:checked').length; $(this).parent().parent().toggleClass('selected'); if(!$(this).attr('checked')){ $('#select_all').attr('checked',false); }else{ - if($('td.selection input:checkbox:checked').length==$('td.selection input:checkbox').length){ + if(selectedCount==$('td.filename input:checkbox').length){ $('#select_all').attr('checked',true); } } + procesSelection(); }); $('#file_newfolder_form').submit(function(event) { @@ -109,7 +114,7 @@ $(document).ready(function() { $('.download').live('click',function(event) { var files=''; - $('td.selection input:checkbox:checked').parent().parent().each(function(i,element){ + $('td.filename input:checkbox:checked').parent().parent().each(function(i,element){ files+=';'+$(element).attr('data-file'); }); files=files.substr(1);//remove leading ; @@ -121,9 +126,9 @@ $(document).ready(function() { return false; }); - $('.delete').live('click',function(event) { + $('.delete').click(function(event) { var files=''; - $('td.selection input:checkbox:checked').parent().parent().each(function(i,element){ + $('td.filename input:checkbox:checked').parent().parent().each(function(i,element){ files+=';'+$(element).attr('data-file'); }); files=files.substr(1);//remove leading ; @@ -133,7 +138,7 @@ $(document).ready(function() { data: "dir="+$('#dir').val()+"&files="+encodeURIComponent(files), complete: function(data){ boolOperationFinished(data, function(){ - $('td.selection input:checkbox:checked').parent().parent().each(function(i,element){ + $('td.filename input:checkbox:checked').parent().parent().each(function(i,element){ FileList.remove($(element).attr('data-file')); }); }); @@ -148,46 +153,83 @@ $(document).ready(function() { var uploadId=form.attr('data-upload-id'); var files=this.files; var target=form.children('iframe'); - target.load(function(){ - var response=jQuery.parseJSON(target.contents().find('body').text()); - //set mimetype and if needed filesize - if(response){ - for(var i=0;i<response.length;i++){ - var file=response[i]; - $('tr[data-file="'+file.name+'"]').attr('data-mime',file.mime); - if(size=='Pending'){ - $('tr[data-file='+file.name+'] td.filesize').text(file.size); + var totalSize=0; + for(var i=0;i<files.length;i++){ + totalSize+=files[i].size; + } + if(totalSize>$('#max_upload').val()){ + $( "#uploadsize-message" ).dialog({ + modal: true, + buttons: { + Close: function() { + $( this ).dialog( "close" ); } - FileList.loadingDone(file.name); } + }); + }else{ + target.load(function(){ + var response=jQuery.parseJSON(target.contents().find('body').text()); + //set mimetype and if needed filesize + if(response){ + for(var i=0;i<response.length;i++){ + var file=response[i]; + $('tr[data-file="'+file.name+'"]').attr('data-mime',file.mime); + if(size=='Pending'){ + $('tr[data-file='+file.name+'] td.filesize').text(file.size); + } + FileList.loadingDone(file.name); + } + } + }); + form.submit(); + var date=new Date(); + var uploadTime=formatDate(date); + for(var i=0;i<files.length;i++){ + if(files[i].size>0){ + var size=simpleFileSize(files[i].size); + }else{ + var size='Pending'; + } + FileList.addFile(files[i].name,size,uploadTime,true); } - }); - form.submit(); - var date=new Date(); - var uploadTime=formatDate(date); - for(var i=0;i<files.length;i++){ - if(files[i].size>0){ - var size=simpleFileSize(files[i].size); - }else{ - var size='Pending'; - } - FileList.addFile(files[i].name,size,uploadTime,true); + + //clone the upload form and hide the new one to allow users to start a new upload while the old one is still uploading + var clone=form.clone(); + uploadId++; + clone.attr('data-upload-id',uploadId); + clone.attr('target','file_upload_target_'+uploadId); + clone.children('iframe').attr('name','file_upload_target_'+uploadId) + clone.insertBefore(form); + form.hide(); } - - //clone the upload form and hide the new one to allow users to start a new upload while the old one is still uploading - var clone=form.clone(); - uploadId++; - clone.attr('data-upload-id',uploadId); - clone.attr('target','file_upload_target_'+uploadId); - clone.children('iframe').attr('name','file_upload_target_'+uploadId) - clone.insertBefore(form); - form.hide(); }); //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) if(navigator.userAgent.search(/konqueror/i)==-1){ $('.file_upload_start').attr('multiple','multiple') } + + //if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder + var crumb=$('div.crumb').first(); + while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){ + crumb.children('a').text('...'); + crumb=crumb.next('div.crumb'); + } + //if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent + var crumb=$('div.crumb').first(); + var next=crumb.next('div.crumb'); + while($('div.controls').height()>40 && next.next('div.crumb').length>0){ + crumb.remove(); + crumb=next; + next=crumb.next('div.crumb'); + } + //still not enough, start shorting down the current folder name + var crumb=$('div.crumb>a').last(); + while($('div.controls').height()>40 && crumb.text().length>6){ + var text=crumb.text() + text=text.substr(0,text.length-6)+'...'; + crumb.text(text); + } }); var adjustNewFolderSize = function() { @@ -282,4 +324,51 @@ 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'); + } }
\ No newline at end of file |