From 263e2c3e8838547901782b18c216348e13a58768 Mon Sep 17 00:00:00 2001
From: "a.schindlbeck" <a.schindlbeck@adito.de>
Date: Tue, 30 Oct 2018 13:27:16 +0100
Subject: [PATCH] PartStat fixes

---
 .../entityfields/categories/valueProcess.js       |  5 +++--
 .../children/accept/onActionProcess.js            | 15 +++++++++++----
 .../children/decline/onActionProcess.js           | 15 +++++++++++----
 .../children/tentative/onActionProcess.js         | 15 +++++++++++----
 entity/Appointment_entity/onUpdate.js             |  4 ++--
 process/Appointment_lib/process.js                | 11 ++++-------
 6 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/entity/Appointment_entity/entityfields/categories/valueProcess.js b/entity/Appointment_entity/entityfields/categories/valueProcess.js
index 6e54dcd0b4..064e4914d6 100644
--- a/entity/Appointment_entity/entityfields/categories/valueProcess.js
+++ b/entity/Appointment_entity/entityfields/categories/valueProcess.js
@@ -3,5 +3,6 @@ import("system.result");
 import("system.vars");
 import("system.calendars");
 
-var categs = JSON.parse(vars.getString("param.entry"))[calendars.CATEGORIES];
-result.string(categs);
+var categs = JSON.parse(vars.getString("$param.entry"))[calendars.CATEGORIES];
+logging.log("categs -> "+ categs);
+result.string(categs);
\ No newline at end of file
diff --git a/entity/Appointment_entity/entityfields/partstatactiongroup/children/accept/onActionProcess.js b/entity/Appointment_entity/entityfields/partstatactiongroup/children/accept/onActionProcess.js
index 4ee04f054f..fd31c4af45 100644
--- a/entity/Appointment_entity/entityfields/partstatactiongroup/children/accept/onActionProcess.js
+++ b/entity/Appointment_entity/entityfields/partstatactiongroup/children/accept/onActionProcess.js
@@ -10,8 +10,15 @@ var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.us
 var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
 var currentUserUri = currentUserDecodedArray[0];
 
-var currentAttendees = vars.get("$field.ATTENDEES");
-var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, "ACCEPTED");
+var newState = "ACCEPTED";
 
-appointmentUtil.sendExchangedAction(vars.get("$param.entry"));
-neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
+if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
+{   
+    appointmentUtil.sendExchangedAction(vars.get("$param.entry"), newState);
+}
+else
+{
+    var currentAttendees = vars.get("$field.ATTENDEES");
+    var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, newState);
+    neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
+}
diff --git a/entity/Appointment_entity/entityfields/partstatactiongroup/children/decline/onActionProcess.js b/entity/Appointment_entity/entityfields/partstatactiongroup/children/decline/onActionProcess.js
index 4c8288f8a4..831a49bcec 100644
--- a/entity/Appointment_entity/entityfields/partstatactiongroup/children/decline/onActionProcess.js
+++ b/entity/Appointment_entity/entityfields/partstatactiongroup/children/decline/onActionProcess.js
@@ -10,8 +10,15 @@ var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.us
 var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
 var currentUserUri = currentUserDecodedArray[0];
 
-var currentAttendees = vars.get("$field.ATTENDEES");
-var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, "DECLINED");
+var newState = "DECLINED";
 
-appointmentUtil.sendExchangedAction(vars.get("$param.entry"));
-neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
+if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
+{   
+    appointmentUtil.sendExchangedAction(vars.get("$param.entry"), newState);
+}
+else
+{
+    var currentAttendees = vars.get("$field.ATTENDEES");
+    var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, newState);
+    neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
+}
diff --git a/entity/Appointment_entity/entityfields/partstatactiongroup/children/tentative/onActionProcess.js b/entity/Appointment_entity/entityfields/partstatactiongroup/children/tentative/onActionProcess.js
index 9fdc8598e1..24a1e6e1c9 100644
--- a/entity/Appointment_entity/entityfields/partstatactiongroup/children/tentative/onActionProcess.js
+++ b/entity/Appointment_entity/entityfields/partstatactiongroup/children/tentative/onActionProcess.js
@@ -10,8 +10,15 @@ var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.us
 var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
 var currentUserUri = currentUserDecodedArray[0];
 
-var currentAttendees = vars.get("$field.ATTENDEES");
-var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, "TENTATIVE");
+var newState = "TENTATIVE";
 
-appointmentUtil.sendExchangedAction(vars.get("$param.entry"));
-neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
\ No newline at end of file
+if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
+{   
+    appointmentUtil.sendExchangedAction(vars.get("$param.entry"), newState);
+}
+else
+{
+    var currentAttendees = vars.get("$field.ATTENDEES");
+    var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, newState);
+    neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
+}
\ No newline at end of file
diff --git a/entity/Appointment_entity/onUpdate.js b/entity/Appointment_entity/onUpdate.js
index 14e610ccd1..48860685ef 100644
--- a/entity/Appointment_entity/onUpdate.js
+++ b/entity/Appointment_entity/onUpdate.js
@@ -13,9 +13,9 @@ import("system.tools");
 
 // Dieser Prozess speichert die im Frame angezeigten Daten
 // Je nach Modus (INSERT, EDIT) wird ein neuer Datensatz angelegt oder der alte editiert
-if(vars.exists("param.entry"))
+if(vars.exists("$param.entry"))
 {
-    var event = JSON.parse(vars.getString("param.entry"));
+    var event = JSON.parse(vars.getString("$param.entry"));
 
     var ok = false;
     if ( calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS  && event[calendars.ORGANIZER2]["cn"] != event[calendars.USER2]["cn"])
diff --git a/process/Appointment_lib/process.js b/process/Appointment_lib/process.js
index 43f7d1b942..476a993b04 100644
--- a/process/Appointment_lib/process.js
+++ b/process/Appointment_lib/process.js
@@ -62,13 +62,10 @@ function AppointmentUtils()
     }
     
     
-    this.sendExchangedAction = function(event)
+    this.sendExchangedAction = function(event, newState)
     {
-        if( calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS )
-        {   
-            event["X-ADITO-STATUSACTION"] = "ACCEPT";    // "ACCEPT", "DECLINE", ""
-            event[calendars.AFFECTEDUSERS] = "";
-            calendars.updateEntry(event);
-        }
+        event["X-ADITO-STATUSACTION"] = newState;    // "ACCEPT", "DECLINE", ""
+        event[calendars.AFFECTEDUSERS] = "";
+        calendars.updateEntry(event);
     }
 }
\ No newline at end of file
-- 
GitLab