Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
basic
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab Maintenance 28.03.2025 | 20:00 - 23:00 MEZ
Show more breadcrumbs
xrm
basic
Commits
97f32f06
Commit
97f32f06
authored
6 years ago
by
Johannes Goderbauer
Browse files
Options
Downloads
Patches
Plain Diff
COMM: added functions for setting the standard-comm-entry
parent
696a9f41
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
process/Comm_lib/process.js
+156
-67
156 additions, 67 deletions
process/Comm_lib/process.js
with
156 additions
and
67 deletions
process/Comm_lib/process.js
+
156
−
67
View file @
97f32f06
import
(
"
system.translate
"
);
import
(
"
system.net
"
);
import
(
"
system.mail
"
);
import
(
"
system.cti
"
);
/**
* provides static methods for validation of communication data
* do not create an instance of this
*
* @class
*/
function
CommValidationUtil
()
{
}
/**
* creates a function depending on a given COMM-category (like PHONE, EMAIL, etc.) or null if no validation-function was defined for the given category
* @param {string} commCategory category that determines which function shall be created, e.g. "EMAIL"
* @return {function} function that receives the following arguments:
* <br/> - commAddress
* <br/> - extensions
* <br/>the function has to return null if everything is OK or a value with details if validation failed
*/
CommValidationUtil
.
makeValidationFn
=
function
(
commCategory
){
var
callbackFn
;
switch
(
commCategory
)
{
case
"
EMAIL
"
:
callbackFn
=
function
(
addrValue
){
if
(
!
mail
.
isValidMailAddress
(
addrValue
))
//TODO: enable JDito-methods
return
translate
.
text
(
"
no valid mail-address format
"
);
return
null
;
}
break
;
case
"
LINK
"
:
callbackFn
=
function
(
addrValue
){
if
(
!
net
.
isValidUrl
(
addrValue
,
[
"
http
"
,
"
https
"
]))
//TODO: enable JDito-methods
return
translate
.
text
(
"
no valid format
"
);
return
null
;
}
break
;
case
"
TELEPHONE
"
:
callbackFn
=
function
(
addrValue
,
ext
){
var
country
=
null
;
if
(
addrValue
[
0
]
!=
"
+
"
)
//if the number starts with a country-identifier (e.g. +49) no country needs to be specified
country
=
ext
.
countryCode
;
// if (!cti.isValidPhoneNumber(addrValue, country))//TODO: enable JDito-methods
// return translate.text("no valid phone number");
return
null
;
}
break
;
default
:
callbackFn
=
null
;
break
;
}
return
callbackFn
;
}
/**
* returns a blueprint for validation extensions; these extensions are needed for validating comm data and can be passed to other functions
* @return {object} a object with properties that have a specific default value; normally you want to overwrite that value
*/
CommValidationUtil
.
getExtensionsBlueprint
=
function
(){
return
{
countryCode
:
null
};
}
import
(
"
system.db
"
);
import
(
"
system.vars
"
);
import
(
"
system.datetime
"
);
import
(
"
system.translate
"
);
import
(
"
system.net
"
);
import
(
"
system.mail
"
);
import
(
"
system.cti
"
);
/**
* provides static methods for miscellaneous tasks
* do not create an instance of this
*
* @class
*/
function
CommUtil
(){}
/**
* returns the ids of COMM.MEDIUM that are clustered unter a specific category
* @param {String} pCategory value of the keyword "COMM.MEDIUM" custom.category; e.g. "PHONE"
* @return {String[]} array of the medium-ids
*/
CommUtil
.
getMediumIdsByCategory
=
function
(
pCategory
)
{
var
kwd
=
KeywordUtils
.
createKeyword
(
"
COMM.MEDIUM
"
);
kwd
.
filter
(
function
(
id
,
name
,
customs
){
return
customs
.
category
==
pCategory
;
});
var
mediumIds
=
kwd
.
toArray
(
"
id
"
);
return
mediumIds
;
};
/**
* sets the standard address for COMM entries for a specific category;
* does not verify if the COMMID you provide has the given category
* @param {String} pAffectedRowId a refencial ID whoes COMMs should be modified (a RELATIONID)
* @param {String} pNewStandardCommId COMMID of the new STANDARD comm-entry
* @param {String} pCategory value of the keyword "COMM.MEDIUM" custom.category; e.g. "PHONE"; the STANDARD of this category is set
* @return {null} currently returns always null; reserved for future
*/
CommUtil
.
setStandardForCategory
=
function
(
pAffectedRowId
,
pNewStandardCommId
,
pCategory
)
{
if
(
!
pAffectedRowId
||
!
pNewStandardCommId
||
!
pCategory
)
return
null
;
var
mediumIds
=
CommUtil
.
getMediumIdsByCategory
(
pCategory
);
if
(
mediumIds
.
length
==
0
)
//none found? since mediumIds affects the update later there is no reason to continue
return
null
;
var
statements
=
[];
var
timestamp
=
datetime
.
date
();
var
login
=
vars
.
get
(
"
$sys.user
"
);
var
cols
=
[
"
STANDARD
"
,
"
DATE_EDIT
"
,
"
USER_EDIT
"
];
var
types
=
db
.
getColumnTypes
(
"
COMM
"
,
cols
);
//set current standard comm-record as non-standard
var
cond
=
SqlCondition
.
begin
().
and
(
"
STANDARD = 1
"
).
andPrepare
(
"
COMM.RELATION_ID
"
,
pAffectedRowId
);
//mediumIds cannot be empty so no need to do further checks (this is checked above)
cond
.
and
(
"
MEDIUM_ID in (
"
+
mediumIds
.
join
(
"
,
"
)
+
"
)
"
);
statements
.
push
([
"
COMM
"
,
cols
,
types
,
[
"
0
"
,
timestamp
,
login
],
cond
.
build
()]);
//set the new standard comm-record
cond
.
clear
();
//check commid, relId and medium to prevent data-inconsistency when bad function params are passed by (e.g commid of a different category)
cond
.
andPrepare
(
"
COMM.COMMID
"
,
pNewStandardCommId
).
andPrepare
(
"
COMM.RELATION_ID
"
,
pAffectedRowId
);
cond
.
and
(
"
MEDIUM_ID in (
"
+
mediumIds
.
join
(
"
,
"
)
+
"
)
"
);
statements
.
push
([
"
COMM
"
,
cols
,
types
,
[
"
1
"
,
timestamp
,
login
],
cond
.
build
()]);
count
=
db
.
updates
(
statements
);
return
null
;
};
/**
* sets the standard PHONE-entry for COMM
* does not verify if the COMMID you provide is actually PHONE-COMM
* @param {String} pAffectedRowId a refencial ID whoes COMMs should be modified (a RELATIONID)
* @param {String} pNewStandardCommId COMMID of the new STANDARD comm-entry
* @return {null} currently returns always null; reserved for future
*/
CommUtil
.
setStandardPhone
=
function
(
pAffectedRowId
,
pNewStandardCommId
)
{
return
CommUtil
.
setStandardForCategory
(
pAffectedRowId
,
pNewStandardCommId
,
"
PHONE
"
);
};
/**
* sets the standard EMAIL-entry for COMM
* does not verify if the COMMID you provide is actually EMAIL-COMM
* @param {String} pAffectedRowId a refencial ID whoes COMMs should be modified (a RELATIONID)
* @param {String} pNewStandardCommId COMMID of the new STANDARD comm-entry
* @return {null} currently returns always null; reserved for future
*/
CommUtil
.
setStandardMail
=
function
(
pAffectedRowId
,
pNewStandardCommId
)
{
return
CommUtil
.
setStandardForCategory
(
pAffectedRowId
,
pNewStandardCommId
,
"
EMAIL
"
);
};
/**
* provides static methods for validation of communication data
* do not create an instance of this
*
* @class
*/
function
CommValidationUtil
()
{}
/**
* creates a function depending on a given COMM-category (like PHONE, EMAIL, etc.) or null if no validation-function was defined for the given category
* @param {string} commCategory category that determines which function shall be created, e.g. "EMAIL"
* @return {function} function that receives the following arguments:
* <br/> - commAddress
* <br/> - extensions
* <br/>the function has to return null if everything is OK or a value with details if validation failed
*/
CommValidationUtil
.
makeValidationFn
=
function
(
commCategory
)
{
var
callbackFn
;
switch
(
commCategory
)
{
case
"
EMAIL
"
:
callbackFn
=
function
(
addrValue
){
if
(
!
mail
.
isValidMailAddress
(
addrValue
))
//TODO: enable JDito-methods
return
translate
.
text
(
"
no valid mail-address format
"
);
return
null
;
}
break
;
case
"
LINK
"
:
callbackFn
=
function
(
addrValue
){
if
(
!
net
.
isValidUrl
(
addrValue
,
[
"
http
"
,
"
https
"
]))
//TODO: enable JDito-methods
return
translate
.
text
(
"
no valid format
"
);
return
null
;
}
break
;
case
"
TELEPHONE
"
:
callbackFn
=
function
(
addrValue
,
ext
){
var
country
=
null
;
if
(
addrValue
[
0
]
!=
"
+
"
)
//if the number starts with a country-identifier (e.g. +49) no country needs to be specified
country
=
ext
.
countryCode
;
// if (!cti.isValidPhoneNumber(addrValue, country))//TODO: enable JDito-methods
// return translate.text("no valid phone number");
return
null
;
}
break
;
default
:
callbackFn
=
null
;
break
;
}
return
callbackFn
;
};
/**
* returns a blueprint for validation extensions; these extensions are needed for validating comm data and can be passed to other functions
* @return {object} a object with properties that have a specific default value; normally you want to overwrite that value
*/
CommValidationUtil
.
getExtensionsBlueprint
=
function
()
{
return
{
countryCode
:
null
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment