From 16153e86b1925ee86801586ff6f623b746b4be51 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Tue, 8 Jan 2019 16:47:20 +0100
Subject: [PATCH] refactor documentation

---
 .../SalesprojectCycle_context.aod             |  1 +
 .../Salesproject_context.aod                  |  1 +
 .../Salesproject_context/documentation.adoc   | 18 +++++
 process/Activity_lib/process.js               |  2 +-
 process/Address_lib/Address_lib.aod           |  6 --
 process/Address_lib/process.js                | 66 ----------------
 process/Appointment_lib/process.js            |  4 +-
 process/Comm_lib/process.js                   |  2 +-
 process/Date_lib/process.js                   |  4 +-
 process/Entity_lib/process.js                 | 65 +++++++++++++---
 process/Neon_lib/process.js                   |  6 ++
 process/Offer_lib/process.js                  |  2 +-
 process/PostalAddress_lib/process.js          | 78 +++++++++++++++++++
 13 files changed, 165 insertions(+), 90 deletions(-)
 create mode 100644 neonContext/Salesproject_context/documentation.adoc
 delete mode 100644 process/Address_lib/Address_lib.aod
 delete mode 100644 process/Address_lib/process.js

diff --git a/neonContext/SalesprojectCycle_context/SalesprojectCycle_context.aod b/neonContext/SalesprojectCycle_context/SalesprojectCycle_context.aod
index f1613afaa8..177964021d 100644
--- a/neonContext/SalesprojectCycle_context/SalesprojectCycle_context.aod
+++ b/neonContext/SalesprojectCycle_context/SalesprojectCycle_context.aod
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.0.0">
   <name>SalesprojectCycle_context</name>
+  <description>Milestones of a salesproject</description>
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <filterview>SalesprojectCycleFilter_view</filterview>
   <editview>SalesprojectCycleEdit_view</editview>
diff --git a/neonContext/Salesproject_context/Salesproject_context.aod b/neonContext/Salesproject_context/Salesproject_context.aod
index 4619a61297..f21df4abe4 100644
--- a/neonContext/Salesproject_context/Salesproject_context.aod
+++ b/neonContext/Salesproject_context/Salesproject_context.aod
@@ -3,6 +3,7 @@
   <name>Salesproject_context</name>
   <title>Salesproject</title>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <documentation>%aditoprj%/neonContext/Salesproject_context/documentation.adoc</documentation>
   <mainview>SalesprojectMain_view</mainview>
   <filterview>SalesprojectFilter_view</filterview>
   <editview>SalesprojectEdit_view</editview>
