From 3062a51bd4f9a51d068ea6c87afcce4b5ece85a4 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Mon, 15 Apr 2019 11:29:54 +0200
Subject: [PATCH] add task to employee-lib

---
 .../ActivityLink_entity.aod                   |   2 +
 process/Employee_lib/process.js               | 227 +++++++++---------
 2 files changed, 117 insertions(+), 112 deletions(-)

diff --git a/entity/ActivityLink_entity/ActivityLink_entity.aod b/entity/ActivityLink_entity/ActivityLink_entity.aod
index 312eb10803..00d2c837e4 100644
--- a/entity/ActivityLink_entity/ActivityLink_entity.aod
+++ b/entity/ActivityLink_entity/ActivityLink_entity.aod
@@ -16,6 +16,7 @@
       <name>OBJECT_TYPE</name>
       <title>{$OBJECTLINK_TYPE}</title>
       <consumer>Context</consumer>
+      <mandatory v="true" />
       <displayValueProcess>%aditoprj%/entity/ActivityLink_entity/entityfields/object_type/displayValueProcess.js</displayValueProcess>
     </entityField>
     <entityField>
@@ -23,6 +24,7 @@
       <title>{$OBJECTLINK_OBJECT}</title>
       <consumer>Objects</consumer>
       <linkedContextProcess>%aditoprj%/entity/ActivityLink_entity/entityfields/object_rowid/linkedContextProcess.js</linkedContextProcess>
+      <mandatory v="true" />
       <displayValueProcess>%aditoprj%/entity/ActivityLink_entity/entityfields/object_rowid/displayValueProcess.js</displayValueProcess>
     </entityField>
     <entityField>
