Skip to content
Snippets Groups Projects
Commit ed611eb6 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

Address validation fixes

parent ed5edda8
No related branches found
No related tags found
No related merge requests found
import("system.vars");
import("system.result");
import("WsValidation_lib");
result.string(WsValidationUtils.valueFromJSON(vars.get("$this.value")));
\ No newline at end of file
import("system.vars");
import("DataPrivacy_lib");
DataPrivacyUtils.notifyNeedDataPrivacyUpdate(vars.get("$field.CONTACT_ID"), vars.get("$param.ShowDsgvoMessage_param"));
\ No newline at end of file
var rowdata = vars.get("$local.rowdata");
DataPrivacyUtils.notifyNeedDataPrivacyUpdate(rowdata["ADDRESS.CONTACT_ID"], vars.get("$param.ShowDsgvoMessage_param"));
\ No newline at end of file
......@@ -13,7 +13,6 @@
<contentTypeProcess>%aditoprj%/entity/Communication_entity/entityfields/addr/contentTypeProcess.js</contentTypeProcess>
<mandatory v="true" />
<valueProcess>%aditoprj%/entity/Communication_entity/entityfields/addr/valueProcess.js</valueProcess>
<onValueChange>%aditoprj%/entity/Communication_entity/entityfields/addr/onValueChange.js</onValueChange>
<onValueChangeTypes>
<element>MASK</element>
</onValueChangeTypes>
......
import("system.logging");
import("WsValidation_lib");
import("system.neon");
import("KeywordRegistry_basic");
import("Keyword_lib");
import("system.vars");
import("system.cti");
var addr = vars.get("$local.value");
if (addr)
{
var commMedium = vars.get("$field.MEDIUM_ID");
var keywordAttributes = KeywordUtils.getAttributeRelationsByKey(commMedium, $KeywordRegistry.communicationMedium());
var commCategory = keywordAttributes.contentType || "TEXT";
switch (commCategory)
{
case "TELEPHONE": // Phone
if(addr.length > 5)
{
var formatted = cti.formatPhoneNumber(addr, true, vars.get("$param.ContactsMainCountry_param"))
neon.setFieldValue("$field.ADDR", cti.formatPhoneNumber(addr, true, vars.get("$param.ContactsMainCountry_param")))
}
break;
default:
}
}
\ No newline at end of file
import("system.logging");
import("system.cti");
import("system.result");
import("system.vars");
import("system.neon");
......@@ -5,10 +7,14 @@ import("KeywordRegistry_basic");
import("Keyword_lib");
var recordstate = vars.get("$sys.recordstate");
var addr = vars.getString("$this.value");
logging.log("value process" + addr);
if (recordstate == neon.OPERATINGSTATE_NEW || recordstate == neon.OPERATINGSTATE_EDIT)
{
var medium = vars.get("$field.MEDIUM_ID");
if (vars.getString("$this.value") == "" && medium)
if (addr == null && medium)
{
var keywordAttrs = KeywordUtils.getAttributeRelationsByKey(medium, $KeywordRegistry.communicationMedium());
var isInternet = keywordAttrs.contentType == "LINK";
......@@ -16,4 +22,26 @@ if (recordstate == neon.OPERATINGSTATE_NEW || recordstate == neon.OPERATINGSTATE
if (isInternet)
result.string("https://");
}
else if (addr)
{
var commMedium = vars.get("$field.MEDIUM_ID");
var keywordAttributes = KeywordUtils.getAttributeRelationsByKey(commMedium, $KeywordRegistry.communicationMedium());
var commCategory = keywordAttributes.contentType || "TEXT";
switch (commCategory)
{
case "TELEPHONE": // Phone
if(addr.length > 5)
{
logging.log("format " + JSON.stringify(addr, null, "\t"))
var formatted = cti.formatPhoneNumber(addr, true, vars.get("$param.ContactsMainCountry_param"))
result.string(cti.formatPhoneNumber(addr, true, vars.get("$param.ContactsMainCountry_param")))
}
break;
default:
}
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ import("DataPrivacy_lib");
import("system.vars");
import("StandardObject_lib");
var rowdata = vars.get("$local.rowdata");
new StandardObject("Communication", vars.get("$field.COMMUNICATIONID"), "Person", vars.get("$field.CONTACT_ID"))
.onCommunicationUpdate(vars.get("$field.MEDIUM_ID"));
......
......@@ -266,47 +266,79 @@ WsValidationUtils.validate = function(pValue, pType, pCountry, pCity)
}
/**
* set all address-fields by the value of $local.value, which should contain an object of all values as JSON
* @param {String} [pFieldToSetToValue=undefined] the field which should be set to data.value
* parses a json array, but also checks if it is really an array
* @param {String} pJSON the json data
*
* @return {Array|null} the parsed data as array or null if it was no array
*/
WsValidationUtils.setAddressFields = function(pFieldToSetToValue)
{
WsValidationUtils._parseJSONArray = function(pJSON) {
try
{
var data = JSON.parse(vars.getString("$local.value"));
} catch (exception) {
var data = JSON.parse(pJSON);
} catch (ex) {
// if no valid json, it is a direct user input and not a uuid.
// ignore error
return
return null
}
var type = typeof data;
// Only an array can be returned by the ws. V-- this check is slow -> check if not object before as its faster
if (type != "object" || Object.prototype.toString.call(data) !== '[object Array]')
return
_setField("$field.ZIP", data[1]);
_setField("$field.CITY", data[2]);
_setField("$field.COUNTRY", data[4]);
//_setField("$field.DISTRICT", data[5]); not needed currently
_setField("$field.REGION", data[6]);
_setField("$field.STATE", data[7]);
_setField("$field.ADDRESS", data[8]);
return null
if (pFieldToSetToValue)
{
_setField(pFieldToSetToValue, data[12])
return data;
}
/**
* set all address-fields by pValue, which should contain an array of all values as JSON
* Note: it does not set the current field itself as this sould be done by the value process. Use WsValidationUtils.valueFromJSON for this.
*
* @param {String} pJSON the values as json
*/
WsValidationUtils.setAddressFields = function(pJSON)
{
var data = WsValidationUtils._parseJSONArray(pJSON);
if (data == null)
return
var currentField = vars.get("$this.name");
var toSet = {
"$field.ZIP": data[1],
"$field.CITY": data[2],
"$field.COUNTRY": data[4],
//"$field.DISTRICT": data[5], not needed currently
"$field.REGION": data[6],
"$field.STATE": data[7],
"$field.ADDRESS": data[8]
}
function _setField(pField, pValue)
for (field in toSet)
{
if (!pValue)
pValue = ""
if (field != currentField)
{
let value = toSet[field];
if (!value)
value = ""
neon.setFieldValue(pField, pValue);
neon.setFieldValue(field, value);
}
}
}
/**
* gives you only the value of the json.
*
* @param {String} pJSON the values as json
* @return {String} the value or null if local.value did not contain a valid json array
*/
WsValidationUtils.valueFromJSON = function(pJSON)
{
var data = WsValidationUtils._parseJSONArray(pJSON);
if (data == null)
return null
return data[12];
}
/**
* check if the Webservice is enabled in the project preferences
* @param {Object} pType
......
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