From e6bff1f416a5ecb607992832678b33fe6b6a0084 Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Tue, 26 Mar 2019 17:20:56 +0100
Subject: [PATCH] Task&Activity: use of correct displayValues

---
 entity/Activity_entity/Activity_entity.aod    |  2 +-
 .../creator/displayValueProcess.js            |  8 ++++++
 .../entityfields/creator/valueProcess.js      |  8 ------
 .../editor_contact_id/displayValueProcess.js  |  3 ++-
 .../displayValueProcess.js                    |  3 ++-
 process/Contact_lib/process.js                | 26 ++++++++++++++++++-
 6 files changed, 38 insertions(+), 12 deletions(-)
 create mode 100644 entity/Activity_entity/entityfields/creator/displayValueProcess.js
 delete mode 100644 entity/Activity_entity/entityfields/creator/valueProcess.js

diff --git a/entity/Activity_entity/Activity_entity.aod b/entity/Activity_entity/Activity_entity.aod
index dc0e95ce40..3f998199e7 100644
--- a/entity/Activity_entity/Activity_entity.aod
+++ b/entity/Activity_entity/Activity_entity.aod
@@ -263,7 +263,7 @@
       <consumer>Contacts</consumer>
       <linkedContext>Person</linkedContext>
       <searchable v="false" />
-      <valueProcess>%aditoprj%/entity/Activity_entity/entityfields/creator/valueProcess.js</valueProcess>
+      <displayValueProcess>%aditoprj%/entity/Activity_entity/entityfields/creator/displayValueProcess.js</displayValueProcess>
     </entityField>
     <entityConsumer>
       <name>ModuleTrees</name>
diff --git a/entity/Activity_entity/entityfields/creator/displayValueProcess.js b/entity/Activity_entity/entityfields/creator/displayValueProcess.js
new file mode 100644
index 0000000000..0dde82e772
--- /dev/null
+++ b/entity/Activity_entity/entityfields/creator/displayValueProcess.js
@@ -0,0 +1,8 @@
+import("system.result");
+import("system.vars");
+import("Contact_lib");
+
+var id = vars.get("$this.value");
+//show the simpel title since this will be later an employee-entry and therefore no organisation is needed
+var title = ContactUtils.getTitleByContactId(id);
+result.string(title);
\ No newline at end of file
diff --git a/entity/Activity_entity/entityfields/creator/valueProcess.js b/entity/Activity_entity/entityfields/creator/valueProcess.js
deleted file mode 100644
index fbf6105a85..0000000000
--- a/entity/Activity_entity/entityfields/creator/valueProcess.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import("system.result");
-import("system.vars");
-import("system.neon");
-
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
-{
-    result.string(vars.get("$sys.user"));
-}
\ No newline at end of file
diff --git a/entity/Task_entity/entityfields/editor_contact_id/displayValueProcess.js b/entity/Task_entity/entityfields/editor_contact_id/displayValueProcess.js
index ee76682f8e..0dde82e772 100644
--- a/entity/Task_entity/entityfields/editor_contact_id/displayValueProcess.js
+++ b/entity/Task_entity/entityfields/editor_contact_id/displayValueProcess.js
@@ -3,5 +3,6 @@ import("system.vars");
 import("Contact_lib");
 
 var id = vars.get("$this.value");
-var title = ContactUtils.getFullTitleByContactId(id);
+//show the simpel title since this will be later an employee-entry and therefore no organisation is needed
+var title = ContactUtils.getTitleByContactId(id);
 result.string(title);
\ No newline at end of file
diff --git a/entity/Task_entity/entityfields/requestor_contact_id/displayValueProcess.js b/entity/Task_entity/entityfields/requestor_contact_id/displayValueProcess.js
index ee76682f8e..0dde82e772 100644
--- a/entity/Task_entity/entityfields/requestor_contact_id/displayValueProcess.js
+++ b/entity/Task_entity/entityfields/requestor_contact_id/displayValueProcess.js
@@ -3,5 +3,6 @@ import("system.vars");
 import("Contact_lib");
 
 var id = vars.get("$this.value");
-var title = ContactUtils.getFullTitleByContactId(id);
+//show the simpel title since this will be later an employee-entry and therefore no organisation is needed
+var title = ContactUtils.getTitleByContactId(id);
 result.string(title);
\ No newline at end of file
diff --git a/process/Contact_lib/process.js b/process/Contact_lib/process.js
index 4dc852d62e..f4d5068268 100644
--- a/process/Contact_lib/process.js
+++ b/process/Contact_lib/process.js
@@ -235,6 +235,7 @@ ContactUtils.getFullTitleByContactId = function(pContactId)
 
 /**
  * get the name of the person
+ * do not use this for a mass of data (e.g. in a loop) since this will be slow due to select-time
  * 
  * @param {String} pPersonId the id of the person where the data shall be loaded
  * 
@@ -259,6 +260,28 @@ ContactUtils.getTitleByPersonId = function(pPersonId)
     return "";
 }
 
+/**
+ * get the name of the person
+ * do not use this for a mass of data (e.g. in a loop) since this will be slow due to select-time
+ * 
+ * @param {String} pContactId the id of the contact entry with the person where the data shall be loaded
+ * 
+ * @return {String} the name or ""
+ */
+ContactUtils.getTitleByContactId = function(pContactId)
+{
+    if (pContactId) 
+    {
+        var personId = db.cell(SqlCondition.begin()
+                                           .andPrepare("CONTACT.CONTACTID", pContactId)
+                                            .buildSql("select CONTACT.PERSON_ID from CONTACT ", "1 = 2"));
+        if (personId)
+            return ContactUtils.getTitleByPersonId(personId);
+    }
+    
+    return "";
+}
+
 /**
  * returns the from string for the contact joined with org, person, address 
  *
@@ -368,7 +391,7 @@ Contact.createWithColumnPreset = function()
 function ContactTitleRenderer(pContact, pOptions)
 {
     this.contact = pContact;
-    if (pOptions !== undefined)//null means null which is "no option"; so check exactly for undefined
+    if (pOptions !== undefined)//null means null which is "no option"; so check exactly for undefined to check if default option has to be set
         this._options = pOptions;
     else 
         this._options = ContactTitleRenderer.OPTIONS.IncludeOrganisation;
@@ -401,6 +424,7 @@ function ContactTitleRenderer(pContact, pOptions)
  * @static
  */
 ContactTitleRenderer.OPTIONS = {
+    NoOption: 0,
     IncludeOrganisation: 1
 };
 
-- 
GitLab