From 848cc08add2459fbd297e05e09643bcbeeb4aae5 Mon Sep 17 00:00:00 2001
From: "a.schindlbeck" <a.schindlbeck@adito.de>
Date: Wed, 27 Mar 2019 16:20:52 +0100
Subject: [PATCH] Vertriebsproject: REASONS / Liste

---
 .../Salesproject_entity.aod                   |  12 +-
 .../reasons/displayValueProcess.js            |   6 -
 .../reasons/possibleItemsProcess.js           |   6 +
 .../entityfields/reasons/valueProcess.js      |  11 --
 .../reasons.displayvalue/expression.js        |   7 -
 .../SalesprojectPreview_view.aod              | 182 +++++++++---------
 process/Keyword_lib/process.js                |  23 +++
 7 files changed, 125 insertions(+), 122 deletions(-)
 delete mode 100644 entity/Salesproject_entity/entityfields/reasons/displayValueProcess.js
 create mode 100644 entity/Salesproject_entity/entityfields/reasons/possibleItemsProcess.js
 delete mode 100644 entity/Salesproject_entity/entityfields/reasons/valueProcess.js
 delete mode 100644 entity/Salesproject_entity/recordcontainers/db/recordfieldmappings/reasons.displayvalue/expression.js

diff --git a/entity/Salesproject_entity/Salesproject_entity.aod b/entity/Salesproject_entity/Salesproject_entity.aod
index 17fe6bc790..f3c63dd2c8 100644
--- a/entity/Salesproject_entity/Salesproject_entity.aod
+++ b/entity/Salesproject_entity/Salesproject_entity.aod
@@ -453,13 +453,15 @@
     <entityField>
       <name>REASONS</name>
       <title>Reason</title>
-      <consumer>KeywordWonLost</consumer>
       <mandatoryProcess>%aditoprj%/entity/Salesproject_entity/entityfields/reasons/mandatoryProcess.js</mandatoryProcess>
+      <possibleItemsProcess>%aditoprj%/entity/Salesproject_entity/entityfields/reasons/possibleItemsProcess.js</possibleItemsProcess>
       <searchable v="true" />
       <selectionMode>MULTI</selectionMode>
       <stateProcess>%aditoprj%/entity/Salesproject_entity/entityfields/reasons/stateProcess.js</stateProcess>
-      <valueProcess>%aditoprj%/entity/Salesproject_entity/entityfields/reasons/valueProcess.js</valueProcess>
-      <displayValueProcess>%aditoprj%/entity/Salesproject_entity/entityfields/reasons/displayValueProcess.js</displayValueProcess>
+      <onValueChangeTypes>
+        <element>MASK</element>
+        <element>PROCESS</element>
+      </onValueChangeTypes>
     </entityField>
     <entityProvider>
       <name>Salesprojects</name>
@@ -597,10 +599,6 @@
           <name>PHASE.displayValue</name>
           <expression>%aditoprj%/entity/Salesproject_entity/recordcontainers/db/recordfieldmappings/phase.displayvalue/expression.js</expression>
         </dbRecordFieldMapping>
-        <dbRecordFieldMapping>
-          <name>REASONS.displayValue</name>
-          <expression>%aditoprj%/entity/Salesproject_entity/recordcontainers/db/recordfieldmappings/reasons.displayvalue/expression.js</expression>
-        </dbRecordFieldMapping>
         <dbRecordFieldMapping>
           <name>REASONS.value</name>
           <recordfield>SALESPROJECT.REASONS</recordfield>
