attempt to manage some special chars in file list

Added a jquery function to filter by attributes.
Add more logging in rename file
Use the new function to avoid errors
This commit is contained in:
Brice Maron 2011-11-01 22:35:13 +01:00
parent e533e82bc9
commit c7d1737d47
7 changed files with 56 additions and 31 deletions

View file

@ -10,7 +10,7 @@ $(document).ready(function() {
type: 'GET',
url: OC.linkTo('files_sharing', 'ajax/getitem.php'),
dataType: 'json',
data: 'source='+file,
data: {source: file},
async: false,
success: function(users) {
if (users) {
@ -184,8 +184,8 @@ function createDropdown(filename, files) {
html += '<input id="link" style="display:none; width:90%;" />';
html += '</div>';
if (filename) {
$('tr[data-file="'+filename+'"]').addClass('mouseOver');
$(html).appendTo($('tr[data-file="'+filename+'"] td.filename'));
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
$(html).appendTo($('tr').filterAttr('data-file',filename).find('td.filename'));
} else {
$(html).appendTo($('thead .share'));
}

View file

@ -401,3 +401,10 @@ if (!Array.prototype.map){
return res;
};
}
/**
* Filter Jquery selector by attribute value
**/
$.fn.filterAttr = function(attr_name, attr_value) {
return this.filter(function() { return $(this).attr(attr_name) === attr_value; });
};

View file

@ -56,7 +56,7 @@ FileActions={
$('#fileList .action').remove();
var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType());
var file=FileActions.getCurrentFile();
if($('tr[data-file="'+file+'"]').data('renaming')){
if($('tr').filterAttr('data-file',file).data('renaming')){
return;
}
var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType());

View file

@ -4,7 +4,7 @@ FileList={
},
addFile:function(name,size,lastModified,loading){
var img=(loading)?OC.imagePath('core', 'loading.gif'):OC.imagePath('core', 'filetypes/file.png');
var html='<tr data-file="'+name+'" data-type="file" data-size="'+size+'">';
var html='<tr data-type="file" data-size="'+size+'">';
if(name.indexOf('.')!=-1){
var basename=name.substr(0,name.lastIndexOf('.'));
var extention=name.substr(name.lastIndexOf('.'));
@ -29,16 +29,21 @@ FileList={
html+='<td class="filesize" title="'+humanFileSize(size)+'" style="color:rgb('+sizeColor+','+sizeColor+','+sizeColor+')">'+simpleSize+'</td>';
html+='<td class="date"><span class="modified" title="'+formatDate(lastModified)+'" style="color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')">'+relative_modified_date(lastModified.getTime() / 1000)+'</span></td>';
html+='</tr>';
FileList.insertElement(name,'file',$(html));
FileList.insertElement(name,'file',$(html).attr('data-file',name));
if(loading){
$('tr[data-file="'+name+'"]').data('loading',true);
$('tr').filterAttr('data-file',name).data('loading',true);
}else{
$('tr[data-file="'+name+'"] td.filename').draggable(dragOptions);
$('tr').filterAttr('data-file',name).find('td.filename').draggable(dragOptions);
}
},
addDir:function(name,size,lastModified){
var html='<tr data-file="'+name+'" data-type="dir" data-size="'+size+'">';
html+='<td class="filename" style="background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')"><input type="checkbox" /><a class="name" href="index.php?dir='+$('#dir').val()+'/'+name+'">'+name+'</a></td>';
html = $('<tr></tr>').attr({ "data-type": "dir", "data-size": size, "data-file": name});
td = $('<td></td>').attr({"class": "filename", "style": 'background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')' });
td.append('<input type="checkbox" />');
var link_elem = $('<a></a>').attr({ "class": "name", "href": "index.php?dir="+ encodeURIComponent($('#dir').val()+'/'+name) });
link_elem.append($('<span></span>').addClass('nametext').text(name));
td.append(link_elem);
html.append(td);
if(size!='Pending'){
simpleSize=simpleFileSize(size);
}else{
@ -47,13 +52,15 @@ FileList={
sizeColor = Math.round(200-Math.pow((size/(1024*1024)),2));
lastModifiedTime=Math.round(lastModified.getTime() / 1000);
modifiedColor=Math.round((Math.round((new Date()).getTime() / 1000)-lastModifiedTime)/60/60/24*5);
html+='<td class="filesize" title="'+humanFileSize(size)+'" style="color:rgb('+sizeColor+','+sizeColor+','+sizeColor+')">'+simpleSize+'</td>';
html+='<td class="date"><span class="modified" title="'+formatDate(lastModified)+'" style="color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')">'+relative_modified_date(lastModified.getTime() / 1000)+'</span></td>';
html+='</tr>';
td = $('<td></td>').attr({ "class": "filesize", "title": humanFileSize(size), "style": 'color:rgb('+sizeColor+','+sizeColor+','+sizeColor+')'}).text(simpleSize);
html.append(td);
FileList.insertElement(name,'dir',$(html));
$('tr[data-file="'+name+'"] td.filename').draggable(dragOptions);
$('tr[data-file="'+name+'"] td.filename').droppable(folderDropOptions);
td = $('<td></td>').attr({ "class": "date" });
td.append($('<span></span>').attr({ "class": "modified", "title": formatDate(lastModified), "style": 'color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')' }).text( relative_modified_date(lastModified.getTime() / 1000) ));
html.append(td);
FileList.insertElement(name,'dir',html);
$('tr').filterAttr('data-file',name).find('td.filename').draggable(dragOptions);
$('tr').filterAttr('data-file',name).find('td.filename').droppable(folderDropOptions);
},
refresh:function(data) {
result = jQuery.parseJSON(data.responseText);
@ -64,8 +71,8 @@ FileList={
resetFileActionPanel();
},
remove:function(name){
$('tr[data-file="'+name+'"] td.filename').draggable('destroy');
$('tr[data-file="'+name+'"]').remove();
$('tr').filterAttr('data-file',name).find('td.filename').draggable('destroy');
$('tr').filterAttr('data-file',name).remove();
if($('tr[data-file]').length==0){
$('#emptyfolder').show();
$('.file_upload_filename').addClass('highlight');
@ -101,7 +108,7 @@ FileList={
$('.file_upload_filename').removeClass('highlight');
},
loadingDone:function(name){
var tr=$('tr[data-file="'+name+'"]');
var tr=$('tr').filterAttr('data-file',name);
tr.data('loading',false);
var mime=tr.data('mime');
tr.attr('data-mime',mime);
@ -111,13 +118,13 @@ FileList={
tr.find('td.filename').draggable(dragOptions);
},
isLoading:function(name){
return $('tr[data-file="'+name+'"]').data('loading');
return $('tr').filterAttr('data-file',name).data('loading');
},
rename:function(name){
var tr=$('tr[data-file="'+name+'"]');
var tr=$('tr').filterAttr('data-file',name);
tr.data('renaming',true);
var td=tr.children('td.filename');
var input=$('<input value="'+name+'" class="filename"></input>');
var input=$('<input class="filename"></input>').val(name);
var form=$('<form action="#"></form>')
form.append(input);
td.children('a.name').text('');
@ -143,7 +150,7 @@ FileList={
}
$.ajax({
url: 'ajax/rename.php',
data: "dir="+$('#dir').val()+"&newname="+encodeURIComponent(newname)+"&file="+encodeURIComponent(name)
data: { dir : $('#dir').val(), newname: newname, file: name }
});
});
form.click(function(event){
@ -165,9 +172,10 @@ FileList={
files=[files];
}
$.each(files,function(index,file){
$('tr[data-file="'+file+'"]').hide();
$('tr[data-file="'+file+'"]').find('input[type="checkbox"]').removeAttr('checked');
$('tr[data-file="'+file+'"]').removeClass('selected');
var files = $('tr').filterAttr('data-file',file);
files.hide();
files.find('input[type="checkbox"]').removeAttr('checked');
files.removeClass('selected');
});
procesSelection();
FileList.deleteCanceled=false;
@ -208,7 +216,7 @@ $(document).ready(function(){
if($('#notification').data('deletefile'))
{
$.each(FileList.deleteFiles,function(index,file){
$('tr[data-file="'+file+'"]').show();
$('tr').filterAttr('data-file',file).show();
// alert(file);
});
FileList.deleteCanceled=true;

View file

@ -1,4 +1,9 @@
$(document).ready(function() {
$('#fileList tr').each(function(){
//little hack to set unescape filenames in attribute
$(this).attr('data-file',unescape($(this).data('file')));
});
if($('tr[data-file]').length==0){
$('.file_upload_filename').addClass('highlight');
}
@ -185,9 +190,9 @@ $(document).ready(function() {
if(response[0] != undefined && response[0].status == 'success'){
for(var i=0;i<response.length;i++){
var file=response[i];
$('tr[data-file="'+file.name+'"]').data('mime',file.mime);
$('tr').filterAttr('data-file',file.name).data('mime',file.mime);
if(size=='Pending'){
$('tr[data-file='+file.name+'] td.filesize').text(file.size);
$('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size);
}
FileList.loadingDone(file.name);
}
@ -343,7 +348,7 @@ var folderDropOptions={
url: 'ajax/move.php',
data: "dir="+dir+"&file="+file+'&target='+dir+'/'+target,
complete: function(data){boolOperationFinished(data, function(){
var el=$('#fileList tr[data-file="'+file+'"] td.filename');
var el = $('#fileList tr').filterAttr('data-file',file).find('td.filename');
el.draggable('destroy');
FileList.remove(file);
});}

View file

@ -5,7 +5,7 @@
$relative_modified_date = relative_modified_date($file['mtime']);
$relative_date_color = round((time()-$file['mtime'])/60/60/24*14); // the older the file, the brighter the shade of grey; days*14
if($relative_date_color>200) $relative_date_color = 200; ?>
<tr data-file="<?php echo $file['name'];?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mime']?>" data-size='<?php echo $file['size'];?>'>
<tr data-file="<?php echo urlencode($file['name']);?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mime']?>" data-size='<?php echo $file['size'];?>'>
<td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo mimetype_icon('dir'); else echo mimetype_icon($file['mime']); ?>)">
<?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" /><?php } ?>
<a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseURL'].$file['directory'].'/'.$file['name']; else echo $_['downloadURL'].urlencode($file['directory']).'/'.urlencode($file['name']); ?>" title="">

View file

@ -84,6 +84,11 @@ class OC_Filestorage_Local extends OC_Filestorage{
return $return;
}
public function rename($path1,$path2){
if(! $this->file_exists($path1)){
OC_Log::write('core','unable to rename, file does not exists : '.$path1,OC_Log::ERROR);
return false;
}
if($return=rename($this->datadir.$path1,$this->datadir.$path2)){
$this->clearFolderSizeCache($path1);
$this->clearFolderSizeCache($path2);