diff --git a/process/Employee_lib/process.js b/process/Employee_lib/process.js
index dac86b25c4..17ca0efa8f 100644
--- a/process/Employee_lib/process.js
+++ b/process/Employee_lib/process.js
@@ -1,113 +1,116 @@
-import("system.db");
-import("Sql_lib");
-import("system.tools");
-
-/**
- * Provides functions for employees and users.j
- * 
- * Do not create an instance of this!
- * 
- * @class
- */
-function EmployeeUtils () {}
-
-/**
- * Returns the contact id of the current user
- * 
- * @return the contact id
- */
-EmployeeUtils.getCurrentContactId = function ()
-{
-    var user = tools.getCurrentUser();
-    return user ? user[tools.PARAMS][tools.CONTACTID] : null;
-}
-
-/**
- * Returns the username id of the current user
- * 
- * @return the username
- */
-EmployeeUtils.getCurrentUserName = function ()
-{
-    var user = tools.getCurrentUser();
-    return user ? user[tools.TITLE] : null;
-}
-
-EmployeeUtils.sliceUserId = function (pUserId)
-{
-    return pUserId.substr(10, 36);
-}
-
-/**
- * generates a username from the firstname and lastname with the given structure
- * 
- * @param {String} pFirstName
- * @param {String} pLastName
- * @param {String} pStructure the structure of the username, special characters:
- *      f - one letter of the firstname in lowercase
- *      F - one letter of the firstname in uppsercase
- *      l - one letter of the lastname in lowercase
- *      L - one letter of the lastname in uppsercase
- *      f+ - the complete firstname in lowercase
- *      F+ - the complete firstname
- *      l+ - the complete lastname in lowercae
- *      L+ - the complete lastname 
- * 
- * @return {String} the generated username
- */
-EmployeeUtils.generateUserName = function (pFirstName, pLastName, pStructure)
-{
-    if (!pStructure || (!pFirstName && !pLastName))
-        return null;
-    
-    var firstNameIndex = 0;
-    var lastNameIndex = 0;
-    var userName = pStructure.replace(/(f\+|l\+|f|l)/ig, function (type)
-    {
-        switch (type)
-        {
-            case "f+":
-            return pFirstName.toLowerCase() || "";
-            case "F+":
-                return pFirstName || "";
-            case "l+":
-                return pLastName.toLowerCase()  || "";
-            case "L+":
-                return pLastName || "";
-            case "f":
-                return pFirstName.charAt(firstNameIndex++).toLowerCase() || "";
-            case "F":
-                return pFirstName.charAt(firstNameIndex++).toUpperCase() || "";
-            case "l":
-                return pLastName.charAt(lastNameIndex++).toLowerCase() || "";
-            case "L":
-                return pLastName.charAt(lastNameIndex++).toUpperCase() || "";
-        }
-    });
-    
-    return userName;
-}
-
-/**
- * checks if an employee is used somewhere
- * 
- * @param {String} pContactId the contact id of the user
- * 
- * @return {boolean} if the employee has relations
- */
-EmployeeUtils.hasRelations = function (pContactId)
-{
-    //sql queries with selects on tables where an employee can be used
-    var queries = [
-        SqlCondition.begin()
-            .andPrepare("ACTIVITY.CREATOR", pContactId)
-            .buildSql("select 1 from ACTIVITY"),
-        SqlCondition.begin()
-            .andPrepare("TIMETRACKING.CONTACT_ID", pContactId)
-            .buildSql("select 1 from TIMETRACKING")
-    ];
-    return queries.some(function (sql)
-        {
-            return db.cell(sql) != "";
-        });
+import("system.db");
+import("Sql_lib");
+import("system.tools");
+
+/**
+ * Provides functions for employees and users.j
+ * 
+ * Do not create an instance of this!
+ * 
+ * @class
+ */
+function EmployeeUtils () {}
+
+/**
+ * Returns the contact id of the current user
+ * 
+ * @return the contact id
+ */
+EmployeeUtils.getCurrentContactId = function ()
+{
+    var user = tools.getCurrentUser();
+    return user ? user[tools.PARAMS][tools.CONTACTID] : null;
+}
+
+/**
+ * Returns the username id of the current user
+ * 
+ * @return the username
+ */
+EmployeeUtils.getCurrentUserName = function ()
+{
+    var user = tools.getCurrentUser();
+    return user ? user[tools.TITLE] : null;
+}
+
+EmployeeUtils.sliceUserId = function (pUserId)
+{
+    return pUserId.substr(10, 36);
+}
+
+/**
+ * generates a username from the firstname and lastname with the given structure
+ * 
+ * @param {String} pFirstName
+ * @param {String} pLastName
+ * @param {String} pStructure the structure of the username, special characters:
+ *      f - one letter of the firstname in lowercase
+ *      F - one letter of the firstname in uppsercase
+ *      l - one letter of the lastname in lowercase
+ *      L - one letter of the lastname in uppsercase
+ *      f+ - the complete firstname in lowercase
+ *      F+ - the complete firstname
+ *      l+ - the complete lastname in lowercae
+ *      L+ - the complete lastname 
+ * 
+ * @return {String} the generated username
+ */
+EmployeeUtils.generateUserName = function (pFirstName, pLastName, pStructure)
+{
+    if (!pStructure || (!pFirstName && !pLastName))
+        return null;
+    
+    var firstNameIndex = 0;
+    var lastNameIndex = 0;
+    var userName = pStructure.replace(/(f\+|l\+|f|l)/ig, function (type)
+    {
+        switch (type)
+        {
+            case "f+":
+            return pFirstName.toLowerCase() || "";
+            case "F+":
+                return pFirstName || "";
+            case "l+":
+                return pLastName.toLowerCase()  || "";
+            case "L+":
+                return pLastName || "";
+            case "f":
+                return pFirstName.charAt(firstNameIndex++).toLowerCase() || "";
+            case "F":
+                return pFirstName.charAt(firstNameIndex++).toUpperCase() || "";
+            case "l":
+                return pLastName.charAt(lastNameIndex++).toLowerCase() || "";
+            case "L":
+                return pLastName.charAt(lastNameIndex++).toUpperCase() || "";
+        }
+    });
+    
+    return userName;
+}
+
+/**
+ * checks if an employee is used somewhere
+ * 
+ * @param {String} pContactId the contact id of the user
+ * 
+ * @return {boolean} if the employee has relations
+ */
+EmployeeUtils.hasRelations = function (pContactId)
+{
+    //sql queries with selects on tables where an employee can be used
+    var queries = [
+        SqlCondition.begin()
+            .andPrepare("ACTIVITY.CREATOR", pContactId)
+            .buildSql("select 1 from ACTIVITY"),
+        SqlCondition.begin()
+            .andPrepare("TASK.REQUESTOR_CONTACT_ID", pContactId)
+            .buildSql("select 1 from TASK"),
+        SqlCondition.begin()
+            .andPrepare("TIMETRACKING.CONTACT_ID", pContactId)
+            .buildSql("select 1 from TIMETRACKING")
+    ];
+    return queries.some(function (sql)
+        {
+            return db.cell(sql) != "";
+        });
 }
\ No newline at end of file
-- 
GitLab