some javascript changes

This commit is contained in:
Robin Appelman 2011-07-26 16:43:12 +02:00
parent 543bdb8ccd
commit b0f166fc83
2 changed files with 67 additions and 43 deletions

View File

@ -55,3 +55,22 @@ OC={
$('head').append(style); $('head').append(style);
} }
} }
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp*/) {
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in this) {
var val = this[i]; // in case fun mutates this
if (fun.call(thisp, val, i, this))
res.push(val);
}
}
return res;
};
}

View File

@ -4,31 +4,8 @@ $(document).ready(function() {
//drag/drop of files //drag/drop of files
$('#fileList tr td.filename').draggable(dragOptions); $('#fileList tr td.filename').draggable(dragOptions);
$('#fileList tr[data-type="dir"] td.filename').droppable(folderDropOptions); $('#fileList tr[data-type="dir"] td.filename').droppable(folderDropOptions);
$('div.crumb').droppable({ $('div.crumb').droppable(crumbDropOptions);
drop: function( event, ui ) { $('#plugins>ul>li:first-child').droppable(crumbDropOptions);
var file=ui.draggable.text().trim();
var target=$(this).attr('data-dir');
var dir=$('#dir').val();
while(dir.substr(0,1)=='/'){//remove extra leading /'s
dir=dir.substr(1);
}
dir='/'+dir;
if(dir.substr(-1,1)!='/'){
dir=dir+'/';
}
if(target==dir){
return;
}
$.ajax({
url: 'ajax/move.php',
data: "dir="+dir+"&file="+file+'&target='+target,
complete: function(data){boolOperationFinished(data, function(){
FileList.remove(file);
});}
});
},
tolerance: 'pointer'
});
// Sets the file-action buttons behaviour : // Sets the file-action buttons behaviour :
$('tr').live('mouseenter',function(event) { $('tr').live('mouseenter',function(event) {
@ -41,10 +18,10 @@ $(document).ready(function() {
// Sets the file link behaviour : // Sets the file link behaviour :
$('td.filename a').live('click',function(event) { $('td.filename a').live('click',function(event) {
event.preventDefault(); event.preventDefault();
var filename=$(this).parent().parent().attr('data-file'); var filename=$(this).parent().parent().data('file');
if(!FileList.isLoading(filename)){ if(!FileList.isLoading(filename)){
var mime=$(this).parent().parent().attr('data-mime'); var mime=$(this).parent().parent().data('mime');
var type=$(this).parent().parent().attr('data-type'); var type=$(this).parent().parent().data('type');
var action=FileActions.getDefault(mime,type); var action=FileActions.getDefault(mime,type);
if(action){ if(action){
action(filename); action(filename);
@ -131,7 +108,7 @@ $(document).ready(function() {
complete: function(data){ complete: function(data){
boolOperationFinished(data, function(){ boolOperationFinished(data, function(){
$('td.filename 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')); FileList.remove($(element).data('file'));
}); });
}); });
} }
@ -165,7 +142,7 @@ $(document).ready(function() {
if(response){ if(response){
for(var i=0;i<response.length;i++){ for(var i=0;i<response.length;i++){
var file=response[i]; var file=response[i];
$('tr[data-file="'+file.name+'"]').attr('data-mime',file.mime); $('tr[data-file="'+file.name+'"]').data('mime',file.mime);
if(size=='Pending'){ if(size=='Pending'){
$('tr[data-file='+file.name+'] td.filesize').text(file.size); $('tr[data-file='+file.name+'] td.filesize').text(file.size);
} }
@ -317,10 +294,36 @@ var folderDropOptions={
}); });
} }
} }
var crumbDropOptions={
drop: function( event, ui ) {
var file=ui.draggable.text().trim();
var target=$(this).data('dir');
var dir=$('#dir').val();
while(dir.substr(0,1)=='/'){//remove extra leading /'s
dir=dir.substr(1);
}
dir='/'+dir;
if(dir.substr(-1,1)!='/'){
dir=dir+'/';
}
if(target==dir){
return;
}
$.ajax({
url: 'ajax/move.php',
data: "dir="+dir+"&file="+file+'&target='+target,
complete: function(data){boolOperationFinished(data, function(){
FileList.remove(file);
});}
});
},
tolerance: 'pointer'
}
function procesSelection(){ function procesSelection(){
var selectedFiles=$('tr[data-type="file"]>td.filename>input:checkbox:checked').parent().parent(); var selected=getSelectedFiles();
var selectedFolders=$('tr[data-type="dir"]>td.filename>input:checkbox:checked').parent().parent(); var selectedFiles=selected.filter(function(el){return el.type=='file'});
var selectedFolders=selected.filter(function(el){return el.type=='dir'});
if(selectedFiles.length==0 && selectedFolders.length==0){ if(selectedFiles.length==0 && selectedFolders.length==0){
$('#headerName>span.name').text('Name'); $('#headerName>span.name').text('Name');
$('#headerSize').text('Size (MB)'); $('#headerSize').text('Size (MB)');
@ -328,12 +331,12 @@ function procesSelection(){
}else{ }else{
$('#selectedActions').show(); $('#selectedActions').show();
var totalSize=0; var totalSize=0;
selectedFiles.each(function(){ for(var i=0;i<selectedFiles.length;i++){
totalSize+=parseInt($(this).attr('data-size')); totalSize+=selectedFiles[i].size;
}); };
selectedFolders.each(function(){ for(var i=0;i<selectedFolders.length;i++){
totalSize+=parseInt($(this).attr('data-size')); totalSize+=selectedFolders[i].size;
}); };
if(totalSize>0){ if(totalSize>0){
totalSize = Math.round(totalSize/(1024*102.4))/10; totalSize = Math.round(totalSize/(1024*102.4))/10;
if(totalSize < 0.1) { if(totalSize < 0.1) {
@ -370,22 +373,24 @@ function procesSelection(){
* @param string property (option) the property of the file requested * @param string property (option) the property of the file requested
* @return array * @return array
* *
* possible values for property: name, mime * possible values for property: name, mime, size and type
* if property is set, an array with that property for each file is returnd * 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 * if it's ommited an array of objects with all properties is returned
*/ */
function getSelectedFiles(property){ function getSelectedFiles(property){
var elements=$('td.selection input:checkbox:checked').parent().parent(); var elements=$('td.filename input:checkbox:checked').parent().parent();
var files=[]; var files=[];
elements.each(function(i,element){ elements.each(function(i,element){
var file={ var file={
name:$(element).attr('data-file'), name:$(element).data('file'),
mime:$(element).attr('data-mime') mime:$(element).data('mime'),
type:$(element).data('type'),
size:$(element).data('size'),
}; };
if(property){ if(property){
files.push(file[property]); files.push(file[property]);
}else{ }else{
files.push(); files.push(file);
} }
}); });
return files; return files;