[Preventivi]
- Fix upload allegati
This commit is contained in:
@@ -112,8 +112,7 @@ class MtbAartLink {
|
||||
|
||||
public static function upload($codMart, $fileItems) {
|
||||
$Ret = new Ret;
|
||||
|
||||
$fileItems = \Utility\File::rearrangeFilesArray($fileItems["files"]);
|
||||
$fileItems = \Utility\File::rearrangeFilesArray(array_get($fileItems, "files", $fileItems));
|
||||
|
||||
foreach ($fileItems as $fileItem) {
|
||||
if (file_exists($fileItem["tmp_name"])) {
|
||||
|
||||
@@ -35,10 +35,8 @@ if (isset($_GET["load_filters"])) {
|
||||
} else if (isset($_POST["upload_allegato"])) {
|
||||
$Ret = new Ret;
|
||||
if (count($_FILES) > 0) {
|
||||
$files = array_values($_FILES);
|
||||
$file = $files[0];
|
||||
$data = Utility::B64JSON_parse($_POST["upload_allegato"]);
|
||||
$Ret = Catalogo\Prodotto::upload_allegato($data, $file);
|
||||
$Ret = Catalogo\Prodotto::upload_allegato($data, $_FILES);
|
||||
} else {
|
||||
$Ret->set_error("File non pervenuto");
|
||||
}
|
||||
|
||||
@@ -23,24 +23,25 @@ $(function () {
|
||||
});
|
||||
|
||||
$(document).on("change", "#m_fileAllegato", function (e) {
|
||||
var $file = $(this);
|
||||
if (!is_null($file.getValue())) {
|
||||
var $toDisable = $file.closest(".modal-content").children();
|
||||
const $file = $(this);
|
||||
|
||||
if (!is_null($file.getValue())) {
|
||||
const $toDisable = $file.closest(".modal-content").children();
|
||||
const data = {codMart: _catalogo.product.codMart};
|
||||
const ajax = new Ajax();
|
||||
|
||||
var data = {codMart: _catalogo.product.codMart};
|
||||
var ajax = new Ajax();
|
||||
ajax.post("upload_allegato")
|
||||
.data(data)
|
||||
.file($file)
|
||||
.file($file, true)
|
||||
.$button($("#m_btAllega"))
|
||||
.$toDisable($toDisable)
|
||||
.noticeAsModal()
|
||||
.onSuccess(function (ret) {
|
||||
_catalogo.product.allegato.callbackOK(ret.returnData);
|
||||
var toast = new Toast();
|
||||
const toast = new Toast();
|
||||
toast.success("Il file <b>" + ret.returnData.path_link + "</b> è stato aggiunto");
|
||||
|
||||
var $tr = $(ret.returnString);
|
||||
const $tr = $(ret.returnString);
|
||||
$("#m_tbAllegati").children("tbody").append($tr);
|
||||
$tr.highlightRow();
|
||||
})
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
<?php
|
||||
|
||||
if (isset($_GET["get_listDepo"])) {
|
||||
$data = Utility::sanitizeB64JSON_parse($_GET["get_listDepo"]);
|
||||
FileExchangePanel::get_listDepo($data)->display();
|
||||
|
||||
} else if (isset($_POST["transmit"])) {
|
||||
$data = Utility::sanitizeB64JSON_parse($_POST["transmit"]);
|
||||
$files = array_values($_FILES);
|
||||
$file = $files[0];
|
||||
FileExchangePanel::transmit($data, $file)->display();
|
||||
|
||||
} else if (isset($_GET["get_log"])) {
|
||||
$data = Utility::sanitizeB64JSON_parse($_GET["get_log"]);
|
||||
FileExchangePanel::get_log($data)->display();
|
||||
|
||||
}
|
||||
@@ -73,6 +73,7 @@ function Ajax() {
|
||||
this._modalWaiter = false;
|
||||
this._toastWaiter = false;
|
||||
this._arrFiles = null;
|
||||
this._multipleUpload = false;
|
||||
this._requestParam = null;
|
||||
this._ajaxObjOptions = null;
|
||||
this._jqxhr = null;
|
||||
@@ -160,15 +161,22 @@ Ajax.prototype.execute = function (callback = undefined, arrayEncode = true) {
|
||||
}
|
||||
|
||||
if (!is_null(self._arrFiles) || !is_null(self._formData)) { // INVIO FORM + FILE
|
||||
var formData = new FormData();
|
||||
if (!is_null(self._arrFiles)) {
|
||||
$.each(self._arrFiles, function (i, $file) {
|
||||
for (var j = 0; j < $file.get(0).files.length; j++) {
|
||||
var fileItem = $file.get(0).files[j];
|
||||
formData.append(fileItem.name, fileItem);
|
||||
}
|
||||
});
|
||||
let formData = new FormData();
|
||||
|
||||
if (!is_null(self._arrFiles)) {
|
||||
if (self._multipleUpload) {
|
||||
Array.from(self._arrFiles).forEach(file => formData.append("files[]", file));
|
||||
} else {
|
||||
const fileItem = self._arrFiles[0];
|
||||
formData.append(fileItem.name, fileItem);
|
||||
}
|
||||
|
||||
// $.each(self._arrFiles, function (i, $file) {
|
||||
// for (var j = 0; j < $file.get(0).files.length; j++) {
|
||||
// var fileItem = $file.get(0).files[j];
|
||||
// formData.append(fileItem.name, fileItem);
|
||||
// }
|
||||
// });
|
||||
} else {
|
||||
formData = self._formData;
|
||||
}
|
||||
@@ -780,11 +788,13 @@ Ajax.prototype.method = function (v) {
|
||||
return this;
|
||||
};
|
||||
|
||||
Ajax.prototype.file = function ($file) {
|
||||
Ajax.prototype.file = function ($file, multipleUpload = false) {
|
||||
if (is_null(this._arrFiles)) {
|
||||
this._arrFiles = [];
|
||||
}
|
||||
this._arrFiles.push($file);
|
||||
|
||||
this._multipleUpload = multipleUpload;
|
||||
this._arrFiles = $file.get(0).files;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user