Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 13914731

Von Sven Schöling vor mehr als 3 Jahren hinzugefügt

  • ID 139147317f2179d4205abe5c9c4fa5aa876ff66d
  • Vorgänger a7211172
  • Nachfolger f0e76e67

ImageUpload: multiupload in einem request

Unterschiede anzeigen:

js/kivi.ImageUpload.js
73 73

  
74 74
    kivi.FileDB.retrieve_all((myfiles) => {
75 75
      let filesize  = 0;
76
      myfiles.forEach(file => {
77
        filesize  += file.size;
78
        if (filesize > maxsize) {
79
          M.flash(kivi.t8("filesize too big: ") + ns.format_si(filesize) + kivi.t8(" > ") + ns.format_si(maxsize));
80
          $("#upload_modal").modal("close");
81
          return;
82
        }
76
      myfiles.forEach(file => filesize  += file.size);
77

  
78
      if (filesize > maxsize) {
79
        M.flash(kivi.t8("filesize too big: ") + ns.format_si(filesize) + kivi.t8(" > ") + ns.format_si(maxsize));
80
        $("#upload_modal").modal("close");
81
        return;
82
      }
83 83

  
84
        let data = new FormData();
85
        data.append("uploadfiles[]", file);
86
        data.append("action", "File/ajax_files_uploaded");
87
        data.append("json", "1");
88
        data.append("object_type", type);
89
        data.append("object_id", id);
90
        data.append("file_type", "attachment");
91

  
92
        $("#upload_result").html(kivi.t8("start upload"));
93

  
94
        let xhr = new XMLHttpRequest;
95
        xhr.open('POST', 'controller.pl', true);
96
        xhr.onload = ns.upload_complete;
97
        xhr.upload.onprogress = ns.progress;
98
        xhr.upload.onerror = ns.failed;
99
        xhr.upload.onabort = ns.abort;
100
        xhr.send(data);
101

  
102
        ns.upload_in_progress = xhr;
103
      });
84
      let data = new FormData();
85
      myfiles.forEach(file => data.append("uploadfiles[]", file));
86
      data.append("action", "File/ajax_files_uploaded");
87
      data.append("json", "1");
88
      data.append("object_type", type);
89
      data.append("object_id", id);
90
      data.append("file_type", "attachment");
91

  
92
      $("#upload_result").html(kivi.t8("start upload"));
93

  
94
      let xhr = new XMLHttpRequest;
95
      xhr.open('POST', 'controller.pl', true);
96
      xhr.onload = ns.upload_complete;
97
      xhr.upload.onprogress = ns.progress;
98
      xhr.upload.onerror = ns.failed;
99
      xhr.upload.onabort = ns.abort;
100
      xhr.send(data);
101

  
102
      ns.upload_in_progress = xhr;
104 103
    });
105 104
  };
106 105

  
107 106
  ns.progress = function(event) {
108 107
    if (event.lengthComputable) {
109 108
      var percent_complete = (event.loaded / event.total) * 100;
110
      console.log(percent_complete);
111 109
      $("#upload_progress div").removeClass("indeterminate").addClass("determinate").attr("style", "width: " + percent_complete + "%");
112 110
    }
113 111
  };

Auch abrufbar als: Unified diff