add getSelectedFiles() to files.js

This commit is contained in:
Robin Appelman 2011-07-25 20:24:59 +02:00
parent edec37b402
commit e03340b04d
1 changed files with 28 additions and 10 deletions

View File

@ -108,11 +108,7 @@ $(document).ready(function() {
}); });
$('.download').live('click',function(event) { $('.download').live('click',function(event) {
var files=''; var files=getSelectedFiles('name').join(';');
$('td.selection input:checkbox:checked').parent().parent().each(function(i,element){
files+=';'+$(element).attr('data-file');
});
files=files.substr(1);//remove leading ;
//send the browser to the download location //send the browser to the download location
var dir=$('#dir').val()||'/'; var dir=$('#dir').val()||'/';
@ -122,11 +118,7 @@ $(document).ready(function() {
}); });
$('.delete').live('click',function(event) { $('.delete').live('click',function(event) {
var files=''; var files=getSelectedFiles('name').join(';');
$('td.selection input:checkbox:checked').parent().parent().each(function(i,element){
files+=';'+$(element).attr('data-file');
});
files=files.substr(1);//remove leading ;
$.ajax({ $.ajax({
url: 'ajax/delete.php', url: 'ajax/delete.php',
@ -282,4 +274,30 @@ var folderDropOptions={
});} });}
}); });
} }
}
/**
* @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;
} }