From 64ad984956776e62b73eb7719b0d9c2fe7ed82e6 Mon Sep 17 00:00:00 2001
From: Martin Groppe <m.groppe@adito.de>
Date: Tue, 1 Jun 2021 11:54:12 +0000
Subject: [PATCH] campaignparticipant duplicate entries

---
 .../BulkMailRecipient_entity.aod                |  1 +
 .../campaignstep_id/onValidation.js             |  2 +-
 .../CampaignParticipant_entity.aod              |  1 +
 .../entityfields/contact_id/onValidation.js     | 17 +++++++++++++++++
 .../entityfields/contact_id/stateProcess.js     |  2 +-
 language/_____LANGUAGE_de/_____LANGUAGE_de.aod  |  4 ++++
 6 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 entity/CampaignParticipant_entity/entityfields/contact_id/onValidation.js

diff --git a/entity/BulkMailRecipient_entity/BulkMailRecipient_entity.aod b/entity/BulkMailRecipient_entity/BulkMailRecipient_entity.aod
index 3257dcb0779..b78cdfe9353 100644
--- a/entity/BulkMailRecipient_entity/BulkMailRecipient_entity.aod
+++ b/entity/BulkMailRecipient_entity/BulkMailRecipient_entity.aod
@@ -188,6 +188,7 @@
           <name>ExcludeCommunicationRejecting_param</name>
           <valueProcess>%aditoprj%/entity/BulkMailRecipient_entity/entityfields/recipientstobemailed/children/excludecommunicationrejecting_param/valueProcess.js</valueProcess>
           <expose v="false" />
+          <title></title>
         </entityParameter>
       </children>
     </entityProvider>
diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/onValidation.js b/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/onValidation.js
index 29f8f42cc56..9767998d736 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/onValidation.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/onValidation.js
@@ -11,7 +11,7 @@ var maxCount = vars.get("$field.campaignStepMaxParticipantCount");
 var isUpdate = Utils.toBoolean(vars.get("$param.isUpdate_param"));
 
 if (vars.get("$field.CAMPAIGN_ID")){
-    var currentCount = CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEP_ID"),vars.get("$field.CAMPAIGN_ID"));
+    var currentCount = parseInt(CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEP_ID"),vars.get("$field.CAMPAIGN_ID")));
     if ( (validCount+currentCount) > maxCount)
         result.string(translate.text("Not enough room in campaignstep"));
     
diff --git a/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod b/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
index b32ed04cf46..7f9346cc2d5 100644
--- a/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
+++ b/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
@@ -103,6 +103,7 @@
       <state>READONLY</state>
       <stateProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/contact_id/stateProcess.js</stateProcess>
       <displayValueProcess>%aditoprj%/entity/CampaignParticipant_entity/entityfields/contact_id/displayValueProcess.js</displayValueProcess>
+      <onValidation>%aditoprj%/entity/CampaignParticipant_entity/entityfields/contact_id/onValidation.js</onValidation>
     </entityField>
     <entityField>
       <name>DATE_NEW</name>
diff --git a/entity/CampaignParticipant_entity/entityfields/contact_id/onValidation.js b/entity/CampaignParticipant_entity/entityfields/contact_id/onValidation.js
new file mode 100644
index 00000000000..6be2052997f
--- /dev/null
+++ b/entity/CampaignParticipant_entity/entityfields/contact_id/onValidation.js
@@ -0,0 +1,17 @@
+import("system.translate");
+import("system.result");
+import("system.neon");
+import("system.vars");
+import("Sql_lib");
+
+if (vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW && vars.get("$local.value") && vars.get("$field.CAMPAIGN_ID"))
+{
+    var isParticipant= newSelect(["CONTACT_ID"])
+                        .from("CAMPAIGNPARTICIPANT")
+                        .where("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", vars.get("$field.CAMPAIGN_ID"))
+                        .and("CAMPAIGNPARTICIPANT.CONTACT_ID",vars.get("$local.value"))
+                        .cell();
+    if (isParticipant){
+        result.string(translate.text("Chosen record is already in the campaign"));
+    }
+}
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/entityfields/contact_id/stateProcess.js b/entity/CampaignParticipant_entity/entityfields/contact_id/stateProcess.js
index aefbe65aa0e..1d20f9f105c 100644
--- a/entity/CampaignParticipant_entity/entityfields/contact_id/stateProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/contact_id/stateProcess.js
@@ -2,7 +2,7 @@ import("system.result");
 import("system.neon");
 import("system.vars");
 
-if(vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param"))
+if(vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param") || vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT)
     //A contact has been provided. Show it in readonly.
     fieldState = neon.COMPONENTSTATE_READONLY;
 else
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index 21ed6ae8fee..22bff7f58fb 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -435,6 +435,10 @@
       <key>Claim task</key>
       <value>Aufgabe annehmen</value>
     </entry>
+    <entry>
+      <key>Chosen record is already in the campaign</key>
+      <value>Ausgewählter Datensatz befindet sich bereits in der Kampagne</value>
+    </entry>
     <entry>
       <key>Finished tasks</key>
       <value>Abgeschlossene Aufgaben</value>
-- 
GitLab