From: Sven Schöling Date: Fri, 14 May 2021 16:43:25 +0000 (+0200) Subject: ImageUpload: multiupload in einem request X-Git-Tag: kivitendo-mebil_0.1-0~9^2~69 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=bf196481cac582a30d865f740c0e1dc7dd0d2800;p=kivitendo-erp.git ImageUpload: multiupload in einem request --- diff --git a/js/kivi.ImageUpload.js b/js/kivi.ImageUpload.js index e655b54fb..25566467c 100644 --- a/js/kivi.ImageUpload.js +++ b/js/kivi.ImageUpload.js @@ -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 + "%"); } };