From 19eb89cb12e871bed0ecab25ad25486e7589b8dc Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Wed, 19 Jun 2019 11:43:33 +0200
Subject: [PATCH] Beginn implementierung Serienaktion mit condition

---
 .../CampaignAddParticipants_entity.aod        |  10 +-
 .../valueProcess.js                           |  10 +-
 .../recordcontainers/jdito/onInsert.js        | 114 +++++++++++-------
 .../onActionProcess.js                        |   5 +-
 .../addtocampaignfromtable/onActionProcess.js |  11 +-
 .../addtocampaignfromtable/onActionProcess.js |  17 ++-
 .../_____LANGUAGE_EXTRA.aod                   |   3 +
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     |   1 +
 .../_____LANGUAGE_en/_____LANGUAGE_en.aod     |   3 +
 neonContext/CampaignStep/CampaignStep.aod     |   1 -
 process/Campaign_lib/process.js               |  25 ++--
 11 files changed, 137 insertions(+), 63 deletions(-)

diff --git a/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod b/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod
index 5d48a5105c..71c8af2723 100644
--- a/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod
+++ b/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod
@@ -38,7 +38,7 @@
       <valueProcess>%aditoprj%/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js</valueProcess>
     </entityField>
     <entityParameter>
-      <name>campaignParticipants_param</name>
+      <name>campaignParticipantsRowIds_param</name>
       <expose v="true" />
       <description>PARAMETER</description>
     </entityParameter>
@@ -115,6 +115,14 @@
       <name>isUpdate</name>
       <valueProcess>%aditoprj%/entity/CampaignAddParticipants_entity/entityfields/isupdate/valueProcess.js</valueProcess>
     </entityField>
+    <entityParameter>
+      <name>campaignParticipantsCondition_param</name>
+      <expose v="true" />
+    </entityParameter>
+    <entityParameter>
+      <name>dataSourceTableName_param</name>
+      <expose v="true" />
+    </entityParameter>
   </entityFields>
   <recordContainers>
     <jDitoRecordContainer>
diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js
index 93144d421b..e26b93f07e 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantmessage/valueProcess.js
@@ -1,8 +1,12 @@
+import("system.logging");
 import("system.result");
 import("system.translate");
 import("system.vars");
 
-var campaignParticipantsAmount = JSON.parse(vars.getString("$param.campaignParticipants_param")).length;
-var informationText = translate.text("participants will be added to the selected campaign step");
+//logging.log(" -> " + JSON.stringify(vars.getString("$param.campaignParticipantsRowIds_param")));
+//var test = vars.getString("$param.campaignParticipantsRowIds_param");
+//var campaignParticipantsAmount = JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param")).length;
+//var informationText = translate.text("participants will be added to the selected campaign step");
 
-result.string(campaignParticipantsAmount + " " + informationText);
\ No newline at end of file
+//result.string(campaignParticipantsAmount + " " + informationText);
+result.string("Message");
\ No newline at end of file
diff --git a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
index 323f5b11c4..77fdca8e84 100644
--- a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
@@ -1,74 +1,96 @@
+import("system.logging");
 import("system.vars");
 import("system.db");
 import("system.util");
 import("Campaign_lib");
 
+var cols = [];
+
+var participantRowIds = JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param"));
+var participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param"));
+var conditionSourceTableName = vars.getString("$param.dataSourceTableName_param");
+
 var campaignId = vars.getString("$field.CAMPAIGN_ID");
 var newCampaignStepId = vars.getString("$field.CAMPAIGNSTEP_ID");
-var participants   = JSON.parse(vars.getString("$param.campaignParticipants_param"));
-
 var isUpdate = vars.get("$field.isUpdate");
-var colNamesCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumnNames();
 
-var cols = [];
+var colNamesCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumnNames();
 
-if(isUpdate == "true")
+if(participantRowIds.length > 0)
 {
-    cols = [ "CAMPAIGNSTEP_ID",
-              "USER_EDIT",
-              "DATE_EDIT"
-            ];
+    _handleRowIds(participantRowIds);
 }
 else
 {
-    cols = [ "CAMPAIGNPARTICIPANTID"
-    ,"CONTACT_ID"
-    ,"CAMPAIGN_ID"
-    ,"CAMPAIGNSTEP_ID"
-    ,"USER_NEW"
-    ,"DATE_NEW"
-    ];
+    _handleCondition(participantCondition, conditionSourceTableName)
+}
+
+function _handleCondition(pCondition, pSourceTableName)
+{
+    //( UPPER( PERSON.SALUTATION ) = UPPER( 'Frau' ) 
 }
 
