From 96b266d1f1e28e6869eb1a79f00d506fb2fd0df1 Mon Sep 17 00:00:00 2001 From: Markus Escher <m.escher@adito.de> Date: Tue, 27 Nov 2018 15:31:21 +0100 Subject: [PATCH] remove defaultAction add filename from uploaded file add utility methods to retrieve filename/filedata --- entity/Document_entity/Document_entity.aod | 4 +- .../bindata_upload/defaultAction.js | 2 - .../bindata_upload/onValueChange.js | 8 ++++ entity/Document_entity/onInsert.js | 3 +- entity/Document_entity/onUpdate.js | 12 ++++-- entity/Pers_entity/Pers_entity.aod | 38 +++++++++---------- process/Document_lib/process.js | 32 ++++++++++++++++ 7 files changed, 73 insertions(+), 26 deletions(-) delete mode 100644 entity/Document_entity/entityfields/bindata_upload/defaultAction.js create mode 100644 entity/Document_entity/entityfields/bindata_upload/onValueChange.js diff --git a/entity/Document_entity/Document_entity.aod b/entity/Document_entity/Document_entity.aod index 9538910600..53179f421d 100644 --- a/entity/Document_entity/Document_entity.aod +++ b/entity/Document_entity/Document_entity.aod @@ -27,6 +27,7 @@ <name>NAME</name> <title>Dateiname</title> <fieldName>FILENAME</fieldName> + <mandatory v="true" /> <state>AUTO</state> </entityField> <entityField> @@ -44,6 +45,7 @@ <title>Datum</title> <fieldName>EDIT_DATE</fieldName> <contentType>DATE</contentType> + <outputFormat>yyyy-MM-dd HH:mm:ss</outputFormat> <state>READONLY</state> </entityField> <entityField> @@ -69,7 +71,7 @@ <name>BINDATA_UPLOAD</name> <title>Datei</title> <contentType>FILE</contentType> - <defaultAction>%aditoprj%/entity/Document_entity/entityfields/bindata_upload/defaultAction.js</defaultAction> + <onValueChange>%aditoprj%/entity/Document_entity/entityfields/bindata_upload/onValueChange.js</onValueChange> </entityField> <entityActionGroup> <name>Document_actions</name> diff --git a/entity/Document_entity/entityfields/bindata_upload/defaultAction.js b/entity/Document_entity/entityfields/bindata_upload/defaultAction.js deleted file mode 100644 index 2822624e94..0000000000 --- a/entity/Document_entity/entityfields/bindata_upload/defaultAction.js +++ /dev/null @@ -1,2 +0,0 @@ -import("system.logging"); -logging.log("document default action"); \ No newline at end of file diff --git a/entity/Document_entity/entityfields/bindata_upload/onValueChange.js b/entity/Document_entity/entityfields/bindata_upload/onValueChange.js new file mode 100644 index 0000000000..71f1f3c4db --- /dev/null +++ b/entity/Document_entity/entityfields/bindata_upload/onValueChange.js @@ -0,0 +1,8 @@ +import("system.logging"); +import("system.vars"); +import("system.neon"); +import("Util_lib"); +import("Document_lib"); + +var uploadValue = ProcessHandlingUtil.getOnValidationValue(vars.get("$field.BINDATA_UPLOAD")); +neon.setFieldValue("$field.NAME", DocumentUtil.getFilenameFromUpload(uploadValue)); diff --git a/entity/Document_entity/onInsert.js b/entity/Document_entity/onInsert.js index 9373df97d6..5bb825c7b8 100644 --- a/entity/Document_entity/onInsert.js +++ b/entity/Document_entity/onInsert.js @@ -1,11 +1,12 @@ import("system.logging"); import("system.db"); import("system.vars"); +import("Document_lib"); var assignmentTable = vars.get("$param.AssignmentTable_param"); var assignmentName = vars.get("$param.AssignmentName_param"); var assignmentRowId = vars.get("$param.AssignmentRowId_param"); -var bindata = vars.get("$field.BINDATA_UPLOAD"); +var bindata = DocumentUtil.getBindataFromUpload(vars.get("$field.BINDATA_UPLOAD")); var filename = vars.get("$field.NAME"); var description = vars.get("$field.DESCRIPTION"); var alias = db.getCurrentAlias(); diff --git a/entity/Document_entity/onUpdate.js b/entity/Document_entity/onUpdate.js index acd28548e7..b43e4f3eae 100644 --- a/entity/Document_entity/onUpdate.js +++ b/entity/Document_entity/onUpdate.js @@ -1,6 +1,7 @@ import("system.vars"); import("system.db"); import("system.logging"); +import("Document_lib"); var id = vars.get("$field.ID"); var parentId = ""; @@ -8,10 +9,15 @@ var fileName = vars.get("$field.NAME"); var description = vars.get("$field.DESCRIPTION"); var keyword = ""; var alias = db.getCurrentAlias(); -var base64data = vars.get("$field.BINDATA_UPLOAD"); + +var bindata = DocumentUtil.getBindataFromUpload(vars.get("$field.BINDATA_UPLOAD")); + +if (bindata == ''){ + bindata = vars.get("$field.BINDATA_UPLOAD") +} // Check if bindata is present and execute the corresponding update method -if(base64data != '') - db.updateBinary(id, parentId, base64data, fileName, description, keyword, alias); +if(bindata != '') + db.updateBinary(id, parentId, bindata, fileName, description, keyword, alias); else db.updateBinaryMetadata(id, parentId, fileName, description, keyword, alias); \ No newline at end of file diff --git a/entity/Pers_entity/Pers_entity.aod b/entity/Pers_entity/Pers_entity.aod index b9ad55a7ef..7d6620665e 100644 --- a/entity/Pers_entity/Pers_entity.aod +++ b/entity/Pers_entity/Pers_entity.aod @@ -10,6 +10,25 @@ <alias>Data_alias</alias> <fromClauseProcess>%aditoprj%/entity/Pers_entity/fromClauseProcess.js</fromClauseProcess> <conditionProcess>%aditoprj%/entity/Pers_entity/conditionProcess.js</conditionProcess> + <linkInformation> + <linkInformation> + <name>9ce0dfd2-192d-4446-8b2d-a4c053abc44a</name> + <tableName>PERS</tableName> + <primaryKey>PERSID</primaryKey> + </linkInformation> + <linkInformation> + <name>348312a8-6392-4adb-af69-75cbcfc5b65b</name> + <tableName>RELATION</tableName> + <primaryKey>RELATIONID</primaryKey> + <isUIDTable v="true" /> + </linkInformation> + <linkInformation> + <name>edf5e4f3-993d-4097-b59d-a100d5222cad</name> + <tableName>ORG</tableName> + <primaryKey>ORGID</primaryKey> + <readonly v="true" /> + </linkInformation> + </linkInformation> <entityFields> <entityField> <name>DATEOFBIRTH</name> @@ -449,23 +468,4 @@ <description>PARAMETER</description> </entityParameter> </entityFields> - <linkInformation> - <linkInformation> - <name>9ce0dfd2-192d-4446-8b2d-a4c053abc44a</name> - <tableName>PERS</tableName> - <primaryKey>PERSID</primaryKey> - </linkInformation> - <linkInformation> - <name>348312a8-6392-4adb-af69-75cbcfc5b65b</name> - <tableName>RELATION</tableName> - <primaryKey>RELATIONID</primaryKey> - <isUIDTable v="true" /> - </linkInformation> - <linkInformation> - <name>edf5e4f3-993d-4097-b59d-a100d5222cad</name> - <tableName>ORG</tableName> - <primaryKey>ORGID</primaryKey> - <readonly v="true" /> - </linkInformation> - </linkInformation> </entity> diff --git a/process/Document_lib/process.js b/process/Document_lib/process.js index 4b811e6a60..11f51c0fff 100644 --- a/process/Document_lib/process.js +++ b/process/Document_lib/process.js @@ -53,3 +53,35 @@ DocumentUtil.deleteCurrentDocument = function() { db.deleteBinary(uid, alias); } } + +/** + * Utility function to retrieve the filename from an uploadcomponent value. + * The value of an uploadcomponent contains filename + filedata separated by + * a semicolon e.g. "file1.jpg;base64data" + * + * @param {String} pUploadValue the value of the uploadcomponent (filename + filedata) + * @return {String} the filename or empty String + */ +DocumentUtil.getFilenameFromUpload = function(pUploadValue) { + var result = pUploadValue.split(";"); + if(result.length > 0) + return result[0]; + else + return ''; +} + +/** + * Utility function to retrieve the filedata from an uploadcomponent value. + * The value of an uploadcomponent contains filename + filedata separated by + * a semicolon e.g. "file1.jpg;base64data" + * + * @param {String} pUploadValue the value of the uploadcomponent (filename + filedata) + * @return {String} the filedata or empty String + */ +DocumentUtil.getBindataFromUpload = function(pUploadValue) { + var result = pUploadValue.split(";"); + if(result.length > 1) + return result[1]; + else + return ''; +} \ No newline at end of file -- GitLab