diff --git a/neonContext/Salesproject_context/documentation.adoc b/neonContext/Salesproject_context/documentation.adoc
new file mode 100644
index 0000000000..51166614a3
--- /dev/null
+++ b/neonContext/Salesproject_context/documentation.adoc
@@ -0,0 +1,18 @@
+Salesproject
+============
+== Overview ==
+A salesproject consists of some modules:
+- Salesproject itself
+- Activity (former History)
+- Milestones
+- Competition
+- Source
+- Offer
+- Member
+- Classification
+- Forecast
+- Timetracking
+
+== Information ==
+Milestones are currently inserted on each change of Phase and State.
+(with the processes db.onDBUpdate, db.onDBInsert)
\ No newline at end of file
diff --git a/process/Activity_lib/process.js b/process/Activity_lib/process.js
index b95c18ca62..f5e1edbcb1 100644
--- a/process/Activity_lib/process.js
+++ b/process/Activity_lib/process.js
@@ -14,7 +14,7 @@ import("Report_lib");
 import("Context_lib");
 
 /**
- * Methods used by Offer.
+ * Methods used by for activities (former history).
  * Do not create an instance of this!
  * 
  * @class
diff --git a/process/Address_lib/Address_lib.aod b/process/Address_lib/Address_lib.aod
deleted file mode 100644
index a56ebd098c..0000000000
--- a/process/Address_lib/Address_lib.aod
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.7" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.1.7">
-  <name>Address_lib</name>
-  <majorModelMode>DISTRIBUTED</majorModelMode>
-  <process>%aditoprj%/process/Address_lib/process.js</process>
-</process>
diff --git a/process/Address_lib/process.js b/process/Address_lib/process.js
deleted file mode 100644
index 4f1a7512a8..0000000000
--- a/process/Address_lib/process.js
+++ /dev/null
@@ -1,66 +0,0 @@
-import("system.logging");
-import("Relation_lib");
-import("Sql_lib");
-import("system.db");
-
-/**
- * Methods for adresses.
- * Todo: evtl. übernahme / anpassung der Adresslib aus altem Basic. 1030856
- * 
- * Do not create an instance of this!
- * 
- * @class
- */
-function AddressUtils() {}
-   
-/**
- * Returns the formatted standard address for the relation.
- * 
- * TODO: Dummy method! Ãœbernahme der Adresslib aus altem Basic
- * 
- * @return {String}
- */
-AddressUtils.getAddress = function(pRelationId) {
-    var address = db.array(db.ROW, SqlCondition.begin().andPrepare("RELATION.RELATIONID", pRelationId).buildSelect('select RELATIONID, ADDRESS, BUILDINGNO, ZIP, CITY, "NAME", FIRSTNAME, LASTNAME, TITLE from' + RelationUtils.getFullRelationFromString(), "1=0"));
-    
-    // TODO: currently there are some relations without standard address. Use Hardcoded one.
-    if (!address[1]) {
-        var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSelect('select ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0"));
-        address[1] = dummyAddress[0];
-        address[2] = dummyAddress[1];
-        address[3] = dummyAddress[2];
-        address[4] = dummyAddress[3];
-        
-    }
-    var type = RelationUtils.getRelationTypeByRelation(pRelationId);
-    
-    var resultAddr = "";
-    // 1 if organisation <br>
-    // 2 if privat person <br>
-    // 3 if person of an organisation <br>*/
-    switch (type) 
-    {
-        case 1:
-            resultAddr = address[5] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
-            break;
-        case 2:
-            resultAddr = address[8] + " " + address[6] + " " + address[7] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
-            break;
-        case 3:
-            resultAddr = address[5] + "\n" + address[6] + " " + address[7] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
-            break;
-    }
-    
-    return resultAddr;
-}
-
-/**
- * Returns a letter salutation.
- * 
- * TODO: Dummy method! Ãœbernahme der Adresslib aus altem Basic
- * 
- * @return {String}
- */
-AddressUtils.getLetterSalutation = function() {
-    return "Sehr geehrte Damen und Herren";
-}
\ No newline at end of file
diff --git a/process/Appointment_lib/process.js b/process/Appointment_lib/process.js
index 37a89036a2..6a3ccc33da 100644
--- a/process/Appointment_lib/process.js
+++ b/process/Appointment_lib/process.js
@@ -12,7 +12,7 @@ import("system.text");
 function AppointmentUtils() {}
 
 /**
- * Sets the partstat of the current users as given param state
+ * Sets the participant stats of the current users as given param state
  * @param {String} currentUserUri
  * @param {String} attendees encoded as multistring
  * @param {String} newState partstat
@@ -54,7 +54,7 @@ AppointmentUtils.setPartStat = function (currentUserUri, attendees, newState) {
             {
                  if (text.decodeMS(attendeesDecodedArray[x])[0] == currentUserUri)
                  {
-                     newAttendees.push(text.encodeMS( updated))
+                     newAttendees.push(text.encodeMS(updated))
                  }
                  else
                  {
diff --git a/process/Comm_lib/process.js b/process/Comm_lib/process.js
index 08093abd9c..9028be65ba 100644
--- a/process/Comm_lib/process.js
+++ b/process/Comm_lib/process.js
@@ -8,7 +8,7 @@ import("system.cti");
 import("Sql_lib");
 
 /**
- * provides static methods for miscellaneous tasks
+ * provides static methods for Comm
  * do not create an instance of this
  * 
  * @class
diff --git a/process/Date_lib/process.js b/process/Date_lib/process.js
index 8f202fd19a..bbfc15c251 100644
--- a/process/Date_lib/process.js
+++ b/process/Date_lib/process.js
@@ -56,7 +56,7 @@ DateUtils.getDateIncrementedByYears = function(pDate, pYears) {
  * 
  * @result {String} translated name
  */
-DateUtils.getDateIncrementedByYears = function(pDate, pYears) {
+DateUtils.getMonthName = function(pMonth) {
     var monthNames = [
         translate.text("January"),
         translate.text("February"),
@@ -73,5 +73,5 @@ DateUtils.getDateIncrementedByYears = function(pDate, pYears) {
     ];
     
     
-    return 
+    return monthNames[pMonth];
 }
\ No newline at end of file
diff --git a/process/Entity_lib/process.js b/process/Entity_lib/process.js
index 591abc0ab9..f4f63e47f8 100644
--- a/process/Entity_lib/process.js
+++ b/process/Entity_lib/process.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.result");
 import("system.neon");
 import("system.vars");
@@ -25,14 +24,9 @@ function ProcessHandlingUtils() {}
 ProcessHandlingUtils.getOnValidationValue = function(fieldValue) {
     if (fieldValue == undefined) {
         fieldValue = vars.get("$this.value");
-        logging.log("$this.value " + fieldValue)
-    }
-   
-    if (vars.exists("$local.value")) {
-        logging.log("$local.value " + vars.get("$local.value"))
     }
     
-    return (vars.exists("$local.value") &&  vars.get("$local.value") != null) ? vars.get("$local.value") : fieldValue;
+    return (vars.exists("$local.value") && vars.get("$local.value") != null) ? vars.get("$local.value") : fieldValue;
 }
 
 /**
@@ -53,19 +47,57 @@ ProcessHandlingUtils.initialParamToResult = function(pParamVarName)
     
 }
 
-//TODO: comment
+/**
+ * Workaround for detecting field changes of fields not managed by record containers. 
+ * Should be fixed in the future: Ticket 1030023
+ * 
+ * How to use:
+ * 1. put this into the onValueChange of the field
+ * FieldChanges.setChange("$field.MY_FIELD");
+ * 
+ * 2. you may have to change onValueChangeTypes if it is called too often.
+ * 
+ * 3. use this in the record container: onDBUpdate / onDBInsert / onDBDelete
+ * FieldChanges.assimilateChangeAndDispose("$field.MY_FIELD", function(state, value) {
+ *      // check the state like this:
+ *      if (state == FieldChanges.STATE_CHANGED())
+ *          // do something
+ *          PersUtils.setImage(vars.get("$field.PERSID"), value);
+ *      else
+  *         // do something else
+ *          PersUtils.removeImage(vars.get("$field.PERSID"));
+ * });
+ * 
+ * do not create an instance of this
+ * 
+ * @class
+ */
 function FieldChanges(){}
 
+/**
+ * State if nothing changed
+ */
 FieldChanges.STATE_NO_CHANGE = function (){
     return "NO_CHANGE"
-    };
+};
+
+/**
+ * State if field was changed
+ */
 FieldChanges.STATE_CHANGED = function (){
     return "CHANGED"
-    };
+};
+
+/**
+ * State if field was deleted (set to false, null, "" etc.)
+ */
 FieldChanges.STATE_DELETED = function (){
     return "DELETED"
-    };
+};
 