-var statementArray = [];
-var logArray = [];
-for (participant in participants)
+function _handleRowIds(pParticipantRowIds)
 {
-    var campaignParticipantLogId = util.getNewUUID();
     if(isUpdate == "true")
     {
-        let updatedValues = [newCampaignStepId,
-                        vars.get("$sys.user"),
-                        vars.get("$sys.date")];
-        
-        let condition = "CAMPAIGNPARTICIPANTID = '" + participants[participant] + "'";
-        let valsCampaignParticipantLog = new Array(participants[participant], campaignId, newCampaignStepId, campaignParticipantLogId, vars.get("$sys.user"), vars.get("$sys.date"));
-        
-        statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, updatedValues, condition]);
-        logArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, null, valsCampaignParticipantLog]);
+        cols = [ "CAMPAIGNSTEP_ID",
+                  "USER_EDIT",
+                  "DATE_EDIT"
+                ];
     }
     else
     {
-        let campaignParticipantId = util.getNewUUID();
-    
-        var valsCampaignParticipant = [ campaignParticipantId
-        , participants[participant]
-        , campaignId
-        , newCampaignStepId
-        , vars.get("$sys.user")
-        , vars.get("$sys.date")
+        cols = [ "CAMPAIGNPARTICIPANTID"
+        ,"CONTACT_ID"
+        ,"CAMPAIGN_ID"
+        ,"CAMPAIGNSTEP_ID"
+        ,"USER_NEW"
+        ,"DATE_NEW"
         ];
+    }
 
-        let valsCampaignParticipantLog = new Array(campaignParticipantId, campaignId, newCampaignStepId, campaignParticipantLogId, vars.get("$sys.user"), vars.get("$sys.date"));
+    let statementArray = [];
+    let logArray = [];
+    for (participant in pParticipantRowIds)
+    {
+        let campaignParticipantLogId = util.getNewUUID();
+        if(isUpdate == "true")
+        {
+            let updatedValues = [newCampaignStepId,
+                            vars.get("$sys.user"),
+                            vars.get("$sys.date")];
+
+            let condition = "CAMPAIGNPARTICIPANTID = '" + pParticipantRowIds[participant] + "'";
+            let valsCampaignParticipantLog = new Array(pParticipantRowIds[participant], campaignId, newCampaignStepId, campaignParticipantLogId, vars.get("$sys.user"), vars.get("$sys.date"));
+
+            statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, updatedValues, condition]);
+            logArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, null, valsCampaignParticipantLog]);
+        }
+        else
+        {
+            let campaignParticipantId = util.getNewUUID();
+
+            let valsCampaignParticipant = [ campaignParticipantId
+            , pParticipantRowIds[participant]
+            , campaignId
+            , newCampaignStepId
+            , vars.get("$sys.user")
+            , vars.get("$sys.date")
+            ];
+
+            let valsCampaignParticipantLog = new Array(campaignParticipantId, campaignId, newCampaignStepId, campaignParticipantLogId, vars.get("$sys.user"), vars.get("$sys.date"));
 
-        statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, valsCampaignParticipant]);
-        logArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, null, valsCampaignParticipantLog]);
+            statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, valsCampaignParticipant]);
+        }
     }
+    
+    if(isUpdate == "true")
+        db.updates(statementArray)
+    else
+        db.inserts(statementArray);
+    
+    if(logArray.length > 0)
+        db.inserts(logArray);
 }
 
-if(isUpdate == "true")
-    db.updates(statementArray)
-else
-    db.inserts(statementArray);
-
-db.inserts(logArray);
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js b/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
index 990e188be5..1b2aa9e9bb 100644
--- a/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
@@ -2,7 +2,10 @@ import("system.vars");
 import("system.neon");
 import("Campaign_lib");
 
-if(vars.exists("$sys.selection")) //selektierte IDs als Array
+
+var sysSelection = vars.getString("$sys.selection");
+
+if(sysSelection.length > 0) //selektierte IDs als Array
 {
     CampaignUtils.openSetCampaignStepView(vars.getString("$sys.selection"), vars.get("$field.CAMPAIGN_ID"), vars.get("$field.CAMPAIGNSTEP_ID"));
 }
\ No newline at end of file
diff --git a/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js b/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
index 0fbec19d1d..8ae8d45bb0 100644
--- a/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
+++ b/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
@@ -2,7 +2,14 @@ import("system.vars");
 import("system.neon");
 import("Campaign_lib");
 
-if(vars.exists("$sys.selection")) //selektierte IDs als Array
+var sysSelection = vars.getString("sys.selection");
+
+if(sysSelection.length > 0) //selektierte IDs als Array
+{
+    CampaignUtils.addParticipantsByRowIds(sysSelection, "ORGANISATION");
+}
+else
 {
-    CampaignUtils.addParticipants(vars.getString("$sys.selection"));
+    let sysFilter = vars.get("$sys.filter");//todo change name
+    CampaignUtils.addParticipantsByCondition(sysFilter.condition, "ORGANISATION");
 }
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js b/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
index 93d8123c03..7be2f554b7 100644
--- a/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
+++ b/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
@@ -2,7 +2,20 @@ import("system.vars");
 import("system.neon");
 import("Campaign_lib");
 
