From c13c6a64549faf9bd0dc29c1a334bed571df43e6 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Wed, 6 Nov 2019 08:58:47 +0100
Subject: [PATCH] use same Picture-loading mechanisms for anycontact as for
 Person / Organisation

---
 entity/AnyContact_entity/AnyContact_entity.aod   | 12 ++++++++++--
 .../avatartext_param/valueProcess.js             | 16 ++++++++++++++++
 .../entityfields/image/valueProcess.js           | 15 ---------------
 .../person_picture/displayValueProcess.js        | 10 ++++++++++
 .../AnyContactLookup_view.aod                    |  2 +-
 5 files changed, 37 insertions(+), 18 deletions(-)
 create mode 100644 entity/AnyContact_entity/entityfields/avatartext_param/valueProcess.js
 delete mode 100644 entity/AnyContact_entity/entityfields/image/valueProcess.js
 create mode 100644 entity/AnyContact_entity/entityfields/person_picture/displayValueProcess.js

diff --git a/entity/AnyContact_entity/AnyContact_entity.aod b/entity/AnyContact_entity/AnyContact_entity.aod
index 31e74cc643..266eb5fdc4 100644
--- a/entity/AnyContact_entity/AnyContact_entity.aod
+++ b/entity/AnyContact_entity/AnyContact_entity.aod
@@ -111,9 +111,9 @@ See ContactUtils.getRelationTypeByPersOrg for possible values</description>
       <title>Lastname</title>
     </entityField>
     <entityField>
-      <name>IMAGE</name>
+      <name>PERSON_PICTURE</name>
       <contentType>IMAGE</contentType>
-      <valueProcess>%aditoprj%/entity/AnyContact_entity/entityfields/image/valueProcess.js</valueProcess>
+      <displayValueProcess>%aditoprj%/entity/AnyContact_entity/entityfields/person_picture/displayValueProcess.js</displayValueProcess>
     </entityField>
     <entityField>
       <name>STANDARD_EMAIL_COMMUNICATION</name>
@@ -165,6 +165,10 @@ See ContactUtils.getRelationTypeByPersOrg for possible values</description>
       <valueProcess>%aditoprj%/entity/AnyContact_entity/entityfields/withprivatepersons_param/valueProcess.js</valueProcess>
       <expose v="true" />
     </entityParameter>
+    <entityParameter>
+      <name>AvatarText_param</name>
+      <valueProcess>%aditoprj%/entity/AnyContact_entity/entityfields/avatartext_param/valueProcess.js</valueProcess>
+    </entityParameter>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
@@ -260,6 +264,10 @@ See ContactUtils.getRelationTypeByPersOrg for possible values</description>
           <name>PERSON_SALUTATION.value</name>
           <recordfield>PERSON.SALUTATION</recordfield>
         </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>PERSON_PICTURE.value</name>
+          <recordfield>PERSON.PICTURE</recordfield>
+        </dbRecordFieldMapping>
       </recordFieldMappings>
     </dbRecordContainer>
   </recordContainers>
diff --git a/entity/AnyContact_entity/entityfields/avatartext_param/valueProcess.js b/entity/AnyContact_entity/entityfields/avatartext_param/valueProcess.js
new file mode 100644
index 0000000000..b5b5e4fd29
--- /dev/null
+++ b/entity/AnyContact_entity/entityfields/avatartext_param/valueProcess.js
@@ -0,0 +1,16 @@
+import("system.logging");
+import("system.vars");
+import("system.result");
+
+switch (vars.get("$field.contactType")) 
+{
+    case "1":
+        result.string("TEXT:" + vars.getString("$field.ORGANISATION_NAME"));
+        break;
+    case "2":
+    case "3":
+        result.string("TEXT:" + (vars.getString("$field.PERSON_FIRSTNAME") + " " + vars.getString("$field.PERSON_LASTNAME") + " " + vars.getString("$field.ORGANISATION_NAME")).trim());
+        break;
+    default:
+        result.string("");
+}
diff --git a/entity/AnyContact_entity/entityfields/image/valueProcess.js b/entity/AnyContact_entity/entityfields/image/valueProcess.js
deleted file mode 100644
index d30dd86601..0000000000
--- a/entity/AnyContact_entity/entityfields/image/valueProcess.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import("system.result");
-import("system.neon");
-import("system.vars");
-import("Person_lib");
-import("Organisation_lib");
-import("Contact_lib");
-
-if (vars.get("$field.contactType") == 1) // 1 == org, 2 == person, 3 == person
-{
-    result.string(OrgUtils.getImage(vars.get("$field.ORGANISATION_ID"), vars.getString("$field.ORGANISATION_NAME")));
-}
-else
-{
-    result.string(PersUtils.getImage(vars.get("$field.PERSON_ID"), (vars.getString("$field.PERSON_FIRSTNAME") + " " + vars.getString("$field.PERSON_LASTNAME")).trim()));
-}
\ No newline at end of file
diff --git a/entity/AnyContact_entity/entityfields/person_picture/displayValueProcess.js b/entity/AnyContact_entity/entityfields/person_picture/displayValueProcess.js
new file mode 100644
index 0000000000..635d656736
--- /dev/null
+++ b/entity/AnyContact_entity/entityfields/person_picture/displayValueProcess.js
@@ -0,0 +1,10 @@
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_VIEW) {
+    if (vars.get("$field.PERSON_PICTURE"))
+        result.string(vars.get("$field.PERSON_PICTURE"));
+    else
+        result.string(vars.get("$param.AvatarText_param"));
+}
\ No newline at end of file
diff --git a/neonView/AnyContactLookup_view/AnyContactLookup_view.aod b/neonView/AnyContactLookup_view/AnyContactLookup_view.aod
index ddfce75ee7..cb3871fd15 100644
--- a/neonView/AnyContactLookup_view/AnyContactLookup_view.aod
+++ b/neonView/AnyContactLookup_view/AnyContactLookup_view.aod
@@ -14,7 +14,7 @@
       <columns>
         <neonTableColumn>
           <name>5a0d38bb-bfa5-4abc-86e7-fac65804bb5c</name>
-          <entityField>IMAGE</entityField>
+          <entityField>PERSON_PICTURE</entityField>
         </neonTableColumn>
         <neonTableColumn>
           <name>ca59a64a-adce-49c3-93ad-2978c81809f8</name>
-- 
GitLab