]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blobdiff - frontend/js/app.js
We cannot have one button/input type for both folders and files for upload
[perso/Immae/Projets/Nodejs/Surfer.git] / frontend / js / app.js
index 8970a0f8b6c3d379fa6fba545bbcc51cfdac931d..9d7bacaa1cd4887420714d558972aea1aa7ba420 100644 (file)
@@ -136,7 +136,10 @@ function uploadFiles(files) {
     app.uploadStatus.percentDone = 0;
 
     asyncForEach(files, function (file, callback) {
-        var path = encode(sanitize(app.path + '/' + file.name));
+        // do not handle directories (file.type is empty in such a case)
+        if (file.type === '') return callback();
+
+        var path = encode(sanitize(app.path + '/' + (file.webkitRelativePath || file.name)));
 
         var formData = new FormData();
         formData.append('file', file);
@@ -164,10 +167,13 @@ function uploadFiles(files) {
 }
 
 function dragOver(event) {
+    event.stopPropagation();
     event.preventDefault();
+    event.dataTransfer.dropEffect = 'copy';
 }
 
 function drop(event) {
+    event.stopPropagation();
     event.preventDefault();
     uploadFiles(event.dataTransfer.files || []);
 }
@@ -250,10 +256,8 @@ var app = new Vue({
             var that = this;
 
             $(this.$refs.upload).on('change', function () {
-
                 // detach event handler
                 $(that.$refs.upload).off('change');
-
                 uploadFiles(that.$refs.upload.files || []);
             });
 
@@ -261,6 +265,19 @@ var app = new Vue({
             this.$refs.upload.value = '';
             this.$refs.upload.click();
         },
+        onUploadFolder: function () {
+            var that = this;
+
+            $(this.$refs.uploadFolder).on('change', function () {
+                // detach event handler
+                $(that.$refs.uploadFolder).off('change');
+                uploadFiles(that.$refs.uploadFolder.files || []);
+            });
+
+            // reset the form first to make the change handler retrigger even on the same file selected
+            this.$refs.uploadFolder.value = '';
+            this.$refs.uploadFolder.click();
+        },
         onDelete: function (entry) {
             var that = this;