Skip to content
Snippets Groups Projects
Commit e3b92131 authored by Johannes Hörmann's avatar Johannes Hörmann Committed by Sophia Leierseder
Browse files

add task to employee-lib

parent 01217445
No related branches found
No related tags found
No related merge requests found
......@@ -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>
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment