2011-06-04 20:44:14 +04:00
|
|
|
FileList={
|
|
|
|
update:function(fileListHtml) {
|
|
|
|
$('#fileList').empty().html(fileListHtml);
|
|
|
|
},
|
2011-07-19 22:57:40 +04:00
|
|
|
addFile:function(name,size,lastModified,loading){
|
2011-08-12 13:51:44 +04:00
|
|
|
var img=(loading)?OC.imagePath('core', 'loading.gif'):OC.imagePath('core', 'filetypes/file');
|
2011-07-29 04:33:58 +04:00
|
|
|
var html='<tr data-file="'+name+'" data-type="file" data-size="'+size+'">';
|
2011-07-29 01:52:49 +04:00
|
|
|
if(name.indexOf('.')!=-1){
|
2011-08-28 23:39:17 +04:00
|
|
|
var basename=name.substr(0,name.lastIndexOf('.'));
|
2011-08-25 04:34:27 +04:00
|
|
|
var extention=name.substr(name.lastIndexOf('.'));
|
2011-07-29 01:52:49 +04:00
|
|
|
}else{
|
|
|
|
var basename=name;
|
|
|
|
var extention=false;
|
|
|
|
}
|
2011-08-02 05:17:26 +04:00
|
|
|
html+='<td class="filename" style="background-image:url('+img+')"><input type="checkbox" />';
|
|
|
|
html+='<a class="name" href="download.php?file='+$('#dir').val()+'/'+name+'"><span class="nametext">'+basename
|
2011-07-29 01:52:49 +04:00
|
|
|
if(extention){
|
|
|
|
html+='<span class="extention">'+extention+'</span>';
|
|
|
|
}
|
|
|
|
html+='</span></a></td>';
|
|
|
|
if(size!='Pending'){
|
|
|
|
simpleSize=simpleFileSize(size);
|
|
|
|
}else{
|
|
|
|
simpleSize='Pending';
|
|
|
|
}
|
2011-07-30 17:42:34 +04:00
|
|
|
sizeColor = Math.round(200-size/(1024*1024)*2);
|
2011-07-29 03:10:08 +04:00
|
|
|
lastModifiedTime=Math.round(lastModified.getTime() / 1000);
|
2011-07-30 17:31:11 +04:00
|
|
|
modifiedColor=Math.round((Math.round((new Date()).getTime() / 1000)-lastModifiedTime)/60/60/24*14);
|
2011-07-29 01:52:49 +04:00
|
|
|
html+='<td class="filesize" title="'+humanFileSize(size)+'" style="color:rgb('+sizeColor+','+sizeColor+','+sizeColor+')">'+simpleSize+'</td>';
|
2011-07-29 03:10:08 +04:00
|
|
|
html+='<td class="date" title="'+formatDate(lastModified)+'" style="color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')">'+relative_modified_date(lastModified.getTime() / 1000)+'</td>';
|
2011-06-04 20:44:14 +04:00
|
|
|
html+='</tr>';
|
|
|
|
FileList.insertElement(name,'file',$(html));
|
2011-07-19 22:57:40 +04:00
|
|
|
if(loading){
|
|
|
|
$('tr[data-file="'+name+'"]').data('loading',true);
|
|
|
|
}else{
|
|
|
|
$('tr[data-file="'+name+'"] td.filename').draggable(dragOptions);
|
|
|
|
}
|
2011-06-04 20:44:14 +04:00
|
|
|
},
|
|
|
|
addDir:function(name,size,lastModified){
|
2011-07-29 04:33:58 +04:00
|
|
|
var html='<tr data-file="'+name+'" data-type="dir" data-size="'+size+'">';
|
2011-08-12 13:51:44 +04:00
|
|
|
html+='<td class="filename" style="background-image:url('+OC.imagePath('core', 'places/folder')+')"><input type="checkbox" /><a class="name" href="index.php?dir='+$('#dir').val()+'/'+name+'">'+name+'</a></td>';
|
2011-07-29 03:10:08 +04:00
|
|
|
if(size!='Pending'){
|
|
|
|
simpleSize=simpleFileSize(size);
|
|
|
|
}else{
|
|
|
|
simpleSize='Pending';
|
|
|
|
}
|
|
|
|
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" title="'+formatDate(lastModified)+'" style="color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')">'+relative_modified_date(lastModified.getTime() / 1000)+'</td>';
|
2011-06-04 20:44:14 +04:00
|
|
|
html+='</tr>';
|
2011-08-23 13:45:28 +04:00
|
|
|
|
2011-06-04 20:44:14 +04:00
|
|
|
FileList.insertElement(name,'dir',$(html));
|
2011-07-07 23:43:35 +04:00
|
|
|
$('tr[data-file="'+name+'"] td.filename').draggable(dragOptions);
|
|
|
|
$('tr[data-file="'+name+'"] td.filename').droppable(folderDropOptions);
|
2011-06-04 20:44:14 +04:00
|
|
|
},
|
|
|
|
refresh:function(data) {
|
|
|
|
result = jQuery.parseJSON(data.responseText);
|
|
|
|
if(typeof(result.data.breadcrumb) != 'undefined'){
|
|
|
|
updateBreadcrumb(result.data.breadcrumb);
|
|
|
|
}
|
|
|
|
FileList.update(result.data.files);
|
|
|
|
resetFileActionPanel();
|
|
|
|
},
|
|
|
|
remove:function(name){
|
2011-07-07 23:43:35 +04:00
|
|
|
$('tr[data-file="'+name+'"] td.filename').draggable('destroy');
|
2011-06-04 20:44:14 +04:00
|
|
|
$('tr[data-file="'+name+'"]').remove();
|
2011-07-30 16:42:58 +04:00
|
|
|
if($('tr[data-file]').length==0){
|
|
|
|
$('#emptyfolder').show();
|
|
|
|
$('.file_upload_filename').addClass('highlight');
|
|
|
|
}
|
2011-06-04 20:44:14 +04:00
|
|
|
},
|
|
|
|
insertElement:function(name,type,element){
|
|
|
|
//find the correct spot to insert the file or folder
|
|
|
|
var fileElements=$('tr[data-file][data-type="'+type+'"]');
|
|
|
|
var pos;
|
|
|
|
if(name.localeCompare($(fileElements[0]).attr('data-file'))<0){
|
2011-07-26 18:55:28 +04:00
|
|
|
pos=-1;
|
2011-06-04 20:44:14 +04:00
|
|
|
}else if(name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file'))>0){
|
|
|
|
pos=fileElements.length-1;
|
|
|
|
}else{
|
2011-07-26 18:55:28 +04:00
|
|
|
for(var pos=0;pos<fileElements.length-1;pos++){
|
2011-06-04 20:44:14 +04:00
|
|
|
if(name.localeCompare($(fileElements[pos]).attr('data-file'))>0 && name.localeCompare($(fileElements[pos+1]).attr('data-file'))<0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-04 23:46:20 +04:00
|
|
|
if(fileElements.length){
|
2011-07-26 18:55:28 +04:00
|
|
|
if(pos==-1){
|
|
|
|
$(fileElements[0]).before(element);
|
|
|
|
}else{
|
|
|
|
$(fileElements[pos]).after(element);
|
|
|
|
}
|
|
|
|
}else if(type=='dir' && $('tr[data-file]').length>0){
|
|
|
|
$('tr[data-file]').first().before(element);
|
2011-07-04 23:46:20 +04:00
|
|
|
}else{
|
|
|
|
$('#fileList').append(element);
|
|
|
|
}
|
2011-07-30 16:42:58 +04:00
|
|
|
$('#emptyfolder').hide();
|
|
|
|
$('.file_upload_filename').removeClass('highlight');
|
2011-07-19 22:57:40 +04:00
|
|
|
},
|
|
|
|
loadingDone:function(name){
|
|
|
|
$('tr[data-file="'+name+'"]').data('loading',false);
|
2011-07-29 03:36:31 +04:00
|
|
|
var mime=$('tr[data-file="'+name+'"]').data('mime');
|
2011-08-02 05:17:26 +04:00
|
|
|
$('tr[data-file="'+name+'"] td.filename').attr('style','background-image:url('+getMimeIcon(mime)+')');
|
2011-07-19 22:57:40 +04:00
|
|
|
$('tr[data-file="'+name+'"] td.filename').draggable(dragOptions);
|
|
|
|
},
|
|
|
|
isLoading:function(name){
|
|
|
|
return $('tr[data-file="'+name+'"]').data('loading');
|
2011-07-29 01:04:34 +04:00
|
|
|
},
|
|
|
|
rename:function(name){
|
|
|
|
var tr=$('tr[data-file="'+name+'"]');
|
2011-07-29 04:26:20 +04:00
|
|
|
tr.data('renaming',true);
|
2011-07-29 01:04:34 +04:00
|
|
|
var td=tr.children('td.filename');
|
2011-08-08 20:05:39 +04:00
|
|
|
var input=$('<input value="'+name+'" class="filename"></input>');
|
2011-07-29 01:04:34 +04:00
|
|
|
var form=$('<form action="#"></form>')
|
|
|
|
form.append(input);
|
|
|
|
td.children('a.name').text('');
|
|
|
|
td.children('a.name').append(form)
|
|
|
|
input.focus();
|
|
|
|
form.submit(function(event){
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2011-07-29 19:51:17 +04:00
|
|
|
var newname=input.val();
|
|
|
|
tr.data('renaming',false);
|
2011-07-29 01:04:34 +04:00
|
|
|
tr.attr('data-file',newname);
|
|
|
|
td.children('a.name').empty();
|
2011-07-29 04:17:40 +04:00
|
|
|
if(newname.indexOf('.')>0){
|
2011-08-25 04:34:27 +04:00
|
|
|
basename=newname.substr(0,newname.lastIndexOf('.'));
|
2011-07-29 04:17:40 +04:00
|
|
|
}else{
|
|
|
|
basename=newname;
|
|
|
|
}
|
2011-07-29 19:51:17 +04:00
|
|
|
var span=$('<span class="nametext"></span>');
|
|
|
|
span.text(basename);
|
|
|
|
td.children('a.name').append(span);
|
2011-07-29 04:17:40 +04:00
|
|
|
if(newname.indexOf('.')>0){
|
2011-08-25 04:34:27 +04:00
|
|
|
span.append($('<span class="extention">'+newname.substr(newname.lastIndexOf('.'))+'</span>'));
|
2011-07-29 04:17:40 +04:00
|
|
|
}
|
2011-07-29 01:04:34 +04:00
|
|
|
$.ajax({
|
|
|
|
url: 'ajax/rename.php',
|
|
|
|
data: "dir="+$('#dir').val()+"&newname="+encodeURIComponent(newname)+"&file="+encodeURIComponent(name)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
form.click(function(event){
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
input.blur(function(){
|
2011-07-29 19:51:17 +04:00
|
|
|
form.trigger('submit');
|
2011-07-29 01:04:34 +04:00
|
|
|
});
|
2011-08-04 02:22:44 +04:00
|
|
|
},
|
2011-08-28 03:32:48 +04:00
|
|
|
do_delete:function(files){
|
2011-08-04 02:22:44 +04:00
|
|
|
if(FileList.deleteFiles){//finish any ongoing deletes first
|
|
|
|
FileList.finishDelete(function(){
|
2011-08-28 03:32:48 +04:00
|
|
|
FileList.do_delete(files);
|
2011-08-04 02:22:44 +04:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(files.substr){
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
procesSelection();
|
|
|
|
FileList.deleteCanceled=false;
|
|
|
|
FileList.deleteFiles=files;
|
2011-08-09 19:54:02 +04:00
|
|
|
$('#notification').text(t('files','undo deletion'));
|
2011-08-05 09:37:08 +04:00
|
|
|
$('#notification').fadeIn();
|
2011-08-04 02:22:44 +04:00
|
|
|
},
|
|
|
|
finishDelete:function(ready,sync){
|
|
|
|
if(!FileList.deleteCanceled && FileList.deleteFiles){
|
|
|
|
var fileNames=FileList.deleteFiles.join(';');
|
|
|
|
$.ajax({
|
|
|
|
url: 'ajax/delete.php',
|
|
|
|
async:!sync,
|
|
|
|
data: "dir="+$('#dir').val()+"&files="+encodeURIComponent(fileNames),
|
|
|
|
complete: function(data){
|
|
|
|
boolOperationFinished(data, function(){
|
2011-08-05 09:37:08 +04:00
|
|
|
$('#notification').fadeOut();
|
2011-08-04 02:22:44 +04:00
|
|
|
$.each(FileList.deleteFiles,function(index,file){
|
|
|
|
// alert(file);
|
|
|
|
FileList.remove(file);
|
|
|
|
});
|
|
|
|
FileList.deleteCanceled=true;
|
|
|
|
FileList.deleteFiles=null;
|
|
|
|
if(ready){
|
|
|
|
ready();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-06-04 20:44:14 +04:00
|
|
|
}
|
2011-07-04 23:46:20 +04:00
|
|
|
}
|
2011-08-04 02:22:44 +04:00
|
|
|
|
|
|
|
$(document).ready(function(){
|
2011-08-05 09:37:08 +04:00
|
|
|
$('#notification').hide();
|
2011-08-04 02:22:44 +04:00
|
|
|
$('#notification').click(function(){
|
|
|
|
FileList.deleteCanceled=true;
|
2011-08-05 09:37:08 +04:00
|
|
|
$('#notification').fadeOut();
|
2011-08-04 02:22:44 +04:00
|
|
|
$.each(FileList.deleteFiles,function(index,file){
|
|
|
|
$('tr[data-file="'+file+'"]').show();
|
|
|
|
// alert(file);
|
|
|
|
});
|
|
|
|
FileList.deleteFiles=null;
|
|
|
|
});
|
|
|
|
$(window).bind('beforeunload', function (){
|
|
|
|
FileList.finishDelete(null,true);
|
|
|
|
});
|
|
|
|
});
|