From 674d6284e2a7edfc040cb5383de00b3d91f9a397 Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Fri, 7 Jun 2019 09:52:22 +0200
Subject: [PATCH] =?UTF-8?q?Es=20gibt=20nun=20Funktionen=20in=20der=20Campa?=
 =?UTF-8?q?ignLib=20zum=20l=C3=B6schen=20eine=20Kampagne=20/=20einer=20Stu?=
 =?UTF-8?q?fe=20und=20allen=20dazugeh=C3=B6rigen=20Daten.=20Dies=20wurde?=
 =?UTF-8?q?=20in=20der=20Planungsansicht=20integriert=20Es=20wurden=20zwei?=
 =?UTF-8?q?=20Spalten=20f=C3=BCr=20das=20Gantt=20konfiguriert?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../CampaignPlanning_entity.aod               |  1 -
 .../jditorecordcontainer/onDelete.js          |  4 +-
 .../CampaignPlanning_view.aod                 | 10 ++--
 .../CampaignStepsGantt_view.aod               |  8 ++-
 process/Campaign_lib/process.js               | 59 +++++++++++++------
 5 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/entity/CampaignPlanning_entity/CampaignPlanning_entity.aod b/entity/CampaignPlanning_entity/CampaignPlanning_entity.aod
index 52fbf465a3..04fc236246 100644
--- a/entity/CampaignPlanning_entity/CampaignPlanning_entity.aod
+++ b/entity/CampaignPlanning_entity/CampaignPlanning_entity.aod
@@ -60,7 +60,6 @@
     </entityActionGroup>
     <entityField>
       <name>targetContext</name>
-      <valueProcess>%aditoprj%/entity/CampaignPlanning_entity/entityfields/targetcontext/valueProcess.js</valueProcess>
     </entityField>
     <entityField>
       <name>UID</name>
diff --git a/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/onDelete.js b/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/onDelete.js
index 46044ffba2..0bfb4a162b 100644
--- a/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/onDelete.js
+++ b/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/onDelete.js
@@ -1,9 +1,7 @@
 import("system.vars");
-import("system.logging");
 import("Campaign_lib");
 