diff --git a/entity/Salesproject_entity/entityfields/reasons/displayValueProcess.js b/entity/Salesproject_entity/entityfields/reasons/displayValueProcess.js
deleted file mode 100644
index deb08ee453..0000000000
--- a/entity/Salesproject_entity/entityfields/reasons/displayValueProcess.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import("system.vars");
-import("system.result");
-import("Keyword_lib");
-import("KeywordRegistry_basic");
-
-result.string(KeywordUtils.getViewValue($KeywordRegistry.salesprojectWonLost(), vars.get("$field.REASONS")));
\ No newline at end of file
diff --git a/entity/Salesproject_entity/entityfields/reasons/possibleItemsProcess.js b/entity/Salesproject_entity/entityfields/reasons/possibleItemsProcess.js
new file mode 100644
index 0000000000..82ceaf9374
--- /dev/null
+++ b/entity/Salesproject_entity/entityfields/reasons/possibleItemsProcess.js
@@ -0,0 +1,6 @@
+import("system.logging");
+import("system.result");
+import("Keyword_lib");
+import("KeywordRegistry_basic");
+
+result.object(KeywordUtils.getEntryNamesAndIdsByContainer("SalesprojectWonLost"));
\ No newline at end of file
diff --git a/entity/Salesproject_entity/entityfields/reasons/valueProcess.js b/entity/Salesproject_entity/entityfields/reasons/valueProcess.js
deleted file mode 100644
index 44b96c75cb..0000000000
--- a/entity/Salesproject_entity/entityfields/reasons/valueProcess.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import("system.neon");
-import("system.result");
-import("system.vars");
-
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
-{
-    // IDs: SalesprojectState Order and Lost
-    var state = vars.get("$field.STATE");
-    if(state && (state != 'd8a60f60-a4e6-46ee-88ec-bac53e1afedd' && state != '130bb53a-a97e-455e-8f34-8d445e985474'))
-        result.string("");
-}
diff --git a/entity/Salesproject_entity/recordcontainers/db/recordfieldmappings/reasons.displayvalue/expression.js b/entity/Salesproject_entity/recordcontainers/db/recordfieldmappings/reasons.displayvalue/expression.js
deleted file mode 100644
index c62430bd64..0000000000
--- a/entity/Salesproject_entity/recordcontainers/db/recordfieldmappings/reasons.displayvalue/expression.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import("system.result");
-import("Keyword_lib");
-import("KeywordRegistry_basic");
-import("Sql_lib");
-
-var value = KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.salesprojectWonLost(), "SALESPROJECT.REASONS");
-result.string(value);
diff --git a/neonView/SalesprojectPreview_view/SalesprojectPreview_view.aod b/neonView/SalesprojectPreview_view/SalesprojectPreview_view.aod
index 44cadc8a7c..315544ca5c 100644
--- a/neonView/SalesprojectPreview_view/SalesprojectPreview_view.aod
+++ b/neonView/SalesprojectPreview_view/SalesprojectPreview_view.aod
@@ -1,91 +1,91 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.0">
-  <name>SalesprojectPreview_view</name>
-  <majorModelMode>DISTRIBUTED</majorModelMode>
-  <layout>
-    <boxLayout>
-      <name>layout</name>
-    </boxLayout>
-  </layout>
-  <children>
-    <cardViewTemplate>
-      <name>Head</name>
-      <iconField>IMAGE</iconField>
-      <titleField>PROJECTTITLE</titleField>
-      <descriptionField>PROJECTCODE</descriptionField>
-      <favoriteAction1>newActivity</favoriteAction1>
-      <entityField>#ENTITY</entityField>
-    </cardViewTemplate>
-    <genericViewTemplate>
-      <name>Details</name>
-      <showDrawer v="true" />
-      <drawerCaption>Details</drawerCaption>
-      <entityField>#ENTITY</entityField>
-      <fields>
-        <entityFieldLink>
-          <name>f2b33601-12e8-463f-a920-6e1ae9745491</name>
-          <entityField>RELATION_ID</entityField>
-        </entityFieldLink>
-        <entityFieldLink>
-          <name>4e3d7a37-f55b-4c18-9ba1-ab4ab0bbb442</name>
-          <entityField>STATE</entityField>
-        </entityFieldLink>
-        <entityFieldLink>
-          <name>2867e662-b824-4bbf-8eaf-bbd34f44598e</name>
-          <entityField>REASONS</entityField>
-        </entityFieldLink>
-        <entityFieldLink>
-          <name>ff0dcd67-56ec-4db1-8c53-531f22fda716</name>
-          <entityField>PHASE</entityField>
-        </entityFieldLink>
-        <entityFieldLink>
-          <name>3164fe37-8ca0-44c0-bebe-b9573346fb72</name>
-          <entityField>STARTDATE</entityField>
-        </entityFieldLink>
-        <entityFieldLink>
-          <name>529e8b1f-014f-4b44-8bba-96869156ebf7</name>
-          <entityField>ENDDATE</entityField>
-        </entityFieldLink>
-        <entityFieldLink>
-          <name>0ba7dcb5-9606-4d74-8455-3423a16fd98a</name>
-          <entityField>PROBABILITY</entityField>
-        </entityFieldLink>
-        <entityFieldLink>
-          <name>950d21a3-c0f9-4df5-9810-fa027a6fdb4a</name>
-          <entityField>VOLUME</entityField>
-        </entityFieldLink>
-        <entityFieldLink>
-          <name>bf7ecf7a-3d7f-4ec8-867a-c10ced346343</name>
-          <entityField>TIMETRACKINGSUM</entityField>
-        </entityFieldLink>
-      </fields>
-    </genericViewTemplate>
-    <genericViewTemplate>
-      <name>Info</name>
-      <showDrawer v="true" />
-      <drawerCaption>Further informations</drawerCaption>
-      <entityField>#ENTITY</entityField>
-      <fields>
-        <entityFieldLink>
-          <name>9fe11db5-ec66-4238-9c56-5ace055f1d90</name>
-          <entityField>INFO</entityField>
-        </entityFieldLink>
-      </fields>
-    </genericViewTemplate>
-    <neonViewReference>
-      <name>f3542270-e7bd-4f9f-b7c0-f6c5210bb337</name>
-      <entityField>MainDocuments</entityField>
-      <view>DocumentList_view</view>
-    </neonViewReference>
-    <scoreCardViewTemplate>
-      <name>AdditionalInfo</name>
-      <entityField>#ENTITY</entityField>
-      <fields>
-        <entityFieldLink>
-          <name>79490331-6be4-422f-9450-da0db56f0654</name>
-          <entityField>DAYS_NOTACTIVE</entityField>
-        </entityFieldLink>
-      </fields>
-    </scoreCardViewTemplate>
-  </children>
-</neonView>
+<?xml version="1.0" encoding="UTF-8"?>
+<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.0">
+  <name>SalesprojectPreview_view</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <boxLayout>
+      <name>layout</name>
+    </boxLayout>
+  </layout>
+  <children>
+    <cardViewTemplate>
+      <name>Head</name>
+      <iconField>IMAGE</iconField>
+      <titleField>PROJECTTITLE</titleField>
+      <descriptionField>PROJECTCODE</descriptionField>
+      <favoriteAction1>newActivity</favoriteAction1>
+      <entityField>#ENTITY</entityField>
+    </cardViewTemplate>
+    <genericViewTemplate>
+      <name>Details</name>
+      <showDrawer v="true" />
+      <drawerCaption>Details</drawerCaption>
+      <entityField>#ENTITY</entityField>
+      <fields>
+        <entityFieldLink>
+          <name>f2b33601-12e8-463f-a920-6e1ae9745491</name>
+          <entityField>RELATION_ID</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>4e3d7a37-f55b-4c18-9ba1-ab4ab0bbb442</name>
+          <entityField>STATE</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>2867e662-b824-4bbf-8eaf-bbd34f44598e</name>
+          <entityField>REASONS</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>ff0dcd67-56ec-4db1-8c53-531f22fda716</name>
+          <entityField>PHASE</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>3164fe37-8ca0-44c0-bebe-b9573346fb72</name>
+          <entityField>STARTDATE</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>529e8b1f-014f-4b44-8bba-96869156ebf7</name>
+          <entityField>ENDDATE</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>0ba7dcb5-9606-4d74-8455-3423a16fd98a</name>
+          <entityField>PROBABILITY</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>950d21a3-c0f9-4df5-9810-fa027a6fdb4a</name>
+          <entityField>VOLUME</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>bf7ecf7a-3d7f-4ec8-867a-c10ced346343</name>
+          <entityField>TIMETRACKINGSUM</entityField>
+        </entityFieldLink>
+      </fields>
+    </genericViewTemplate>
+    <genericViewTemplate>
+      <name>Info</name>
+      <showDrawer v="true" />
+      <drawerCaption>Further informations</drawerCaption>
+      <entityField>#ENTITY</entityField>
+      <fields>
+        <entityFieldLink>
+          <name>9fe11db5-ec66-4238-9c56-5ace055f1d90</name>
+          <entityField>INFO</entityField>
+        </entityFieldLink>
+      </fields>
+    </genericViewTemplate>
+    <neonViewReference>
+      <name>f3542270-e7bd-4f9f-b7c0-f6c5210bb337</name>
+      <entityField>MainDocuments</entityField>
+      <view>DocumentList_view</view>
+    </neonViewReference>
+    <scoreCardViewTemplate>
+      <name>AdditionalInfo</name>
+      <entityField>#ENTITY</entityField>
+      <fields>
+        <entityFieldLink>
+          <name>79490331-6be4-422f-9450-da0db56f0654</name>
+          <entityField>DAYS_NOTACTIVE</entityField>
+        </entityFieldLink>
+      </fields>
+    </scoreCardViewTemplate>
+  </children>
+</neonView>
diff --git a/process/Keyword_lib/process.js b/process/Keyword_lib/process.js
index 12fee921f9..a4527c2594 100644
--- a/process/Keyword_lib/process.js
+++ b/process/Keyword_lib/process.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("system.vars");
 import("system.SQLTYPES");
 import("system.db");
@@ -166,6 +167,28 @@ KeywordUtils.getEntryNamesByContainer = function(pContainerName)
     return list;
 };
 
+
+/**
+* provides a translated list of keyword-entry-titles and its ids in the system filtered by a containerName;
+* usefull for lists where the key is the name which is then a editable displayValue
+* 
+* @param {String} pContainerName name of the keyword container for filtering
+* 
+* @return {String[]} translated titles as 1D-Array
+*/
+KeywordUtils.getEntryNamesAndIdsByContainer = function(pContainerName)
+{
+    var sql = SqlCondition.begin()
+                          .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pContainerName)
+                          .buildSql("select AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID, AB_KEYWORD_ENTRY.TITLE from AB_KEYWORD_ENTRY", null, "order by AB_KEYWORD_ENTRY.SORTING asc, AB_KEYWORD_ENTRY.TITLE asc")
+                          
+    var list = db.table(sql);
+    for(var i = 0; i<list.length; i = i + 1)
+        list[i][1] = translate.text(list[i][1]);
+    
+    return list;
+};
+
 /**
  * object that provides featrues for a single keyword attribute; initalizes itself on creation with a specific keyword-attribute
  * 
-- 
GitLab