From 9e21a6c4231404168d1208a92556dfb804ca1d73 Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Thu, 25 Jul 2019 10:59:36 +0200
Subject: [PATCH] CampaignAddParticipants message improved

---
 .../isoperationvalid/valueProcess.js          | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
index c0689ca0aa..fb3bf4d5ae 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
@@ -96,23 +96,27 @@ if(selectedCampaignId != '')
     {
             messageString = translate.text("All selected participants already are in the campaign");
     }
-    else if(hasStepEnoughSlots(countValidParticipantsToAdd))
-    {
-        messageString = translate.withArguments("%0/%1 participant(s) will be added to the selected campaign step", [countValidParticipantsToAdd, countParticipantsToAdd]);
-        resultValue = "true";
-    }
     else
     {
-        messageString = translate.withArguments("Not enough slots for %0/%1 participant(s)", [countValidParticipantsToAdd, countParticipantsToAdd]);
+        let excess = getParticipantExcess(countValidParticipantsToAdd);
+        if (excess > 0)
+        {
+            messageString = translate.withArguments("Not enough slots for %0/%1 participant(s)", [excess, countParticipantsToAdd]);
+        }
+        else
+        {
+            messageString = translate.withArguments("%0/%1 participant(s) will be added to the selected campaign step", [countValidParticipantsToAdd, countParticipantsToAdd]);
+            resultValue = "true";
+        }
     }
     neon.setFieldValue("$field.campaignParticipantMessage", messageString);
     result.string(resultValue);
 }
 
-function hasStepEnoughSlots(pCountToAdd)
+function getParticipantExcess (pCountToAdd)
 {
     let currentParticipants = CampaignUtils.getParticipantCountForStep(selectedCampaignStepId)
     let maxParticipants = CampaignUtils.getMaxParticipantCountForStep(selectedCampaignStepId)
 
-    return (parseInt(currentParticipants) + parseInt(pCountToAdd)) <= maxParticipants;
+    return (parseInt(currentParticipants) + parseInt(pCountToAdd)) - maxParticipants;
 }
\ No newline at end of file
-- 
GitLab