-if(vars.exists("$sys.selection")) //selektierte IDs als Array
+/*
+ * If there's a selection only those are ought to be added.
+ * Otherwise the filter gets checked, if a filter has beed set, the condition
+ * is used to determine the objects to be added.
+ * If no selection has been set, all objects will be added.
+ */
+var sysSelection = vars.getString("$sys.selection");
+
+if(sysSelection.length > 0) //selektierte IDs als Array
+{
+    CampaignUtils.addParticipantsByRowIds(sysSelection, "PERSON");
+}
+else
 {
-    CampaignUtils.addParticipants(vars.getString("$sys.selection"));
+    let sysFilter = vars.get("$sys.filter");//todo change name
+    CampaignUtils.addParticipantsByCondition(sysFilter.condition, "PERSON");
 }
\ No newline at end of file
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index 2cff05e9f2..d1af6a77d2 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -3702,6 +3702,9 @@
     <entry>
       <key>Do you really want to delete this recurring appointment?</key>
     </entry>
+    <entry>
+      <key>Start date</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
   <sqlModels>
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index ce566a5eaf..78f95e3469 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -4523,6 +4523,7 @@
     </entry>
     <entry>
       <key>New step</key>
+      <value>Neue Stufe</value>
     </entry>
     <entry>
       <key>Runtime</key>
diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
index b3908e18a5..ab510d02a2 100644
--- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
+++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
@@ -3751,6 +3751,9 @@
     <entry>
       <key>Do you really want to delete this recurring appointment?</key>
     </entry>
+    <entry>
+      <key>Start date</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
 </language>
diff --git a/neonContext/CampaignStep/CampaignStep.aod b/neonContext/CampaignStep/CampaignStep.aod
index 5ffbe5f7e7..6a03138ca8 100644
--- a/neonContext/CampaignStep/CampaignStep.aod
+++ b/neonContext/CampaignStep/CampaignStep.aod
@@ -3,7 +3,6 @@
   <name>CampaignStep</name>
   <title>Campaign Step</title>
   <majorModelMode>DISTRIBUTED</majorModelMode>
-  <mainview>CampaignStepMain_view</mainview>
   <filterview>CampaignStepFilter_view</filterview>
   <editview>CampaignStepEdit_view</editview>
   <preview>CampaignStepPreview_view</preview>
diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js
index bf72837d51..c1a90cd8d8 100644
--- a/process/Campaign_lib/process.js
+++ b/process/Campaign_lib/process.js
@@ -30,11 +30,22 @@ CampaignUtils.addParticipant = function(pContactId)
  * 
  * @param {String} pRowIds req ContactIds
  */
-CampaignUtils.addParticipants = function(pRowIds)
+CampaignUtils.addParticipantsByRowIds = function(pRowIds, pSourceTableName)
 {
-    _CampaignUtils._openAddParticipantContext("CampaignAddParticipants", pRowIds, "campaignParticipants_param", "CampaignAddParticipantsEdit_view");
+    _CampaignUtils._openAddParticipantContext("CampaignAddParticipants", pRowIds, 
+    "campaignParticipantsRowIds_param", "CampaignAddParticipantsEdit_view", pSourceTableName);
 }
 
+/**
+ * Add many Contacts (Person or Organistaion) to a Campaign
+ * 
+ * @param {String} pRowIds req ContactIds
+ */
+CampaignUtils.addParticipantsByCondition = function(pCondition, pSourceTableName)
+{
+    _CampaignUtils._openAddParticipantContext("CampaignAddParticipants", pCondition, 
+    "campaignParticipantsCondition_param", "CampaignAddParticipantsEdit_view", pSourceTableName);
+}
 
 /**
  * todo
@@ -149,8 +160,7 @@ CampaignUtils.getParticipantLogInsertColumnNames = function()
 CampaignUtils.openSetCampaignStepView = function(pParticipantIds, pCampaignId, pCampaignStepId)
 {
     var params = {};
-    
-    params["campaignParticipants_param"] = pParticipantIds;
+    params["campaignParticipantsRowIds_param"] = pParticipantIds;
     params["currentCampaignId_param"] = pCampaignId;
     params["currentCampaignStepId_param"] = pCampaignStepId;
     params["isUpdate_param"] = true;
@@ -311,15 +321,16 @@ function _CampaignUtils() {}
  * @param {String} pView req targeting view
  * 
  */
-_CampaignUtils._openAddParticipantContext = function(pContext, pRowIds, pEntityParam, pView)
+_CampaignUtils._openAddParticipantContext = function(pContext, pTargetDataExpression, pDataExpressionParameterName, pView, pSourceTableName)
 {
     var params = {};
     
-    if (pRowIds)
+    if (pTargetDataExpression)
     {
-        params[pEntityParam] = pRowIds;
+        params[pDataExpressionParameterName] = pTargetDataExpression;
     }
     params["isUpdate_param"] = false;
+    params["dataSourceTableName_param"] = pSourceTableName;
     
     neon.openContext(pContext, null, null, neon.OPERATINGSTATE_NEW, params);
 }
-- 
GitLab