From 79a6d89bccf4c5d4ce934c88bc544988c47b8e98 Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Wed, 19 Feb 2014 21:23:39 +0000 Subject: [PATCH 01/13] Feature Added : Ability to drag and drop in Chrome --- apps/files/ajax/upload.php | 26 ++++++++++++++++++-------- apps/files/js/file-upload.js | 3 ++- apps/files/js/filelist.js | 32 ++++++++++++++++++++++++++++---- lib/private/files/view.php | 11 +++++++++++ 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 145f40c50d..b2aa7a9920 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -103,22 +103,32 @@ if ($maxUploadFileSize >= 0 and $totalSize > $maxUploadFileSize) { } $result = array(); +$directory = ''; if (strpos($dir, '..') === false) { $fileCount = count($files['name']); for ($i = 0; $i < $fileCount; $i++) { + + // Get the files directory + if(isset($_POST['file_directory']) === true) { + $directory = '/'.$_POST['file_directory']; + } + // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder if (isset($_POST['resolution']) && $_POST['resolution']==='autorename') { // append a number in brackets like 'filename (2).ext' - $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); + $target = OCP\Files::buildNotExistingFileName(stripslashes($dir.$directory), $files['name'][$i]); } else { - $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$files['name'][$i]); + $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir.$directory).'/'.$files['name'][$i]); } - - $directory = \OC\Files\Filesystem::normalizePath(stripslashes($dir)); - if (isset($public_directory)) { - // If we are uploading from the public app, - // we want to send the relative path in the ajax request. - $directory = $public_directory; + + if(empty($directory) === true) + { + $directory = \OC\Files\Filesystem::normalizePath(stripslashes($dir)); + if (isset($public_directory)) { + // If we are uploading from the public app, + // we want to send the relative path in the ajax request. + $directory = $public_directory; + } } if ( ! \OC\Files\Filesystem::file_exists($target) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index f962a7044a..ae6fdc654e 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -327,7 +327,8 @@ $(document).ready(function() { // noone set update parameters, we set the minimum data.formData = { requesttoken: oc_requesttoken, - dir: $('#dir').val() + dir: $('#dir').val(), + file_directory: data.files[0]['relativePath'], }; } }, diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index d6cffde05d..2631812c2e 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -879,7 +879,8 @@ $(document).ready(function() { data.formData = function(form) { return [ {name: 'dir', value: dir}, - {name: 'requesttoken', value: oc_requesttoken} + {name: 'requesttoken', value: oc_requesttoken}, + {name: 'file_directory', value: data.files[0]['relativePath']} ]; }; } @@ -935,7 +936,7 @@ $(document).ready(function() { var file = result[0]; if (data.context && data.context.data('type') === 'dir') { - + // update upload counter ui var uploadtext = data.context.find('.uploadtext'); var currentUploads = parseInt(uploadtext.attr('currentUploads')); @@ -956,10 +957,33 @@ $(document).ready(function() { size += parseInt(file.size); data.context.attr('data-size', size); data.context.find('td.filesize').text(humanFileSize(size)); - - } else { + } + else { + // only append new file if uploaded into the current folder if (file.directory !== FileList.getCurrentDirectory()) { + + file_directory = file.directory.replace('/','').replace(/\/$/, "").split('/'); + + if (file_directory.length == 1) { + file_directory = file_directory[0]; + + // Get the directory + if ($('tr[data-file="'+file_directory+'"]').length == 0) + { + FileList.addDir(file_directory, 0, new Date(), false); + } + } + else { + file_directory = file_directory[0]; + } + + // update folder size + var size = parseInt($('tr[data-file="'+file_directory+'"]').attr('data-size')); + size += parseInt(file.size); + $('tr[data-file="'+file_directory+'"]').attr('data-size', size); + $('tr[data-file="'+file_directory+'"]').find('td.filesize').text(humanFileSize(size)); + return; } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 530aa8f751..7977272ee1 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -617,10 +617,21 @@ class View { } public function fromTmpFile($tmpFile, $path) { + if (Filesystem::isValidPath($path)) { + + // Get directory that the file is going into + $file_path = \OC_User::getHome(\OC_User::getUser()) . '/files'.substr($path, 0, strrpos($path,'/')); + + // Create the directories if any + if(empty($file_path) === false) { + mkdir($file_path, 0770, true); + } + if (!$tmpFile) { debug_print_backtrace(); } + $source = fopen($tmpFile, 'r'); if ($source) { $this->file_put_contents($path, $source); From b01492fecd5019a09cd7b1265a9cef43fc42616f Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Wed, 19 Feb 2014 21:28:32 +0000 Subject: [PATCH 02/13] Feature Added : Ability to drag and drop in Chrome --- apps/files/ajax/upload.php | 4 ++-- apps/files/js/filelist.js | 12 ++++++------ lib/private/files/view.php | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index b2aa7a9920..d189386e05 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -107,12 +107,12 @@ $directory = ''; if (strpos($dir, '..') === false) { $fileCount = count($files['name']); for ($i = 0; $i < $fileCount; $i++) { - + // Get the files directory if(isset($_POST['file_directory']) === true) { $directory = '/'.$_POST['file_directory']; } - + // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder if (isset($_POST['resolution']) && $_POST['resolution']==='autorename') { // append a number in brackets like 'filename (2).ext' diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 2631812c2e..17846c23b7 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -936,7 +936,7 @@ $(document).ready(function() { var file = result[0]; if (data.context && data.context.data('type') === 'dir') { - + // update upload counter ui var uploadtext = data.context.find('.uploadtext'); var currentUploads = parseInt(uploadtext.attr('currentUploads')); @@ -962,12 +962,12 @@ $(document).ready(function() { // only append new file if uploaded into the current folder if (file.directory !== FileList.getCurrentDirectory()) { - + file_directory = file.directory.replace('/','').replace(/\/$/, "").split('/'); - + if (file_directory.length == 1) { file_directory = file_directory[0]; - + // Get the directory if ($('tr[data-file="'+file_directory+'"]').length == 0) { @@ -977,13 +977,13 @@ $(document).ready(function() { else { file_directory = file_directory[0]; } - + // update folder size var size = parseInt($('tr[data-file="'+file_directory+'"]').attr('data-size')); size += parseInt(file.size); $('tr[data-file="'+file_directory+'"]').attr('data-size', size); $('tr[data-file="'+file_directory+'"]').find('td.filesize').text(humanFileSize(size)); - + return; } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 7977272ee1..ddf8c3038b 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -617,21 +617,21 @@ class View { } public function fromTmpFile($tmpFile, $path) { - + if (Filesystem::isValidPath($path)) { - + // Get directory that the file is going into $file_path = \OC_User::getHome(\OC_User::getUser()) . '/files'.substr($path, 0, strrpos($path,'/')); - + // Create the directories if any if(empty($file_path) === false) { mkdir($file_path, 0770, true); } - + if (!$tmpFile) { debug_print_backtrace(); } - + $source = fopen($tmpFile, 'r'); if ($source) { $this->file_put_contents($path, $source); From 089052b13af7a5e27d225ab345616511f4eaf2a9 Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Thu, 20 Feb 2014 20:18:27 +0000 Subject: [PATCH 03/13] Fixed issue with drag and drop not in the root directory, for folders and files --- apps/files/js/filelist.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 17846c23b7..64315c0362 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -958,10 +958,9 @@ $(document).ready(function() { data.context.attr('data-size', size); data.context.find('td.filesize').text(humanFileSize(size)); } - else { - + else { // only append new file if uploaded into the current folder - if (file.directory !== FileList.getCurrentDirectory()) { + if (file.directory != '/' && file.directory !== FileList.getCurrentDirectory()) { file_directory = file.directory.replace('/','').replace(/\/$/, "").split('/'); @@ -977,12 +976,14 @@ $(document).ready(function() { else { file_directory = file_directory[0]; } + + file_directory = FileList.findFileEl(file_directory); // update folder size - var size = parseInt($('tr[data-file="'+file_directory+'"]').attr('data-size')); + var size = parseInt(file_directory.attr('data-size')); size += parseInt(file.size); - $('tr[data-file="'+file_directory+'"]').attr('data-size', size); - $('tr[data-file="'+file_directory+'"]').find('td.filesize').text(humanFileSize(size)); + file_directory.attr('data-size', size); + file_directory.find('td.filesize').text(humanFileSize(size)); return; } From 6d373e97c32ec51bd649eeafdfcc3596067776f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Apr 2014 23:02:49 +0200 Subject: [PATCH 04/13] remove unused exit() --- apps/files/ajax/upload.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 38175fa500..a5ce7b257d 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -196,7 +196,6 @@ if (strpos($dir, '..') === false) { if ($error === false) { OCP\JSON::encodedPrint($result); - exit(); } else { OCP\JSON::error(array(array('data' => array_merge(array('message' => $error, 'code' => $errorCode), $storageStats)))); } From 971a311feec6c4c2de905bdbbe71c2cf60296cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Apr 2014 23:03:19 +0200 Subject: [PATCH 05/13] adding parentId to file info array --- apps/files/lib/helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index b765fdaf3e..f9515d6715 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -73,13 +73,14 @@ class Helper /** * Formats the file info to be returned as JSON to the client. * - * @param \OCP\Files\FileInfo file info + * @param \OCP\Files\FileInfo $i * @return array formatted file info */ public static function formatFileInfo($i) { $entry = array(); $entry['id'] = $i['fileid']; + $entry['parentId'] = $i['parent']; $entry['date'] = \OCP\Util::formatDate($i['mtime']); $entry['mtime'] = $i['mtime'] * 1000; // only pick out the needed attributes From d15a4719d2bc58827d7cbe616ab25aaf376c8293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Apr 2014 23:04:08 +0200 Subject: [PATCH 06/13] fix folder upload in js --- apps/files/js/filelist.js | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 69c97e8b32..4a59508330 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1103,33 +1103,38 @@ $(document).ready(function() { size += parseInt(file.size); data.context.attr('data-size', size); data.context.find('td.filesize').text(humanFileSize(size)); - } - else { + } else { // only append new file if uploaded into the current folder - if (file.directory != '/' && file.directory !== FileList.getCurrentDirectory()) { + if (file.directory !== '/' && file.directory !== FileList.getCurrentDirectory()) { - file_directory = file.directory.replace('/','').replace(/\/$/, "").split('/'); + var fileDirectory = file.directory.replace('/','').replace(/\/$/, "").split('/'); - if (file_directory.length == 1) { - file_directory = file_directory[0]; + if (fileDirectory.length === 1) { + fileDirectory = fileDirectory[0]; // Get the directory - if ($('tr[data-file="'+file_directory+'"]').length == 0) - { - FileList.addDir(file_directory, 0, new Date(), false); + if ($('tr[data-file="'+fileDirectory+'"]').length === 0) { + var dir = { + name: fileDirectory, + type: 'dir', + mimetype: 'httpd/unix-directory', + permissions: file.permissions, + size: 0, + id: file.parentId + }; + FileList.add(dir, {insert: true}); } - } - else { - file_directory = file_directory[0]; + } else { + fileDirectory = fileDirectory[0]; } - file_directory = FileList.findFileEl(file_directory); + fileDirectory = FileList.findFileEl(fileDirectory); // update folder size - var size = parseInt(file_directory.attr('data-size')); + var size = parseInt(fileDirectory.attr('data-size')); size += parseInt(file.size); - file_directory.attr('data-size', size); - file_directory.find('td.filesize').text(humanFileSize(size)); + fileDirectory.attr('data-size', size); + fileDirectory.find('td.filesize').text(humanFileSize(size)); return; } From 7dd00746556aa4be26e41a6f3b66095a29b02c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Apr 2014 23:17:35 +0200 Subject: [PATCH 07/13] fixing mkdir code to respect external file systems as well --- lib/private/files/view.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 0dce90aec4..519ed250b1 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -633,11 +633,11 @@ class View { if (Filesystem::isValidPath($path)) { // Get directory that the file is going into - $file_path = \OC_User::getHome(\OC_User::getUser()) . '/files'.substr($path, 0, strrpos($path,'/')); + $filePath = dirname($path); // Create the directories if any - if(empty($file_path) === false) { - mkdir($file_path, 0770, true); + if (!$this->file_exists($filePath)) { + $this->mkdir($filePath); } if (!$tmpFile) { From 68b7822cf50a670619659ae2082633f4c62fb5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Apr 2014 23:45:35 +0200 Subject: [PATCH 08/13] js style fixes according to our jshintrc rules --- apps/files/js/filelist.js | 114 +++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 4a59508330..ceaaed264a 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -9,7 +9,7 @@ */ /* global OC, t, n, FileList, FileActions, Files, BreadCrumb */ -/* global procesSelection, dragOptions, SVGSupport */ +/* global procesSelection, dragOptions, folderDropOptions, SVGSupport */ window.FileList = { appName: t('files', 'Files'), isEmpty: true, @@ -228,7 +228,7 @@ window.FileList = { linkUrl = Files.getDownloadUrl(name, FileList.getCurrentDirectory()); } td.append(''); - var link_elem = $('').attr({ + var linkElem = $('').attr({ "class": "name", "href": linkUrl }); @@ -244,19 +244,19 @@ window.FileList = { basename = name; extension = false; } - var name_span=$('').addClass('nametext').text(basename); - link_elem.append(name_span); + var nameSpan=$('').addClass('nametext').text(basename); + linkElem.append(nameSpan); if (extension) { - name_span.append($('').addClass('extension').text(extension)); + nameSpan.append($('').addClass('extension').text(extension)); } // dirs can show the number of uploaded files if (type === 'dir') { - link_elem.append($('').attr({ + linkElem.append($('').attr({ 'class': 'uploadtext', 'currentUploads': 0 })); } - td.append(link_elem); + td.append(linkElem); tr.append(td); // size column @@ -266,7 +266,7 @@ window.FileList = { } else { simpleSize = t('files', 'Pending'); } - var lastModifiedTime = Math.round(mtime / 1000); + td = $('').attr({ "class": "filesize", "style": 'color:rgb(' + sizeColor + ',' + sizeColor + ',' + sizeColor + ')' @@ -453,8 +453,6 @@ window.FileList = { }); }, reloadCallback: function(result) { - var $controls = $('#controls'); - delete this._reloadCall; this.hideMask(); @@ -822,10 +820,9 @@ window.FileList = { var info = t('files', '{dirs} and {files}', infoVars); // don't show the filesize column, if filesize is NaN (e.g. in trashbin) - if (isNaN(summary.totalSize)) { - var fileSize = ''; - } else { - var fileSize = ''+humanFileSize(summary.totalSize)+''; + var fileSize = ''; + if (!isNaN(summary.totalSize)) { + fileSize = ''+humanFileSize(summary.totalSize)+''; } var $summary = $(''+info+''+fileSize+''); @@ -911,7 +908,6 @@ window.FileList = { } }, updateEmptyContent: function() { - var $fileList = $('#fileList'); var permissions = $('#permissions').val(); var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0; $('#emptycontent').toggleClass('hidden', !isCreatable || !FileList.isEmpty); @@ -949,13 +945,13 @@ window.FileList = { }, scrollTo:function(file) { //scroll to and highlight preselected file - var $scrolltorow = FileList.findFileEl(file); - if ($scrolltorow.exists()) { - $scrolltorow.addClass('searchresult'); - $(window).scrollTop($scrolltorow.position().top); + var $scrollToRow = FileList.findFileEl(file); + if ($scrollToRow.exists()) { + $scrollToRow.addClass('searchresult'); + $(window).scrollTop($scrollToRow.position().top); //remove highlight when hovered over - $scrolltorow.one('hover', function() { - $scrolltorow.removeClass('searchresult'); + $scrollToRow.one('hover', function() { + $scrollToRow.removeClass('searchresult'); }); } }, @@ -991,9 +987,9 @@ $(document).ready(function() { FileList.initialize(); // handle upload events - var file_upload_start = $('#file_upload_start'); + var fileUploadStart = $('#file_upload_start'); - file_upload_start.on('fileuploaddrop', function(e, data) { + fileUploadStart.on('fileuploaddrop', function(e, data) { OC.Upload.log('filelist handle fileuploaddrop', e, data); var dropTarget = $(e.originalEvent.target).closest('tr, .crumb'); @@ -1021,7 +1017,7 @@ $(document).ready(function() { return [ {name: 'dir', value: dir}, {name: 'requesttoken', value: oc_requesttoken}, - {name: 'file_directory', value: data.files[0]['relativePath']} + {name: 'file_directory', value: data.files[0].relativePath} ]; }; } else { @@ -1032,7 +1028,7 @@ $(document).ready(function() { } } }); - file_upload_start.on('fileuploadadd', function(e, data) { + fileUploadStart.on('fileuploadadd', function(e, data) { OC.Upload.log('filelist handle fileuploadadd', e, data); //finish delete if we are uploading a deleted file @@ -1045,19 +1041,19 @@ $(document).ready(function() { // add to existing folder // update upload counter ui - var uploadtext = data.context.find('.uploadtext'); - var currentUploads = parseInt(uploadtext.attr('currentUploads')); + var uploadText = data.context.find('.uploadtext'); + var currentUploads = parseInt(uploadText.attr('currentUploads'), 10); currentUploads += 1; - uploadtext.attr('currentUploads', currentUploads); + uploadText.attr('currentUploads', currentUploads); var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads); if (currentUploads === 1) { var img = OC.imagePath('core', 'loading.gif'); data.context.find('td.filename').attr('style','background-image:url('+img+')'); - uploadtext.text(translatedText); - uploadtext.show(); + uploadText.text(translatedText); + uploadText.show(); } else { - uploadtext.text(translatedText); + uploadText.text(translatedText); } } @@ -1066,7 +1062,7 @@ $(document).ready(function() { * when file upload done successfully add row to filelist * update counter when uploading to sub folder */ - file_upload_start.on('fileuploaddone', function(e, data) { + fileUploadStart.on('fileuploaddone', function(e, data) { OC.Upload.log('filelist handle fileuploaddone', e, data); var response; @@ -1080,27 +1076,28 @@ $(document).ready(function() { if (typeof result[0] !== 'undefined' && result[0].status === 'success') { var file = result[0]; + var size = 0; if (data.context && data.context.data('type') === 'dir') { // update upload counter ui - var uploadtext = data.context.find('.uploadtext'); - var currentUploads = parseInt(uploadtext.attr('currentUploads')); + var uploadText = data.context.find('.uploadtext'); + var currentUploads = parseInt(uploadText.attr('currentUploads'), 10); currentUploads -= 1; - uploadtext.attr('currentUploads', currentUploads); + uploadText.attr('currentUploads', currentUploads); var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads); if (currentUploads === 0) { var img = OC.imagePath('core', 'filetypes/folder'); data.context.find('td.filename').attr('style','background-image:url('+img+')'); - uploadtext.text(translatedText); - uploadtext.hide(); + uploadText.text(translatedText); + uploadText.hide(); } else { - uploadtext.text(translatedText); + uploadText.text(translatedText); } // update folder size - var size = parseInt(data.context.data('size')); - size += parseInt(file.size); + size = parseInt(data.context.data('size'), 10); + size += parseInt(file.size, 10); data.context.attr('data-size', size); data.context.find('td.filesize').text(humanFileSize(size)); } else { @@ -1131,8 +1128,8 @@ $(document).ready(function() { fileDirectory = FileList.findFileEl(fileDirectory); // update folder size - var size = parseInt(fileDirectory.attr('data-size')); - size += parseInt(file.size); + size = parseInt(fileDirectory.attr('data-size'), 10); + size += parseInt(file.size, 10); fileDirectory.attr('data-size', size); fileDirectory.find('td.filesize').text(humanFileSize(size)); @@ -1140,7 +1137,7 @@ $(document).ready(function() { } // add as stand-alone row to filelist - var size=t('files', 'Pending'); + size = t('files', 'Pending'); if (data.files[0].size>=0) { size=data.files[0].size; } @@ -1152,37 +1149,40 @@ $(document).ready(function() { } } }); - file_upload_start.on('fileuploadstop', function(e, data) { + fileUploadStart.on('fileuploadstop', function(e, data) { OC.Upload.log('filelist handle fileuploadstop', e, data); //if user pressed cancel hide upload chrome if (data.errorThrown === 'abort') { //cleanup uploading to a dir - var uploadtext = $('tr .uploadtext'); + var uploadText = $('tr .uploadtext'); var img = OC.imagePath('core', 'filetypes/folder'); - uploadtext.parents('td.filename').attr('style','background-image:url('+img+')'); - uploadtext.fadeOut(); - uploadtext.attr('currentUploads', 0); + uploadText.parents('td.filename').attr('style','background-image:url('+img+')'); + uploadText.fadeOut(); + uploadText.attr('currentUploads', 0); } }); - file_upload_start.on('fileuploadfail', function(e, data) { + fileUploadStart.on('fileuploadfail', function(e, data) { OC.Upload.log('filelist handle fileuploadfail', e, data); //if user pressed cancel hide upload chrome if (data.errorThrown === 'abort') { //cleanup uploading to a dir - var uploadtext = $('tr .uploadtext'); + var uploadText = $('tr .uploadtext'); var img = OC.imagePath('core', 'filetypes/folder'); - uploadtext.parents('td.filename').attr('style','background-image:url('+img+')'); - uploadtext.fadeOut(); - uploadtext.attr('currentUploads', 0); + uploadText.parents('td.filename').attr('style','background-image:url('+img+')'); + uploadText.fadeOut(); + uploadText.attr('currentUploads', 0); } }); $('#notification').hide(); $('#notification:first-child').on('click', '.replace', function() { OC.Notification.hide(function() { - FileList.replace($('#notification > span').attr('data-oldName'), $('#notification > span').attr('data-newName'), $('#notification > span').attr('data-isNewFile')); + FileList.replace( + $('#notification > span').attr('data-oldName'), + $('#notification > span').attr('data-newName'), + $('#notification > span').attr('data-isNewFile')); }); }); $('#notification:first-child').on('click', '.suggest', function() { @@ -1212,8 +1212,7 @@ $(document).ready(function() { function parseHashQuery() { var hash = window.location.hash, - pos = hash.indexOf('?'), - query; + pos = hash.indexOf('?'); if (pos >= 0) { return hash.substr(pos + 1); } @@ -1222,8 +1221,7 @@ $(document).ready(function() { function parseCurrentDirFromUrl() { var query = parseHashQuery(), - params, - dir = '/'; + params; // try and parse from URL hash first if (query) { params = OC.parseQueryString(decodeQuery(query)); From 2fc9e27ceddf9d632d79916a71f9100138bb685f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 9 Apr 2014 22:16:41 +0200 Subject: [PATCH 09/13] use FileList.findFileEl --- apps/files/js/filelist.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 8ee89aad3e..9c749bb8f3 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1098,7 +1098,8 @@ $(document).ready(function() { fileDirectory = fileDirectory[0]; // Get the directory - if ($('tr[data-file="'+fileDirectory+'"]').length === 0) { + var fd = FileList.findFileEl(fileDirectory); + if (fd.length === 0) { var dir = { name: fileDirectory, type: 'dir', From e8be2ac55492a7e4f141d3bb7e6698783bef454c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 9 Apr 2014 23:32:12 +0200 Subject: [PATCH 10/13] In cases folder drag and drop is not supported a proper message is displayed --- apps/files/js/file-upload.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 46a5320840..070314a118 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -242,11 +242,18 @@ OC.Upload = { data.errorThrown = errorMessage; } - if (file.type === '' && file.size === 4096) { - data.textStatus = 'dirorzero'; - data.errorThrown = t('files', 'Unable to upload {filename} as it is a directory or has 0 bytes', - {filename: file.name} - ); + // in case folder drag and drop is not supported file will point to a directory + if (!file.type && file.size%4096 === 0 && file.size <= 102400) { + try { + reader = new FileReader(); + reader.readAsBinaryString(f); + } catch (NS_ERROR_FILE_ACCESS_DENIED) { + //file is a directory + data.textStatus = 'dirorzero'; + data.errorThrown = t('files', 'Unable to upload {filename} as it is a directory or has 0 bytes', + {filename: file.name} + ); + } } // add size From 0edacf372c5b2e1f1b64210ceff5e757494c959b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 10 Apr 2014 18:07:36 +0200 Subject: [PATCH 11/13] fix single file upload in firefox --- apps/files/js/file-upload.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 070314a118..516812563a 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -333,11 +333,15 @@ OC.Upload = { submit: function(e, data) { OC.Upload.rememberUpload(data); if ( ! data.formData ) { + var fileDirectory = ''; + if(typeof data.files[0].relativePath !== 'undefined') { + fileDirectory = data.files[0].relativePath; + } // noone set update parameters, we set the minimum data.formData = { requesttoken: oc_requesttoken, dir: $('#dir').val(), - file_directory: data.files[0]['relativePath'] + file_directory: fileDirectory }; } }, From 07ea57465ba23dd31dae943b44f4c04ccabb5e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 11 Apr 2014 14:54:13 +0200 Subject: [PATCH 12/13] drop folder support on public shared folders --- apps/files_sharing/js/public.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 9ce8985f1f..ae2412f6a3 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -62,11 +62,17 @@ $(document).ready(function() { var file_upload_start = $('#file_upload_start'); file_upload_start.on('fileuploadadd', function(e, data) { + var fileDirectory = ''; + if(typeof data.files[0].relativePath !== 'undefined') { + fileDirectory = data.files[0].relativePath; + } + // Add custom data to the upload handler data.formData = { requesttoken: $('#publicUploadRequestToken').val(), dirToken: $('#dirToken').val(), - subdir: $('input#dir').val() + subdir: $('input#dir').val(), + file_directory: fileDirectory }; }); From 83e8981e246384de3b9d206a5dcf1109ce421005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 15 Apr 2014 21:39:13 +0200 Subject: [PATCH 13/13] add link to further discussion about that folder check --- apps/files/js/file-upload.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 516812563a..3879aa6588 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -243,6 +243,7 @@ OC.Upload = { } // in case folder drag and drop is not supported file will point to a directory + // http://stackoverflow.com/a/20448357 if (!file.type && file.size%4096 === 0 && file.size <= 102400) { try { reader = new FileReader();