Skip to content
Snippets Groups Projects
Commit 6527c7a2 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

lead import fix file upload in edit mode

parent 3a1e953e
No related branches found
No related tags found
No related merge requests found
......@@ -279,10 +279,6 @@
<onActionProcess>%aditoprj%/entity/Leadimport_entity/entityfields/uploadnewfile/onActionProcess.js</onActionProcess>
<iconId>VAADIN:UPLOAD_ALT</iconId>
</entityActionField>
<entityParameter>
<name>LeadimportNewFile_param</name>
<expose v="true" />
</entityParameter>
<entityField>
<name>information</name>
<title>Warning</title>
......
......@@ -5,17 +5,15 @@ import("system.vars");
import("system.db");
import("Document_lib");
if (vars.get("$sys.recordstate") && vars.get("$sys.recordstate") != neon.OPERATINGSTATE_NEW && vars.get("$sys.recordstate") != neon.OPERATINGSTATE_EDIT)
if (vars.get("$sys.recordstate") && vars.get("$sys.recordstate") != neon.OPERATINGSTATE_NEW && vars.get("$this.value") == null)
{
var binMetadatas = db.getBinaryMetadata("LEADIMPORT", "IMPORTFILE", vars.get("$field.LEADIMPORTID"), false, SqlUtils.getBinariesAlias(), "");
if (binMetadatas.length > 0)
{
// preset with data from db. This is mostly to allow just editing the other fields without uploading a file (because this field is mandatory)
var resultValue = binMetadatas[0].filename;
resultValue += ";" + db.getBinaryContent(binMetadatas[0].id, SqlUtils.getBinariesAlias());
resultValue += ";" + binMetadatas[0].mimetype;
result.string(resultValue);
// preset the field. This is to allow just editing the other fields without uploading a file (because this field is mandatory)
// if the user did not upload a file "FILE NOT CHANGED" will be still in the field in onDBUpdate and nothing has to be done there
// --> this is a marking that the field didn't change
result.string("FILE NOT CHANGED");
} else {
result.string("FILE MISSING");
}
......
import("system.neon");
import("system.vars");
var prompts = new Array();
prompts["LeadimportNewFile_param"] = true;
neon.openContext("Leadimport", "LeadimportDocEdit_view", [vars.getString("$field.LEADIMPORTID")], neon.OPERATINGSTATE_EDIT, prompts);
\ No newline at end of file
neon.openContext("Leadimport", "LeadimportDocEdit_view", [vars.getString("$field.LEADIMPORTID")], neon.OPERATINGSTATE_EDIT, []);
\ No newline at end of file
......@@ -23,5 +23,4 @@ if(bindata != '' && filename != '')
var documentId = SingleBinaryUtils.insertMainDocument("LEADIMPORT", "IMPORTFILE", assignmentRowId, bindata, filename, "", SqlUtils.getBinariesAlias());
LeadImportUtils.loadImportFile(documentId, fieldSep, fieldLimit, recordSep, assignmentRowId);
}
}
}
\ No newline at end of file
......@@ -6,28 +6,32 @@ import("Binary_lib");
import("Leadimport_lib");
import("system.db");
import("system.vars");
import("system.util");
import("Document_lib");
var assignmentRowId = vars.get("$field.LEADIMPORTID");
var bindata = DocumentUtil.getBindataFromUpload(vars.get("$field.bindata"));
var filename = DocumentUtil.getFilenameFromUpload(vars.get("$field.bindata"));
var fieldSep = LeadImportUtils.getFieldSeparator(vars.get("$field.FIELDSEPARATOR"));
var fieldLimit = LeadImportUtils.getFieldLimit(vars.get("$field.FIELDDELIMITERS"));
var recordSep = LeadImportUtils.getRecordSeparator(vars.get("$field.SENTENCESEPARATOR"));
if(bindata != '' && filename != '')
// "FILE NOT CHANGED" is set in the value process of the field to indicate that the user didn't upload a new file
if (vars.get("$field.bindata") != "FILE NOT CHANGED")
{
var mimeType = DocumentUtil.getMimeTypeFromUpload(vars.get("$field.bindata"));
var assignmentRowId = vars.get("$field.LEADIMPORTID");
var bindata = DocumentUtil.getBindataFromUpload(vars.get("$field.bindata"));
var filename = DocumentUtil.getFilenameFromUpload(vars.get("$field.bindata"));
var fieldSep = LeadImportUtils.getFieldSeparator(vars.get("$field.FIELDSEPARATOR"));
var fieldLimit = LeadImportUtils.getFieldLimit(vars.get("$field.FIELDDELIMITERS"));
var recordSep = LeadImportUtils.getRecordSeparator(vars.get("$field.SENTENCESEPARATOR"));
if (mimeType == "application/vnd.ms-excel")
if(bindata != '' && filename != '')
{
var binMetadata = db.getBinaryMetadata("LEADIMPORT", "IMPORTFILE", assignmentRowId, false, SqlUtils.getBinariesAlias(), "MAINDOCUMENT");
if (binMetadata.length > 0) {
db.updateBinary(binMetadata[0].id, "", bindata, filename, "", "MAINDOCUMENT", SqlUtils.getBinariesAlias());
LeadImportUtils.loadImportFile(binMetadata[0].id, fieldSep, fieldLimit, recordSep, assignmentRowId, true, vars.get("$param.LeadimportNewFile_param"));
var mimeType = DocumentUtil.getMimeTypeFromUpload(vars.get("$field.bindata"));
if (mimeType == "application/vnd.ms-excel")
{
var binMetadata = db.getBinaryMetadata("LEADIMPORT", "IMPORTFILE", assignmentRowId, false, SqlUtils.getBinariesAlias(), "");
if (binMetadata.length > 0) {
db.updateBinary(binMetadata[0].id, "", bindata, filename, "", "MAINDOCUMENT", SqlUtils.getBinariesAlias());
LeadImportUtils.loadImportFile(binMetadata[0].id, fieldSep, fieldLimit, recordSep, assignmentRowId, true, true);
}
}
}
}
neon.refreshAll();
\ No newline at end of file
neon.refreshAll();
}
......@@ -101,7 +101,7 @@ LeadImportUtils.loadImportFile = function(pBinId, pFieldSep, pFieldLimit, pRecor
var data = db.getBinaryContent(pBinId, SqlUtils.getBinariesAlias());
data = util.decodeBase64String(data, "UTF-8");
var table = text.parseCSV(data.replace(/(^\s+)|(\s+$)/g,""), pRecordSep, pFieldSep, pFieldLimit.charAt(0));
if (pNewFile != "true")
if (pNewFile)
{
if (pUpdate) {
db.deleteData("IMPORTFIELD", newWhere("IMPORTFIELD.LEADIMPORT_ID", pLeadImportId).build());
......@@ -112,7 +112,7 @@ LeadImportUtils.loadImportFile = function(pBinId, pFieldSep, pFieldLimit, pRecor
insertVals = [util.getNewUUID(), table[0][i], pLeadImportId, vars.getString("$sys.date"), vars.getString("$sys.user"), i.toString()];
toInsert.push([insertTable, insertCols, insertTypes, insertVals]);
}
db.inserts(toInsert);
db.inserts(toInsert);
}
db.deleteData("LEADTEMP", newWhere("LEADTEMP.ROW_ID", pLeadImportId).build());//delete existing temp data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment