From 4bd6acc54e205267b9a57c92c369f0885a20e241 Mon Sep 17 00:00:00 2001
From: Markus Escher <m.escher@adito.de>
Date: Tue, 27 Nov 2018 11:38:45 +0100
Subject: [PATCH] add description field add update process

---
 entity/Document_entity/Document_entity.aod      |  9 +++++++++
 entity/Document_entity/contentProcess.js        |  4 ++--
 entity/Document_entity/onInsert.js              |  3 ++-
 entity/Document_entity/onUpdate.js              | 17 +++++++++++++++++
 .../DocumentEdit_view/DocumentEdit_view.aod     |  4 ++++
 .../DocumentPreview_view.aod                    |  2 +-
 6 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/entity/Document_entity/Document_entity.aod b/entity/Document_entity/Document_entity.aod
index f943b39d25..9538910600 100644
--- a/entity/Document_entity/Document_entity.aod
+++ b/entity/Document_entity/Document_entity.aod
@@ -13,6 +13,7 @@
     <element>EDIT_DATE</element>
     <element>PREVIEW</element>
     <element>FILETYPE</element>
+    <element>DESCRIPTION</element>
   </fields>
   <contentProcess>%aditoprj%/entity/Document_entity/contentProcess.js</contentProcess>
   <onInsert>%aditoprj%/entity/Document_entity/onInsert.js</onInsert>
@@ -26,6 +27,7 @@
       <name>NAME</name>
       <title>Dateiname</title>
       <fieldName>FILENAME</fieldName>
+      <state>AUTO</state>
     </entityField>
     <entityField>
       <name>TYPE</name>
@@ -42,6 +44,7 @@
       <title>Datum</title>
       <fieldName>EDIT_DATE</fieldName>
       <contentType>DATE</contentType>
+      <state>READONLY</state>
     </entityField>
     <entityField>
       <name>PREVIEW_IMAGE</name>
@@ -113,5 +116,11 @@
       <name>ID</name>
       <fieldName>UID</fieldName>
     </entityField>
+    <entityField>
+      <name>DESCRIPTION</name>
+      <title>Beschreibung</title>
+      <fieldName>DESCRIPTION</fieldName>
+      <contentType>LONG_TEXT</contentType>
+    </entityField>
   </entityFields>
 </entity>
diff --git a/entity/Document_entity/contentProcess.js b/entity/Document_entity/contentProcess.js
index 1b32f4aed3..dec0105ea7 100644
--- a/entity/Document_entity/contentProcess.js
+++ b/entity/Document_entity/contentProcess.js
@@ -18,10 +18,10 @@ if(vars.exists("$param.AssignmentTable_param") &&
     else
         metadata = db.getBinaryMetadata(assignmentTable, assignmentName, assignmentRowId, false, alias);    
 
-    // Iterate through found binaray data and populate result array    
+    // Iterate through found binary data and populate result array    
     for( var i = 0; i < metadata.length; i++) {
         documents.push( [metadata[i].id, metadata[i].filename, metadata[i].size, 
-            metadata[i].edit, metadata[i].preview, metadata[i].mimetype]);
+            metadata[i].edit, metadata[i].preview, metadata[i].mimetype, metadata[i].description]);
     }
 
     result.object(documents);
diff --git a/entity/Document_entity/onInsert.js b/entity/Document_entity/onInsert.js
index 5f9dddf1cc..9373df97d6 100644
--- a/entity/Document_entity/onInsert.js
+++ b/entity/Document_entity/onInsert.js
@@ -7,7 +7,8 @@ var assignmentName = vars.get("$param.AssignmentName_param");
 var assignmentRowId = vars.get("$param.AssignmentRowId_param");
 var bindata = vars.get("$field.BINDATA_UPLOAD");
 var filename = vars.get("$field.NAME");
+var description = vars.get("$field.DESCRIPTION");
 var alias = db.getCurrentAlias();
 
 if(bindata != '' && filename != '')    
-    db.insertBinary(assignmentTable, assignmentName, assignmentRowId, "", bindata, filename, "", "", alias);
+    db.insertBinary(assignmentTable, assignmentName, assignmentRowId, "", bindata, filename, description, "", alias);
diff --git a/entity/Document_entity/onUpdate.js b/entity/Document_entity/onUpdate.js
index e69de29bb2..acd28548e7 100644
--- a/entity/Document_entity/onUpdate.js
+++ b/entity/Document_entity/onUpdate.js
@@ -0,0 +1,17 @@
+import("system.vars");
+import("system.db");
+import("system.logging");
+
+var id = vars.get("$field.ID");
+var parentId = "";
+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");
+
+// Check if bindata is present and execute the corresponding update method
+if(base64data != '')
+    db.updateBinary(id, parentId, base64data, fileName, description, keyword, alias);
+else
+    db.updateBinaryMetadata(id, parentId, fileName, description, keyword, alias);
\ No newline at end of file
diff --git a/neonView/DocumentEdit_view/DocumentEdit_view.aod b/neonView/DocumentEdit_view/DocumentEdit_view.aod
index 7aced50b64..ec8d9dd634 100644
--- a/neonView/DocumentEdit_view/DocumentEdit_view.aod
+++ b/neonView/DocumentEdit_view/DocumentEdit_view.aod
@@ -17,6 +17,10 @@
           <name>91d96ac4-d838-4f92-90e7-954166b57288</name>
           <entityField>NAME</entityField>
         </entityFieldLink>
+        <entityFieldLink>
+          <name>253b8716-bdec-4e24-8540-7513d934693b</name>
+          <entityField>DESCRIPTION</entityField>
+        </entityFieldLink>
         <entityFieldLink>
           <name>7d74c495-1af7-4e00-8a78-5787e544e101</name>
           <entityField>BINDATA_UPLOAD</entityField>
diff --git a/neonView/DocumentPreview_view/DocumentPreview_view.aod b/neonView/DocumentPreview_view/DocumentPreview_view.aod
index 3e40deed86..102f644379 100644
--- a/neonView/DocumentPreview_view/DocumentPreview_view.aod
+++ b/neonView/DocumentPreview_view/DocumentPreview_view.aod
@@ -12,7 +12,7 @@
       <name>DocumentPreview_card</name>
       <iconField>PREVIEW_IMAGE</iconField>
       <titleField>NAME</titleField>
-      <descriptionField>DATE_EDIT</descriptionField>
+      <descriptionField>DESCRIPTION</descriptionField>
       <favoriteAction1>downloadFilesAction</favoriteAction1>
       <entityField>#ENTITY</entityField>
     </cardViewTemplate>
-- 
GitLab