Order/Form: documents can be uploaded even if order is closed already

This commit is contained in:
Frank Schubert
2025-10-09 15:33:24 +02:00
parent c5f60f96c3
commit 15bb02de52
4 changed files with 127 additions and 26 deletions

View File

@@ -1041,7 +1041,7 @@
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="note">Datei auswählen</label>
<div class="col-lg-10">
<input type="file" name="OrderFileUpload" class="form-control" />
<input type="file" name="OrderFileUpload" id="OrderFileUpload" class="form-control" />
<small>Erlaubte Dateiendungen: <?=MFUPLOAD_ALLOWED_EXTENSIONS_STR?></small>
</div>
</div>
@@ -1823,9 +1823,47 @@
//$("#orderForm").detach();
/*$("#upload-button").click(() => {
$("#orderForm").wrap('<form method="post" enctype="formdata/');
});*/
$("#upload-button").click(async () => {
// ajax upload
const selectedFile = document.getElementById("OrderFileUpload").files[0];
console.log(selectedFile);
const reader = new FileReader();
reader.onload = async () => {
const fileContent = reader.result;
//console.log(fileContent);
formdata = new FormData();
formdata.append("id", <?=$order->id?>);
formdata.append("file_name", $("#order-files select").val());
//formdata.append("orig_filename", selectedFile.name);
formdata.append("file_description", $("#order-files textarea[name='file_description']").val());
formdata.append("file_contents", new Blob([fileContent]), selectedFile.name);
await fetch("<?=self::getUrl("Order", "api", ["do" => "uploadDocument"])?>", {
body: formdata,
method: "POST",
}).then(resp => {
if (resp.ok) {
return resp.json();
}
}).then(data => {
if(data.status == "OK") {
window.location.replace(window.location.href);
} else {
window.notify("error", "Fehler beim Dateiupload!");
}
}).catch(err => {
window.notify("error", "Fehler beim Dateiupload!");
console.log(err);
});
}
reader.readAsText(selectedFile);
});
$("#upload-button").show();