From 4d0323b709417a09ecd5a5f9a7c57552967ca5a5 Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Wed, 14 Aug 2019 16:40:31 +0200
Subject: [PATCH] Attribute: filter for Objectselection fixed

---
 .../entityfields/responsible/valueProcess.js  |  2 +-
 entity/Attribute_entity/Attribute_entity.aod  |  1 +
 .../dropdownfilter/valueProcess.js            | 14 ++++++++
 entity/Language_entity/Language_entity.aod    |  1 +
 .../appointmentsnextweek/valueProcess.js      | 16 ++++-----
 neonContext/Attribute/Attribute.aod           |  5 +++
 .../AttributeEdit_view/AttributeEdit_view.aod | 10 +++---
 .../AttributeLookup_view.aod                  | 22 ++++++++++++
 .../PersonPreview_view/PersonPreview_view.aod |  4 ---
 process/Attribute_lib/process.js              | 35 ++++++++++++++++---
 10 files changed, 86 insertions(+), 24 deletions(-)
 create mode 100644 entity/Attribute_entity/entityfields/dropdownfilter/valueProcess.js
 create mode 100644 neonView/AttributeLookup_view/AttributeLookup_view.aod

diff --git a/entity/Activity_entity/entityfields/responsible/valueProcess.js b/entity/Activity_entity/entityfields/responsible/valueProcess.js
index a95c59aa0b3..fc2ffa0007b 100644
--- a/entity/Activity_entity/entityfields/responsible/valueProcess.js
+++ b/entity/Activity_entity/entityfields/responsible/valueProcess.js
@@ -3,5 +3,5 @@ import("system.vars");
 import("system.result");
 import("Employee_lib");
 
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value") == null)
     result.string(EmployeeUtils.getCurrentContactId());
\ No newline at end of file
diff --git a/entity/Attribute_entity/Attribute_entity.aod b/entity/Attribute_entity/Attribute_entity.aod
index cc99164ec88..e016d3d0870 100644
--- a/entity/Attribute_entity/Attribute_entity.aod
+++ b/entity/Attribute_entity/Attribute_entity.aod
@@ -355,6 +355,7 @@
       <name>DROPDOWNFILTER</name>
       <title>Filter</title>
       <contentType>FILTER_TREE</contentType>
+      <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/dropdownfilter/valueProcess.js</valueProcess>
     </entityField>
     <entityParameter>
       <name>AttributeTypes_param</name>
diff --git a/entity/Attribute_entity/entityfields/dropdownfilter/valueProcess.js b/entity/Attribute_entity/entityfields/dropdownfilter/valueProcess.js
new file mode 100644
index 00000000000..83bdb17d262
--- /dev/null
+++ b/entity/Attribute_entity/entityfields/dropdownfilter/valueProcess.js
@@ -0,0 +1,14 @@
+import("system.neon");
+import("system.vars");
+import("system.result");
+import("Attribute_lib");
+
+var thisValueNotValid = "{\"entity\":\"\",\"filter\":{\"type\":\"group\",\"operator\":\"AND\",\"childs\":[]}}";
+
+if (vars.get("$field.DROPDOWNDEFINITION") == $AttributeTypes.OBJECTSELECTION 
+    && vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && (vars.get("$this.value") == null || vars.get("$this.value") == thisValueNotValid)) 
+{
+    var entity = vars.getString("$field.DROPDOWNDEFINITION");
+    var condJson = JSON.stringify({entity: entity, filter: {type: "group", operator: "AND", childs: []}});
+    result.string(condJson);
+}
\ No newline at end of file
diff --git a/entity/Language_entity/Language_entity.aod b/entity/Language_entity/Language_entity.aod
index b9b83b6e231..f009d4b2ed3 100644
--- a/entity/Language_entity/Language_entity.aod
+++ b/entity/Language_entity/Language_entity.aod
@@ -2,6 +2,7 @@
 <entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.11" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.11">
   <name>Language_entity</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <title>Language</title>
   <contentTitleProcess>%aditoprj%/entity/Language_entity/contentTitleProcess.js</contentTitleProcess>
   <recordContainer>db</recordContainer>
   <entityFields>
diff --git a/entity/Person_entity/entityfields/appointmentsnextweek/valueProcess.js b/entity/Person_entity/entityfields/appointmentsnextweek/valueProcess.js
index 224a4f60165..ba339914560 100644
--- a/entity/Person_entity/entityfields/appointmentsnextweek/valueProcess.js
+++ b/entity/Person_entity/entityfields/appointmentsnextweek/valueProcess.js
@@ -1,8 +1,8 @@
-import("system.result");
-import("system.entities");
-
-var loadConfig = entities.createConfigForLoadingConsumerRows()
-    .consumer("Appointments");
-var rowCount = entities.getRowCount(loadConfig);
-result.string(rowCount);
-
+//import("system.result");
+//import("system.entities");
+//
+//var loadConfig = entities.createConfigForLoadingConsumerRows()
+//    .consumer("Appointments");
+//var rowCount = entities.getRowCount(loadConfig);
+//result.string(rowCount);
+//
diff --git a/neonContext/Attribute/Attribute.aod b/neonContext/Attribute/Attribute.aod
index b5df2588451..41c89314536 100644
--- a/neonContext/Attribute/Attribute.aod
+++ b/neonContext/Attribute/Attribute.aod
@@ -7,6 +7,7 @@
   <filterview>AttributeFilter_view</filterview>
   <editview>AttributeEdit_view</editview>
   <preview>AttributePreview_view</preview>
+  <lookupview>AttributeLookup_view</lookupview>
   <entity>Attribute_entity</entity>
   <references>
     <neonViewReference>
@@ -25,5 +26,9 @@
       <name>6ab8d733-544c-4e48-ade9-b5210a5e5355</name>
       <view>AttributeTree_view</view>
     </neonViewReference>
