ImageUpload: multiupload in einem request
authorSven Schöling <s.schoeling@googlemail.com>
Fri, 14 May 2021 16:43:25 +0000 (18:43 +0200)
committerSven Schöling <s.schoeling@googlemail.com>
Fri, 25 Jun 2021 13:51:32 +0000 (15:51 +0200)
js/kivi.ImageUpload.js

index e655b54..2556646 100644 (file)
@@ -73,41 +73,39 @@ namespace("kivi.ImageUpload", function(ns) {
 
     kivi.FileDB.retrieve_all((myfiles) => {
       let filesize  = 0;
-      myfiles.forEach(file => {
-        filesize  += file.size;
-        if (filesize > maxsize) {
-          M.flash(kivi.t8("filesize too big: ") + ns.format_si(filesize) + kivi.t8(" > ") + ns.format_si(maxsize));
-          $("#upload_modal").modal("close");
-          return;
-        }
+      myfiles.forEach(file => filesize  += file.size);
+
+      if (filesize > maxsize) {
+        M.flash(kivi.t8("filesize too big: ") + ns.format_si(filesize) + kivi.t8(" > ") + ns.format_si(maxsize));
+        $("#upload_modal").modal("close");
+        return;
+      }
 
-        let data = new FormData();
-        data.append("uploadfiles[]", file);
-        data.append("action", "File/ajax_files_uploaded");
-        data.append("json", "1");
-        data.append("object_type", type);
-        data.append("object_id", id);
-        data.append("file_type", "attachment");
-
-        $("#upload_result").html(kivi.t8("start upload"));
-
-        let xhr = new XMLHttpRequest;
-        xhr.open('POST', 'controller.pl', true);
-        xhr.onload = ns.upload_complete;
-        xhr.upload.onprogress = ns.progress;
-        xhr.upload.onerror = ns.failed;
-        xhr.upload.onabort = ns.abort;
-        xhr.send(data);
-
-        ns.upload_in_progress = xhr;
-      });
+      let data = new FormData();
+      myfiles.forEach(file => data.append("uploadfiles[]", file));
+      data.append("action", "File/ajax_files_uploaded");
+      data.append("json", "1");
+      data.append("object_type", type);
+      data.append("object_id", id);
+      data.append("file_type", "attachment");
+
+      $("#upload_result").html(kivi.t8("start upload"));
+
+      let xhr = new XMLHttpRequest;
+      xhr.open('POST', 'controller.pl', true);
+      xhr.onload = ns.upload_complete;
+      xhr.upload.onprogress = ns.progress;
+      xhr.upload.onerror = ns.failed;
+      xhr.upload.onabort = ns.abort;
+      xhr.send(data);
+
+      ns.upload_in_progress = xhr;
     });
   };
 
   ns.progress = function(event) {
     if (event.lengthComputable) {
       var percent_complete = (event.loaded / event.total) * 100;
-      console.log(percent_complete);
       $("#upload_progress div").removeClass("indeterminate").addClass("determinate").attr("style", "width: " + percent_complete + "%");
     }
   };