+/**
+ * check if the state was changed. Calls the pAssimilatorFn with the parameters state and value
+ */
 FieldChanges.assimilateChangeAndDispose = function (pFieldName, pAssimilatorFn)
 {
     var allChanges = FieldChanges._getStorage();
@@ -82,6 +114,9 @@ FieldChanges.assimilateChangeAndDispose = function (pFieldName, pAssimilatorFn)
     return res;
 };
 
+/**
+ * Call this if the field changed.
+ */
 FieldChanges.setChange = function(pFieldName)
 {
     var allChanges = FieldChanges._getStorage();
@@ -97,6 +132,10 @@ FieldChanges.setChange = function(pFieldName)
     FieldChanges._setStorage(allChanges);
 };
 
+/**
+ * get the changes from a image variable
+ * @ignore 
+ */
 FieldChanges._getStorage = function()
 {
     if (!vars.exists("$image.FieldChanges"))
@@ -104,6 +143,10 @@ FieldChanges._getStorage = function()
     return vars.get("$image.FieldChanges");
 };
 
+/**
+ * save the field changes in a image variable
+ * @ignore 
+ */
 FieldChanges._setStorage = function(pAllChanges)
 {
     return vars.set("$image.FieldChanges", pAllChanges);
diff --git a/process/Neon_lib/process.js b/process/Neon_lib/process.js
index a07ab5e149..ad01679e41 100644
--- a/process/Neon_lib/process.js
+++ b/process/Neon_lib/process.js
@@ -1,3 +1,9 @@
+import("system.vars");
+import("system.datetime");
+import("system.util");
+import("system.db");
+import("system.project");
+import("system.neon");
 /**
  * Class containing utility functions for copying modules
  * do not create an instance of this
diff --git a/process/Offer_lib/process.js b/process/Offer_lib/process.js
index 0d6dc14def..9876c3b210 100644
--- a/process/Offer_lib/process.js
+++ b/process/Offer_lib/process.js
@@ -12,7 +12,7 @@ import("Keyword_lib");
 import("Product_lib");
 import("Report_lib");
 import("OfferOrder_lib");
-import("Address_lib");
+import("PostalAddress_lib");
 
 /**
  * Methods used by Offer.
diff --git a/process/PostalAddress_lib/process.js b/process/PostalAddress_lib/process.js
index 36923c785f..eb6dc01da0 100644
--- a/process/PostalAddress_lib/process.js
+++ b/process/PostalAddress_lib/process.js
@@ -1,8 +1,27 @@
 import("system.db");
 import("Sql_lib");
 
+/**
+ * Methods for addresses.
+ * Todo: evtl. übernahme / anpassung der Adresslib aus altem Basic. 1030856
+ * 
+ * Do not create an instance of this!
+ * 
+ * @class
+ */
 function AddressUtils(){}
 
+/**
+ * format the Address in one line
+ * 
+ * @param {String} pCountry
+ * @param {String} pAddressLine
+ * @param {String} pBuildingNo
+ * @param {String} pZipCode
+ * @param {String} pCity
+ * 
+ * @return {String}
+ */
 AddressUtils.formatOneline = function (pCountry, pAddressLine, pBuildingNo, pZipCode, pCity)
 {
     var country = pCountry || "";
@@ -18,6 +37,65 @@ AddressUtils.formatOneline = function (pCountry, pAddressLine, pBuildingNo, pZip
     .join(", ");
 };
 
+/**
+ * Returns the formatted standard address for the relation.
+ * 
+ * TODO: Dummy method! Ãœbernahme der Adresslib aus altem Basic
+ * 
+ * @return {String}
+ */
+AddressUtils.getAddress = function(pRelationId) {
+    var address = db.array(db.ROW, SqlCondition.begin().andPrepare("RELATION.RELATIONID", pRelationId).buildSelect('select RELATIONID, ADDRESS, BUILDINGNO, ZIP, CITY, "NAME", FIRSTNAME, LASTNAME, TITLE from' + RelationUtils.getFullRelationFromString(), "1=0"));
+    
+    // TODO: currently there are some relations without standard address. Use Hardcoded one.
+    if (!address[1]) {
+        var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSelect('select ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0"));
+        address[1] = dummyAddress[0];
+        address[2] = dummyAddress[1];
+        address[3] = dummyAddress[2];
+        address[4] = dummyAddress[3];
+        
+    }
+    var type = RelationUtils.getRelationTypeByRelation(pRelationId);
+    
+    var resultAddr = "";
+    // 1 if organisation <br>
+    // 2 if privat person <br>
+    // 3 if person of an organisation <br>*/
+    switch (type) 
+    {
+        case 1:
+            resultAddr = address[5] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
+            break;
+        case 2:
+            resultAddr = address[8] + " " + address[6] + " " + address[7] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
+            break;
+        case 3:
+            resultAddr = address[5] + "\n" + address[6] + " " + address[7] + "\n" + address[1] + " " + address[2] + "\n" + address[3] + " " + address[4];
+            break;
+    }
+    
+    return resultAddr;
+}
+
+/**
+ * Returns a letter salutation.
+ * 
+ * TODO: Dummy method! Ãœbernahme der Adresslib aus altem Basic
+ * 
+ * @return {String}
+ */
+AddressUtils.getLetterSalutation = function() {
+    return "Sehr geehrte Damen und Herren";
+}
+
+/**
+ * Methods for validating addresses.
+ * 
+ * Do not create an instance of this!
+ * 
+ * @class
+ */
 function AddressValidationUtils(){}
 
 AddressValidationUtils._getRequiredFields = function(countryCode)
-- 
GitLab