+    <neonViewReference>
+      <name>a380915a-6946-4923-9b13-7a981606ce60</name>
+      <view>AttributeLookup_view</view>
+    </neonViewReference>
   </references>
 </neonContext>
diff --git a/neonView/AttributeEdit_view/AttributeEdit_view.aod b/neonView/AttributeEdit_view/AttributeEdit_view.aod
index 9d807129bbb..c037a3098ad 100644
--- a/neonView/AttributeEdit_view/AttributeEdit_view.aod
+++ b/neonView/AttributeEdit_view/AttributeEdit_view.aod
@@ -38,6 +38,10 @@
           <name>c8a5f45e-8092-45f4-ac22-681700447235</name>
           <entityField>ATTRIBUTE_LEVEL</entityField>
         </entityFieldLink>
+        <entityFieldLink>
+          <name>7f7616c5-d633-4ffd-b05e-51f9fed982c2</name>
+          <entityField>DROPDOWNFILTER</entityField>
+        </entityFieldLink>
       </fields>
     </genericViewTemplate>
     <neonViewReference>
@@ -45,11 +49,5 @@
       <entityField>AttributeUsages</entityField>
       <view>AttributeUsageMultiEdit_view</view>
     </neonViewReference>
-    <filterTreeViewTemplate>
-      <name>FilterTree</name>
-      <entityNameField>DROPDOWNDEFINITION</entityNameField>
-      <filterField>DROPDOWNFILTER</filterField>
-      <entityField>#ENTITY</entityField>
-    </filterTreeViewTemplate>
   </children>
 </neonView>
diff --git a/neonView/AttributeLookup_view/AttributeLookup_view.aod b/neonView/AttributeLookup_view/AttributeLookup_view.aod
new file mode 100644
index 00000000000..95ca44e0759
--- /dev/null
+++ b/neonView/AttributeLookup_view/AttributeLookup_view.aod
@@ -0,0 +1,22 @@
+<?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.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.2">
+  <name>AttributeLookup_view</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <boxLayout>
+      <name>layout</name>
+    </boxLayout>
+  </layout>
+  <children>
+    <tableViewTemplate>
+      <name>Table</name>
+      <entityField>#ENTITY</entityField>
+      <columns>
+        <neonTableColumn>
+          <name>9a69a2af-3186-4180-a665-016c30f1fbdc</name>
+          <entityField>FULL_ATTRIBUTE_NAME</entityField>
+        </neonTableColumn>
+      </columns>
+    </tableViewTemplate>
+  </children>
+</neonView>
diff --git a/neonView/PersonPreview_view/PersonPreview_view.aod b/neonView/PersonPreview_view/PersonPreview_view.aod
index 2fd441219ae..776d85c31bf 100644
--- a/neonView/PersonPreview_view/PersonPreview_view.aod
+++ b/neonView/PersonPreview_view/PersonPreview_view.aod
@@ -79,10 +79,6 @@
           <name>929d76b2-4f91-4a02-9b2e-b3f42b49294a</name>
           <entityField>OpenTasks</entityField>
         </entityFieldLink>
-        <entityFieldLink>
-          <name>4ca4ea6e-ef39-4040-a515-757f7049df48</name>
-          <entityField>AppointmentsNextWeek</entityField>
-        </entityFieldLink>
       </fields>
     </scoreCardViewTemplate>
   </children>
diff --git a/process/Attribute_lib/process.js b/process/Attribute_lib/process.js
index 0a3b7af1fcc..a2a93c3da05 100644
--- a/process/Attribute_lib/process.js
+++ b/process/Attribute_lib/process.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("KeywordData_lib");
 import("Context_lib");
 import("system.util");
@@ -141,8 +142,8 @@ AttributeUtil.getPossibleListValues = function (pAttributeId, pAttributeType, pI
             var config = entities.createConfigForLoadingRows()
                 .entity(module)
                 .fields([uid, title]);
-            if (filter)
-                config.filter(filter);
+            if (filter && filter.filter)
+                config.filter(filter.filter);
             var rows = entities.getRows(config);
             for (let i = 0, l = rows.length; i < l; i++)
                 objects.push([rows[i][uid], rows[i][title]])
@@ -774,16 +775,40 @@ $AttributeTypes.OBJECTSELECTION = {
     getDropDownDefinitions : function ()
         {
             var dropDownList = [];
-            //TODO filter entities
             project.getDataModels(project.DATAMODEL_KIND_ENTITY).forEach(
                 function (entity)
                 {
-                    if (entity[1])
+                    if (entity[1] && this._selectableEntities[entity[0]])
                         dropDownList.push([entity[0], translate.text(entity[1])]);
                 }
             );
             return dropDownList;
-        }
+        },
+    /** @private */
+    _selectableEntities : {
+        "ObjectRelationType_entity" : true,
+        "DocumentTemplate_entity" : true,
+        "SupportTicket_entity" : true,
+        "Organisation_entity" : true,
+        "Salesproject_entity" : true,
+        "Productprice_entity" : true,
+        "SerialLetter_entity" : true,
+        "AnyContact_entity" : true,
+        "Salutation_entity" : true,
+        "Attribute_entity" : true,
+        "Activity_entity" : true,
+        "Contract_entity" : true,
+        "Campaign_entity" : true,
+        "BulkMail_entity" : true,
+        "Employee_entity" : true,
+        "Language_entity" : true,
+        "Product_entity" : true,
+        "Person_entity" : true,
+        "Offer_entity" : true,
+        "Order_entity" : true,
+        "Task_entity" : true,
+        "Role_entity" : true
+    }
 };
 $AttributeTypes.THEME = {
     toString : function () {return "THEME";},
-- 
GitLab