Ver Fonte

Attachment, upload all selected files

- until now only the first attachment was uploaded
Martin Filser há 3 anos atrás
pai
commit
a6b4a698af
1 ficheiros alterados com 27 adições e 23 exclusões
  1. 27 23
      client/components/cards/attachments.js

+ 27 - 23
client/components/cards/attachments.js

@@ -20,30 +20,34 @@ Template.attachmentsGalery.helpers({
 Template.cardAttachmentsPopup.events({
 Template.cardAttachmentsPopup.events({
   'change .js-attach-file'(event) {
   'change .js-attach-file'(event) {
     const card = this;
     const card = this;
-    if (event.currentTarget.files && event.currentTarget.files[0]) {
-      const fileId = Random.id();
-      const config = {
-        file: event.currentTarget.files[0],
-        fileId: fileId,
-        meta: Utils.getCommonAttachmentMetaFrom(card),
-        chunkSize: 'dynamic',
-      };
-      config.meta.fileId = fileId;
-      const uploader = Attachments.insert(
-        config,
-        false,
-      );
-      uploader.on('uploaded', (error, fileRef) => {
-        if (!error) {
-          if (fileRef.isImage) {
-            card.setCover(fileRef._id);
+    const files = event.currentTarget.files;
+    if (files) {
+      let finished = [];
+      for (const file of files) {
+        const fileId = Random.id();
+        const config = {
+          file: file,
+          fileId: fileId,
+          meta: Utils.getCommonAttachmentMetaFrom(card),
+          chunkSize: 'dynamic',
+        };
+        config.meta.fileId = fileId;
+        const uploader = Attachments.insert(
+          config,
+          false,
+        );
+        uploader.on('uploaded', (error, fileRef) => {
+          if (!error) {
+            if (fileRef.isImage) {
+              card.setCover(fileRef._id);
+            }
           }
           }
-        }
-      });
-      uploader.on('end', (error, fileRef) => {
-        Popup.back();
-      });
-      uploader.start();
+        });
+        uploader.on('end', (error, fileRef) => {
+          Popup.back();
+        });
+        uploader.start();
+      }
     }
     }
   },
   },
   'click .js-computer-upload'(event, templateInstance) {
   'click .js-computer-upload'(event, templateInstance) {