-logging.log(" in onDelete -> ");
-var selectedRows = vars.get("$sys.selectionRows");
+var selectedElement = vars.get("$sys.selectionRows");
 
 if(selectedElement.length > 0)
 {
diff --git a/neonView/CampaignPlanning_view/CampaignPlanning_view.aod b/neonView/CampaignPlanning_view/CampaignPlanning_view.aod
index 966eb76f9c..8de425ecd7 100644
--- a/neonView/CampaignPlanning_view/CampaignPlanning_view.aod
+++ b/neonView/CampaignPlanning_view/CampaignPlanning_view.aod
@@ -11,7 +11,7 @@
   </layout>
   <children>
     <ganttViewTemplate>
-      <name>CampaignPlanningGantt</name>
+      <name>AllCampaignsOverviewGantt</name>
       <beginDateField>DATE_START</beginDateField>
       <endDateField>DATE_END</endDateField>
       <titleField>NAME</titleField>
@@ -19,12 +19,14 @@
       <uidField>UID</uidField>
       <stepPredecessorIdField>PREDECESSOR_STEP_ID</stepPredecessorIdField>
       <displayRootElementsAsGroupHeaders v="true" />
+      <columns>
+        <element>NAME</element>
+        <element>DATE_END</element>
+      </columns>
       <favoriteActionGroup2>NewGanttEntries</favoriteActionGroup2>
       <entityField>#ENTITY</entityField>
-      <isCreatable v="true" />
-      <isEditable v="false" />
+      <isEditable v="true" />
       <isDeletable v="true" />
-      <title></title>
     </ganttViewTemplate>
   </children>
 </neonView>
diff --git a/neonView/CampaignStepsGantt_view/CampaignStepsGantt_view.aod b/neonView/CampaignStepsGantt_view/CampaignStepsGantt_view.aod
index d544715e4d..12ec95ffbc 100644
--- a/neonView/CampaignStepsGantt_view/CampaignStepsGantt_view.aod
+++ b/neonView/CampaignStepsGantt_view/CampaignStepsGantt_view.aod
@@ -18,9 +18,13 @@
       <uidField>CAMPAIGNSTEPID</uidField>
       <stepPredecessorIdField>PREDECESSORSTEP_ID</stepPredecessorIdField>
       <displayRootElementsAsGroupHeaders v="false" />
+      <columns>
+        <element>NAME</element>
+        <element>DATE_END</element>
+      </columns>
       <entityField>#ENTITY</entityField>
-      <isCreatable v="true" />
-      <isEditable v="true" />
+      <isCreatable v="false" />
+      <isEditable v="false" />
       <isDeletable v="true" />
       <title></title>
     </ganttViewTemplate>
diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js
index 8d8530ede4..36027c8eab 100644
--- a/process/Campaign_lib/process.js
+++ b/process/Campaign_lib/process.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("system.translate");
 import("system.vars");
 import("system.db");
@@ -227,33 +228,55 @@ CampaignUtils.getMaxParticipantsValidationMessage = function()
 }
 
 /**
- * todo
+ * Deletes a single campaign step and all related data including:
+ * Participant logs
+ * Participants
+ * Costs
+ * The step
+ * @param {String} pCampaignStepId ID of the campaign step to delete
  */
 CampaignUtils.deleteCampaignStepData = function(pCampaignStepId)
 {
-    //todo
-    /*
-     * delete:
-     * step
-     * reference to step in other steps
-     * all log entries regarding this step
-     * all participants in this step
-     * all costs in this step
-     */
+    if(pCampaignStepId == null || pCampaignStepId == "")
+        return;
+    
+    let queries = [];
+
+    db.updateData("CAMPAIGNSTEP", ["PREDECESSORSTEP_ID"], null, [""], "PREDECESSORSTEP_ID = '" + pCampaignStepId + "'")
+    
+    queries.push(new Array("CAMPAIGNPARTICIPANTLOG", "CAMPAIGNSTEP_ID = '" + pCampaignStepId + "'"));
+    queries.push(new Array("CAMPAIGNPARTICIPANT", "CAMPAIGNSTEP_ID = '" + pCampaignStepId + "'"));
+    queries.push(new Array("CAMPAIGNCOST", "CAMPAIGNSTEP_ID = '" + pCampaignStepId + "'"));
+    queries.push(new Array("CAMPAIGNSTEP", "CAMPAIGNSTEPID = '" + pCampaignStepId + "'"));
+    db.deletes(queries)
 }
 
 /**
- * todo
+ * Deletes a campaign and all related data including:
+ * All campaign steps including all step related data
+ * All members
+ * All costs
+ * And the campaign itself
+ * @param {String} pCampaignId ID of the Campaign to delete
  */
 CampaignUtils.deleteCampaignData = function(pCampaignId)
 {
-    //todo
-    /*
-     * delete:
-     * steps with function deleteCampaignStepData
-     * all members
-     * campaign itself
-     */
+    if(pCampaignId == null || pCampaignId == "")
+        return;
+    
+    let allStepIdsOfCampaignQuery = "select CAMPAIGNSTEPID from CAMPAIGNSTEP where CAMPAIGN_ID = '" + pCampaignId + "'";
+    let campaignStepIds = db.array(db.COLUMN, allStepIdsOfCampaignQuery);
+    
+    campaignStepIds.forEach(function (campaignStepId) 
+    {
+        CampaignUtils.deleteCampaignStepData(campaignStepId)
+    });
+    
+    let campaignRelated = [];
+    campaignRelated.push(new Array("CAMPAIGNCOST", "CAMPAIGN_ID = '" + pCampaignId + "'"));
+    campaignRelated.push(new Array("CAMPAIGN", "CAMPAIGNID = '" + pCampaignId + "'"));
+    
+    db.deletes(campaignRelated)
 }
 
 /**
-- 
GitLab