summaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-09-07 15:42:37 +0200
committerBart Visscher <bartv@thisnet.nl>2012-09-07 15:51:44 +0200
commit5eba5798274823fe3147a8d671ca5e15b3eb7843 (patch)
treeeb9cfb3fc687b8be26dde07a08fd23ca3455991f /apps/files/js
parentb483f2aab856e3324026588a9702043072fd7ad2 (diff)
parent3829460ab8cbb6de65c53583a20fd04cbe7927dd (diff)
downloadnextcloud-server-5eba5798274823fe3147a8d671ca5e15b3eb7843.tar.gz
nextcloud-server-5eba5798274823fe3147a8d671ca5e15b3eb7843.zip
Merge branch 'master' into routing
Conflicts: apps/files/js/fileactions.js lib/base.php lib/helper.php lib/ocs.php
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/fileactions.js32
-rw-r--r--apps/files/js/filelist.js157
-rw-r--r--apps/files/js/files.js65
3 files changed, 170 insertions, 84 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 44c04bf0d71..37e6c91ebe5 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -1,9 +1,4 @@
-FileActions={
- PERMISSION_CREATE:4,
- PERMISSION_READ:1,
- PERMISSION_UPDATE:2,
- PERMISSION_DELETE:8,
- PERMISSION_SHARE:16,
+var FileActions={
actions:{},
defaults:{},
icons:{},
@@ -25,20 +20,20 @@ FileActions={
get:function(mime,type,permissions){
var actions={};
if(FileActions.actions.all){
- actions=$.extend( actions, FileActions.actions.all )
+ actions=$.extend( actions, FileActions.actions.all );
}
if(mime){
if(FileActions.actions[mime]){
- actions=$.extend( actions, FileActions.actions[mime] )
+ actions=$.extend( actions, FileActions.actions[mime] );
}
var mimePart=mime.substr(0,mime.indexOf('/'));
if(FileActions.actions[mimePart]){
- actions=$.extend( actions, FileActions.actions[mimePart] )
+ actions=$.extend( actions, FileActions.actions[mimePart] );
}
}
if(type){//type is 'dir' or 'file'
if(FileActions.actions[type]){
- actions=$.extend( actions, FileActions.actions[type] )
+ actions=$.extend( actions, FileActions.actions[type] );
}
}
var filteredActions = {};
@@ -108,7 +103,12 @@ FileActions={
if(img.call){
img=img(file);
}
- var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />';
+ // NOTE: Temporary fix to allow unsharing of files in root of Shared folder
+ if ($('#dir').val() == '/Shared') {
+ var html = '<a href="#" original-title="' + t('files', 'Unshare') + '" class="action delete" style="display:none" />';
+ } else {
+ var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />';
+ }
var element=$(html);
if(img){
element.append($('<img src="'+img+'"/>'));
@@ -148,7 +148,7 @@ FileActions={
getCurrentPermissions:function() {
return FileActions.currentFile.parent().data('permissions');
}
-}
+};
$(document).ready(function(){
if($('#allowZipDownload').val() == 1){
@@ -156,12 +156,12 @@ $(document).ready(function(){
} else {
var downloadScope = 'file';
}
- FileActions.register(downloadScope,'Download', FileActions.PERMISSION_READ, function(){return OC.imagePath('core','actions/download')},function(filename){
+ FileActions.register(downloadScope,'Download', OC.PERMISSION_READ, function(){return OC.imagePath('core','actions/download');},function(filename){
window.location=OC.filePath('files', 'ajax', 'download.php') + encodeURIComponent('?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val()));
});
});
-FileActions.register('all','Delete', FileActions.PERMISSION_DELETE, function(){return OC.imagePath('core','actions/delete')},function(filename){
+FileActions.register('all','Delete', OC.PERMISSION_DELETE, function(){return OC.imagePath('core','actions/delete');},function(filename){
if(Files.cancelUpload(filename)) {
if(filename.substr){
filename=[filename];
@@ -179,11 +179,11 @@ FileActions.register('all','Delete', FileActions.PERMISSION_DELETE, function(){r
$('.tipsy').remove();
});
-FileActions.register('all','Rename', FileActions.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/rename')},function(filename){
+FileActions.register('all','Rename', OC.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/rename');},function(filename){
FileList.rename(filename);
});
-FileActions.register('dir','Open', FileActions.PERMISSION_READ, '', function(filename){
+FileActions.register('dir','Open', OC.PERMISSION_READ, '', function(filename){
window.location=OC.linkTo('files', 'index.php') + '?dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
});
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 7c97f82488d..7be4be0e944 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -1,11 +1,11 @@
-FileList={
+var FileList={
useUndo:true,
update:function(fileListHtml) {
$('#fileList').empty().html(fileListHtml);
},
- addFile:function(name,size,lastModified,loading){
+ addFile:function(name,size,lastModified,loading,hidden){
var img=(loading)?OC.imagePath('core', 'loading.gif'):OC.imagePath('core', 'filetypes/file.png');
- var html='<tr data-type="file" data-size="'+size+'">';
+ var html='<tr data-type="file" data-size="'+size+'" data-permissions="'+$('#permissions').val()+'">';
if(name.indexOf('.')!=-1){
var basename=name.substr(0,name.lastIndexOf('.'));
var extension=name.substr(name.lastIndexOf('.'));
@@ -14,7 +14,7 @@ FileList={
var extension=false;
}
html+='<td class="filename" style="background-image:url('+img+')"><input type="checkbox" />';
- html+='<a class="name" href="download.php?file='+$('#dir').val().replace(/</, '&lt;').replace(/>/, '&gt;')+'/'+name+'"><span class="nametext">'+basename
+ html+='<a class="name" href="download.php?file='+$('#dir').val().replace(/</, '&lt;').replace(/>/, '&gt;')+'/'+name+'"><span class="nametext">'+basename;
if(extension){
html+='<span class="extension">'+extension+'</span>';
}
@@ -36,9 +36,12 @@ FileList={
}else{
$('tr').filterAttr('data-file',name).find('td.filename').draggable(dragOptions);
}
+ if (hidden) {
+ $('tr').filterAttr('data-file', name).hide();
+ }
},
- addDir:function(name,size,lastModified){
- html = $('<tr></tr>').attr({ "data-type": "dir", "data-size": size, "data-file": name});
+ addDir:function(name,size,lastModified,hidden){
+ html = $('<tr></tr>').attr({ "data-type": "dir", "data-size": size, "data-file": name, "data-permissions": $('#permissions').val()});
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": OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent($('#dir').val()+'/'+name).replace(/%2F/g, '/') });
@@ -63,6 +66,9 @@ FileList={
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);
+ if (hidden) {
+ $('tr').filterAttr('data-file', name).hide();
+ }
},
refresh:function(data) {
result = jQuery.parseJSON(data.responseText);
@@ -82,7 +88,7 @@ FileList={
},
insertElement:function(name,type,element){
//find the correct spot to insert the file or folder
- var fileElements=$('tr[data-file][data-type="'+type+'"]');
+ var fileElements=$('tr[data-file][data-type="'+type+'"]:visible');
var pos;
if(name.localeCompare($(fileElements[0]).attr('data-file'))<0){
pos=-1;
@@ -137,11 +143,7 @@ FileList={
event.preventDefault();
var newname=input.val();
if (newname != name) {
- if ($('tr').filterAttr('data-file', newname).length > 0) {
- $('#notification').html(newname+' '+t('files', 'already exists')+'<span class="replace">'+t('files', 'replace')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>');
- $('#notification').data('oldName', name);
- $('#notification').data('newName', newname);
- $('#notification').fadeIn();
+ if (FileList.checkName(name, newname, false)) {
newname = name;
} else {
$.get(OC.filePath('files','ajax','rename.php'), { dir : $('#dir').val(), newname: newname, file: name },function(result) {
@@ -151,7 +153,6 @@ FileList={
}
});
}
-
}
tr.attr('data-file', newname);
var path = td.children('a.name').attr('href');
@@ -179,58 +180,77 @@ FileList={
form.trigger('submit');
});
},
- replace:function(oldName, newName) {
+ checkName:function(oldName, newName, isNewFile) {
+ if (isNewFile || $('tr').filterAttr('data-file', newName).length > 0) {
+ if (isNewFile) {
+ $('#notification').html(newName+' '+t('files', 'already exists')+'<span class="replace">'+t('files', 'replace')+'</span><span class="suggest">'+t('files', 'suggest name')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>');
+ } else {
+ $('#notification').html(newName+' '+t('files', 'already exists')+'<span class="replace">'+t('files', 'replace')+'</span><span class="cancel">'+t('files', 'cancel')+'</span>');
+ }
+ $('#notification').data('oldName', oldName);
+ $('#notification').data('newName', newName);
+ $('#notification').data('isNewFile', isNewFile);
+ $('#notification').fadeIn();
+ return true;
+ } else {
+ return false;
+ }
+ },
+ replace:function(oldName, newName, isNewFile) {
// Finish any existing actions
if (FileList.lastAction || !FileList.useUndo) {
FileList.lastAction();
}
- var tr = $('tr').filterAttr('data-file', oldName);
- tr.hide();
+ $('tr').filterAttr('data-file', oldName).hide();
+ $('tr').filterAttr('data-file', newName).hide();
+ var tr = $('tr').filterAttr('data-file', oldName).clone();
+ tr.attr('data-replace', 'true');
+ tr.attr('data-file', newName);
+ var td = tr.children('td.filename');
+ td.children('a.name .span').text(newName);
+ var path = td.children('a.name').attr('href');
+ td.children('a.name').attr('href', path.replace(encodeURIComponent(oldName), encodeURIComponent(newName)));
+ if (newName.indexOf('.') > 0) {
+ var basename = newName.substr(0, newName.lastIndexOf('.'));
+ } else {
+ var basename = newName;
+ }
+ td.children('a.name').empty();
+ var span = $('<span class="nametext"></span>');
+ span.text(basename);
+ td.children('a.name').append(span);
+ if (newName.indexOf('.') > 0) {
+ span.append($('<span class="extension">'+newName.substr(newName.lastIndexOf('.'))+'</span>'));
+ }
+ FileList.insertElement(newName, tr.data('type'), tr);
+ tr.show();
FileList.replaceCanceled = false;
FileList.replaceOldName = oldName;
FileList.replaceNewName = newName;
+ FileList.replaceIsNewFile = isNewFile;
FileList.lastAction = function() {
FileList.finishReplace();
};
- $('#notification').html(t('files', 'replaced')+' '+newName+' '+t('files', 'with')+' '+oldName+'<span class="undo">'+t('files', 'undo')+'</span>');
+ if (isNewFile) {
+ $('#notification').html(t('files', 'replaced')+' '+newName+'<span class="undo">'+t('files', 'undo')+'</span>');
+ } else {
+ $('#notification').html(t('files', 'replaced')+' '+newName+' '+t('files', 'with')+' '+oldName+'<span class="undo">'+t('files', 'undo')+'</span>');
+ }
$('#notification').fadeIn();
},
finishReplace:function() {
if (!FileList.replaceCanceled && FileList.replaceOldName && FileList.replaceNewName) {
- // Delete the file being replaced and rename the replacement
- FileList.deleteCanceled = false;
- FileList.deleteFiles = [FileList.replaceNewName];
- FileList.finishDelete(function() {
- $.ajax({url: OC.filePath('files', 'ajax', 'rename.php'), async: false, data: { dir: $('#dir').val(), newname: FileList.replaceNewName, file: FileList.replaceOldName }, success: function(result) {
- if (result && result.status == 'success') {
- var tr = $('tr').filterAttr('data-file', FileList.replaceOldName);
- tr.attr('data-file', FileList.replaceNewName);
- var td = tr.children('td.filename');
- td.children('a.name .span').text(FileList.replaceNewName);
- var path = td.children('a.name').attr('href');
- td.children('a.name').attr('href', path.replace(encodeURIComponent(FileList.replaceOldName), encodeURIComponent(FileList.replaceNewName)));
- if (FileList.replaceNewName.indexOf('.') > 0) {
- var basename = FileList.replaceNewName.substr(0, FileList.replaceNewName.lastIndexOf('.'));
- } else {
- var basename = FileList.replaceNewName;
- }
- td.children('a.name').empty();
- var span = $('<span class="nametext"></span>');
- span.text(basename);
- td.children('a.name').append(span);
- if (FileList.replaceNewName.indexOf('.') > 0) {
- span.append($('<span class="extension">'+FileList.replaceNewName.substr(FileList.replaceNewName.lastIndexOf('.'))+'</span>'));
- }
- tr.show();
- } else {
- OC.dialogs.alert(result.data.message, 'Error moving file');
- }
- FileList.replaceCanceled = true;
- FileList.replaceOldName = null;
- FileList.replaceNewName = null;
- FileList.lastAction = null;
- }});
- }, true);
+ $.ajax({url: OC.filePath('files', 'ajax', 'rename.php'), async: false, data: { dir: $('#dir').val(), newname: FileList.replaceNewName, file: FileList.replaceOldName }, success: function(result) {
+ if (result && result.status == 'success') {
+ $('tr').filterAttr('data-replace', 'true').removeAttr('data-replace');
+ } else {
+ OC.dialogs.alert(result.data.message, 'Error moving file');
+ }
+ FileList.replaceCanceled = true;
+ FileList.replaceOldName = null;
+ FileList.replaceNewName = null;
+ FileList.lastAction = null;
+ }});
}
},
do_delete:function(files){
@@ -243,7 +263,12 @@ FileList={
return;
}
FileList.prepareDeletion(files);
- $('#notification').html(t('files', 'deleted')+' '+files+'<span class="undo">'+t('files', 'undo')+'</span>');
+ // NOTE: Temporary fix to change the text to unshared for files in root of Shared folder
+ if ($('#dir').val() == '/Shared') {
+ $('#notification').html(t('files', 'unshared')+' '+files+'<span class="undo">'+t('files', 'undo')+'</span>');
+ } else {
+ $('#notification').html(t('files', 'deleted')+' '+files+'<span class="undo">'+t('files', 'undo')+'</span>');
+ }
$('#notification').fadeIn();
},
finishDelete:function(ready,sync){
@@ -255,7 +280,7 @@ FileList={
data: {dir:$('#dir').val(),files:fileNames},
complete: function(data){
boolOperationFinished(data, function(){
- $('#notification').fadeOut();
+ $('#notification').fadeOut('400');
$.each(FileList.deleteFiles,function(index,file){
FileList.remove(file);
});
@@ -299,21 +324,39 @@ $(document).ready(function(){
FileList.deleteCanceled=true;
FileList.deleteFiles=null;
} else if (FileList.replaceOldName && FileList.replaceNewName) {
- $('tr').filterAttr('data-file', FileList.replaceOldName).show();
+ if (FileList.replaceIsNewFile) {
+ // Delete the new uploaded file
+ FileList.deleteCanceled = false;
+ FileList.deleteFiles = [FileList.replaceOldName];
+ FileList.finishDelete(null, true);
+ } else {
+ $('tr').filterAttr('data-file', FileList.replaceOldName).show();
+ }
+ $('tr').filterAttr('data-replace', 'true').remove();
+ $('tr').filterAttr('data-file', FileList.replaceNewName).show();
FileList.replaceCanceled = true;
FileList.replaceOldName = null;
FileList.replaceNewName = null;
+ FileList.replaceIsNewFile = null;
}
FileList.lastAction = null;
- $('#notification').fadeOut();
+ $('#notification').fadeOut('400');
});
$('#notification .replace').live('click', function() {
$('#notification').fadeOut('400', function() {
- FileList.replace($('#notification').data('oldName'), $('#notification').data('newName'));
+ FileList.replace($('#notification').data('oldName'), $('#notification').data('newName'), $('#notification').data('isNewFile'));
});
});
+ $('#notification .suggest').live('click', function() {
+ $('tr').filterAttr('data-file', $('#notification').data('oldName')).show();
+ $('#notification').fadeOut('400');
+ });
$('#notification .cancel').live('click', function() {
- $('#notification').fadeOut();
+ if ($('#notification').data('isNewFile')) {
+ FileList.deleteCanceled = false;
+ FileList.deleteFiles = [$('#notification').data('oldName')];
+ FileList.finishDelete(null, true);
+ }
});
FileList.useUndo=('onbeforeunload' in window)
$(window).bind('beforeunload', function (){
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index b57e75c9004..101e2bad2e4 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -26,7 +26,7 @@ Files={
});
procesSelection();
}
-}
+};
$(document).ready(function() {
$('#fileList tr').each(function(){
//little hack to set unescape filenames in attribute
@@ -40,8 +40,16 @@ $(document).ready(function() {
$('#file_action_panel').attr('activeAction', false);
//drag/drop of files
- $('#fileList tr[data-write="true"] td.filename').draggable(dragOptions);
- $('#fileList tr[data-type="dir"][data-write="true"] td.filename').droppable(folderDropOptions);
+ $('#fileList tr td.filename').each(function(i,e){
+ if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) {
+ $(e).draggable(dragOptions);
+ }
+ });
+ $('#fileList tr[data-type="dir"] td.filename').each(function(i,e){
+ if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE){
+ $(e).droppable(folderDropOptions);
+ }
+ });
$('div.crumb:not(.last)').droppable(crumbDropOptions);
$('ul#apps>li:first-child').data('dir','');
if($('div.crumb').length){
@@ -228,7 +236,14 @@ $(document).ready(function() {
var size=t('files','Pending');
}
if(files && !dirName){
- FileList.addFile(getUniqueName(files[i].name),size,date,true);
+ var uniqueName = getUniqueName(files[i].name);
+ if (uniqueName != files[i].name) {
+ FileList.checkName(uniqueName, files[i].name, true);
+ var hidden = true;
+ } else {
+ var hidden = false;
+ }
+ FileList.addFile(uniqueName,size,date,true,hidden);
} else if(dirName) {
var uploadtext = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName).find('.uploadtext')
var currentUploads = parseInt(uploadtext.attr('currentUploads'));
@@ -247,7 +262,14 @@ $(document).ready(function() {
}
}else{
var filename=this.value.split('\\').pop(); //ie prepends C:\fakepath\ in front of the filename
- FileList.addFile(getUniqueName(filename),'Pending',date,true);
+ var uniqueName = getUniqueName(filename);
+ if (uniqueName != filename) {
+ FileList.checkName(uniqueName, filename, true);
+ var hidden = true;
+ } else {
+ var hidden = false;
+ }
+ FileList.addFile(uniqueName,'Pending',date,true,hidden);
}
if($.support.xhrFileUpload) {
for(var i=0;i<files.length;i++){
@@ -386,6 +408,21 @@ $(document).ready(function() {
})
});
+ $.assocArraySize = function(obj) {
+ // http://stackoverflow.com/a/6700/11236
+ var size = 0, key;
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) size++;
+ }
+ return size;
+ };
+
+ // warn user not to leave the page while upload is in progress
+ $(window).bind('beforeunload', function(e) {
+ if ($.assocArraySize(uploadingFiles) > 0)
+ return t('files','File upload is in progress. Leaving the page now will cancel the upload.');
+ });
+
//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')
@@ -452,21 +489,27 @@ $(document).ready(function() {
$(this).append(input);
input.focus();
input.change(function(){
- var name=getUniqueName($(this).val());
- if(type != 'web' && name.indexOf('/')!=-1){
+ if(type != 'web' && $(this).val().indexOf('/')!=-1){
$('#notification').text(t('files','Invalid name, \'/\' is not allowed.'));
$('#notification').fadeIn();
return;
}
+ var name = getUniqueName($(this).val());
+ if (name != $(this).val()) {
+ FileList.checkName(name, $(this).val(), true);
+ var hidden = true;
+ } else {
+ var hidden = false;
+ }
switch(type){
case 'file':
$.post(
OC.filePath('files','ajax','newfile.php'),
- {dir:$('#dir').val(),filename:name,content:" \n"},
+ {dir:$('#dir').val(),filename:name},
function(result){
if (result.status == 'success') {
var date=new Date();
- FileList.addFile(name,0,date);
+ FileList.addFile(name,0,date,false,hidden);
var tr=$('tr').filterAttr('data-file',name);
tr.data('mime','text/plain');
getMimeIcon('text/plain',function(path){
@@ -485,7 +528,7 @@ $(document).ready(function() {
function(result){
if (result.status == 'success') {
var date=new Date();
- FileList.addDir(name,0,date);
+ FileList.addDir(name,0,date,hidden);
} else {
OC.dialogs.alert(result.data.message, 'Error');
}
@@ -516,7 +559,7 @@ $(document).ready(function() {
eventSource.listen('success',function(mime){
$('#uploadprogressbar').fadeOut();
var date=new Date();
- FileList.addFile(localName,0,date);
+ FileList.addFile(localName,0,date,false,hidden);
var tr=$('tr').filterAttr('data-file',localName);
tr.data('mime',mime);
getMimeIcon(mime,function(path){