diff options
author | Jan-Christoph Borchardt <hey@jancborchardt.net> | 2013-01-15 20:40:38 +0700 |
---|---|---|
committer | Jan-Christoph Borchardt <hey@jancborchardt.net> | 2013-01-15 20:40:38 +0700 |
commit | 6182b1353bd53bb6bdc5b06248d9742e97d2e249 (patch) | |
tree | b154b88d910c57d17b07ce482cbeb98cb791a106 /apps/files/js/files.js | |
parent | 74b4fefda87feeaf51633ea7794ac498f7dce892 (diff) | |
parent | bb9cc227c2583adc6b51a1f6d75a9fc8333836b9 (diff) | |
download | nextcloud-server-6182b1353bd53bb6bdc5b06248d9742e97d2e249.tar.gz nextcloud-server-6182b1353bd53bb6bdc5b06248d9742e97d2e249.zip |
merge master into navigation
Diffstat (limited to 'apps/files/js/files.js')
-rw-r--r-- | apps/files/js/files.js | 119 |
1 files changed, 73 insertions, 46 deletions
diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 33c775fc8ec..a4260c43285 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -26,17 +26,29 @@ Files={ }); procesSelection(); }, - containsInvalidCharacters:function (name) { + isFileNameValid:function (name) { + if (name === '.') { + $('#notification').text(t('files', '\'.\' is an invalid file name.')); + $('#notification').fadeIn(); + return false; + } + if (name.length == 0) { + $('#notification').text(t('files', 'File name cannot be empty.')); + $('#notification').fadeIn(); + return false; + } + + // check for invalid characters var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*']; for (var i = 0; i < invalid_characters.length; i++) { if (name.indexOf(invalid_characters[i]) != -1) { $('#notification').text(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.")); $('#notification').fadeIn(); - return true; + return false; } } $('#notification').fadeOut(); - return false; + return true; } }; $(document).ready(function() { @@ -75,8 +87,8 @@ $(document).ready(function() { // Sets the file link behaviour : $('td.filename a').live('click',function(event) { - event.preventDefault(); if (event.ctrlKey || event.shiftKey) { + event.preventDefault(); if (event.shiftKey) { var last = $(lastChecked).parent().parent().prevAll().length; var first = $(this).parent().parent().prevAll().length; @@ -118,6 +130,7 @@ $(document).ready(function() { var permissions = $(this).parent().parent().data('permissions'); var action=FileActions.getDefault(mime,type, permissions); if(action){ + event.preventDefault(); action(filename); } } @@ -203,6 +216,9 @@ $(document).ready(function() { var files = data.files; var totalSize=0; if(files){ + if (FileList.lastAction) { + FileList.lastAction(); + } for(var i=0;i<files.length;i++){ if(files[i].size ==0 && files[i].type== '') { @@ -231,12 +247,12 @@ $(document).ready(function() { } }); }else{ - var dropTarget = $(e.originalEvent.target).closest('tr'); - if(dropTarget && dropTarget.attr('data-type') === 'dir') { // drag&drop upload to folder - var dirName = dropTarget.attr('data-file') - } + var dropTarget = $(e.originalEvent.target).closest('tr'); + if(dropTarget && dropTarget.attr('data-type') === 'dir') { // drag&drop upload to folder + var dirName = dropTarget.attr('data-file') + } - var date=new Date(); + var date=new Date(); if(files){ for(var i=0;i<files.length;i++){ if(files[i].size>0){ @@ -289,9 +305,9 @@ $(document).ready(function() { var jqXHR = $('#file_upload_start').fileupload('send', {files: files[i], formData: function(form) { var formArray = form.serializeArray(); - // array index 0 contains the max files size - // array index 1 contains the request token - // array index 2 contains the directory + // array index 0 contains the max files size + // array index 1 contains the request token + // array index 2 contains the directory formArray[2]['value'] = dirName; return formArray; }}).success(function(result, textStatus, jqXHR) { @@ -302,13 +318,14 @@ $(document).ready(function() { $('#notification').fadeIn(); } var file=response[0]; - // TODO: this doesn't work if the file name has been changed server side + // TODO: this doesn't work if the file name has been changed server side delete uploadingFiles[dirName][file.name]; - if ($.assocArraySize(uploadingFiles[dirName]) == 0) { - delete uploadingFiles[dirName]; - } + if ($.assocArraySize(uploadingFiles[dirName]) == 0) { + delete uploadingFiles[dirName]; + } + //TODO update file upload size limit - var uploadtext = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName).find('.uploadtext') + var uploadtext = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName).find('.uploadtext') var currentUploads = parseInt(uploadtext.attr('currentUploads')); currentUploads -= 1; uploadtext.attr('currentUploads', currentUploads); @@ -336,6 +353,7 @@ $(document).ready(function() { } else { uploadtext.text(t('files', '{count} files uploading', {count: currentUploads})); } + delete uploadingFiles[dirName][fileName]; $('#notification').hide(); $('#notification').text(t('files', 'Upload cancelled.')); $('#notification').fadeIn(); @@ -359,8 +377,10 @@ $(document).ready(function() { if(size==t('files','Pending')){ $('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size); } + //TODO update file upload size limit FileList.loadingDone(file.name, file.id); } else { + Files.cancelUpload(this.files[0].name); $('#notification').text(t('files', response.data.message)); $('#notification').fadeIn(); $('#fileList > tr').not('[data-mime]').fadeOut(); @@ -369,6 +389,7 @@ $(document).ready(function() { }) .error(function(jqXHR, textStatus, errorThrown) { if(errorThrown === 'abort') { + Files.cancelUpload(this.files[0].name); $('#notification').hide(); $('#notification').text(t('files', 'Upload cancelled.')); $('#notification').fadeIn(); @@ -389,8 +410,10 @@ $(document).ready(function() { if(size==t('files','Pending')){ $('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size); } + //TODO update file upload size limit FileList.loadingDone(file.name, file.id); } else { + //TODO Files.cancelUpload(/*where do we get the filename*/); $('#notification').text(t('files', response.data.message)); $('#notification').fadeIn(); $('#fileList > tr').not('[data-mime]').fadeOut(); @@ -431,7 +454,7 @@ $(document).ready(function() { // http://stackoverflow.com/a/6700/11236 var size = 0, key; for (key in obj) { - if (obj.hasOwnProperty(key)) size++; + if (obj.hasOwnProperty(key)) size++; } return size; }; @@ -474,7 +497,7 @@ $(document).ready(function() { $('#new').removeClass('active'); $('#new li').each(function(i,element){ if($(element).children('p').length==0){ - $(element).children('input').remove(); + $(element).children('form').remove(); $(element).append('<p>'+$(element).data('text')+'</p>'); } }); @@ -493,7 +516,7 @@ $(document).ready(function() { $('#new li').each(function(i,element){ if($(element).children('p').length==0){ - $(element).children('input').remove(); + $(element).children('form').remove(); $(element).append('<p>'+$(element).data('text')+'</p>'); } }); @@ -502,20 +525,32 @@ $(document).ready(function() { var text=$(this).children('p').text(); $(this).data('text',text); $(this).children('p').remove(); + var form=$('<form></form>'); var input=$('<input>'); - $(this).append(input); + form.append(input); + $(this).append(form); input.focus(); - input.change(function(){ - if (type != 'web' && Files.containsInvalidCharacters($(this).val())) { - return; - } else if( type == 'folder' && $('#dir').val() == '/' && $(this).val() == 'Shared') { - $('#notification').text(t('files','Invalid folder name. Usage of "Shared" is reserved by Owncloud')); + form.submit(function(event){ + event.stopPropagation(); + event.preventDefault(); + var newname=input.val(); + if(type == 'web' && newname.length == 0) { + $('#notification').text(t('files', 'URL cannot be empty.')); + $('#notification').fadeIn(); + return false; + } else if (type != 'web' && !Files.isFileNameValid(newname)) { + return false; + } else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') { + $('#notification').text(t('files','Invalid folder name. Usage of \'Shared\' is reserved by Owncloud')); $('#notification').fadeIn(); - return; + return false; } - var name = getUniqueName($(this).val()); - if (name != $(this).val()) { - FileList.checkName(name, $(this).val(), true); + if (FileList.lastAction) { + FileList.lastAction(); + } + var name = getUniqueName(newname); + if (newname != name) { + FileList.checkName(name, newname, true); var hidden = true; } else { var hidden = false; @@ -559,7 +594,7 @@ $(document).ready(function() { break; case 'web': if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){ - name='http://'.name; + name='http://'+name; } var localName=name; if(localName.substr(localName.length-1,1)=='/'){//strip / @@ -598,8 +633,8 @@ $(document).ready(function() { }); break; } - var li=$(this).parent(); - $(this).remove(); + var li=form.parent(); + form.remove(); li.append('<p>'+li.data('text')+'</p>'); $('#new>a').click(); }); @@ -770,22 +805,14 @@ function procesSelection(){ var selected=getSelectedFiles(); 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(t('files','Name')); $('#headerSize').text(t('files','Size')); $('#modified').text(t('files','Modified')); - $('th').removeClass('multiselect'); + $('table').removeClass('multiselect'); $('.selectedActions').hide(); - $('thead').removeClass('fixed'); - $('#headerName').css('width','auto'); - $('#headerSize').css('width','auto'); - $('#headerDate').css('width','auto'); - $('table').css('padding-top','0'); - }else{ - var width={name:$('#headerName').css('width'),size:$('#headerSize').css('width'),date:$('#headerDate').css('width')}; - $('#headerName').css('width',width.name); - $('#headerSize').css('width',width.size); - $('#headerDate').css('width',width.date); + } + else { $('.selectedActions').show(); var totalSize=0; for(var i=0;i<selectedFiles.length;i++){ @@ -817,7 +844,7 @@ function procesSelection(){ } $('#headerName>span.name').text(selection); $('#modified').text(''); - $('th').addClass('multiselect'); + $('table').addClass('multiselect'); } } |