Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bf196481

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

  • ID bf196481cac582a30d865f740c0e1dc7dd0d2800
  • Vorgänger b2b8017f
  • Nachfolger 9c5ae7ed

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