From ed611eb6841fd211d3fcb961220c17e47f48fe6a Mon Sep 17 00:00:00 2001 From: Johannes Hoermann <j.hoermann@adito.de> Date: Thu, 25 Jul 2019 11:49:59 +0200 Subject: [PATCH] Address validation fixes --- .../AddressValidation_entity.aod | 3 + .../contentTitleProcess.js | 9 ++- .../recordcontainers/jdito/contentProcess.js | 4 +- entity/Address_entity/Address_entity.aod | 6 +- .../address/displayValueProcess.js | 2 +- .../entityfields/address/mandatoryProcess.js | 4 +- .../entityfields/address/onValueChange.js | 3 +- .../entityfields/address/valueProcess.js | 5 ++ .../addresssearch/displayValueProcess.js | 5 -- .../addresssearch/onValueChange.js | 3 +- .../addresssearch/valueProcess.js | 5 ++ .../entityfields/city/displayValueProcess.js | 2 +- .../entityfields/city/mandatoryProcess.js | 3 +- .../entityfields/city/onValueChange.js | 7 +- .../entityfields/city/valueProcess.js | 5 ++ .../country/displayValueProcess.js | 8 -- .../entityfields/state/mandatoryProcess.js | 3 +- .../entityfields/zip/displayValueProcess.js | 2 +- .../entityfields/zip/mandatoryProcess.js | 3 +- .../entityfields/zip/onValueChange.js | 7 +- .../entityfields/zip/valueProcess.js | 5 ++ .../recordcontainers/db/onDBUpdate.js | 6 +- .../Communication_entity.aod | 1 - .../entityfields/addr/onValueChange.js | 30 ------- .../entityfields/addr/valueProcess.js | 30 ++++++- .../recordcontainers/db/onDBUpdate.js | 2 + process/WsValidation_lib/process.js | 78 +++++++++++++------ 27 files changed, 145 insertions(+), 96 deletions(-) create mode 100644 entity/Address_entity/entityfields/address/valueProcess.js delete mode 100644 entity/Address_entity/entityfields/addresssearch/displayValueProcess.js create mode 100644 entity/Address_entity/entityfields/addresssearch/valueProcess.js create mode 100644 entity/Address_entity/entityfields/city/valueProcess.js delete mode 100644 entity/Address_entity/entityfields/country/displayValueProcess.js create mode 100644 entity/Address_entity/entityfields/zip/valueProcess.js delete mode 100644 entity/Communication_entity/entityfields/addr/onValueChange.js diff --git a/entity/AddressValidation_entity/AddressValidation_entity.aod b/entity/AddressValidation_entity/AddressValidation_entity.aod index dbade15ee8..e6a4c6becc 100644 --- a/entity/AddressValidation_entity/AddressValidation_entity.aod +++ b/entity/AddressValidation_entity/AddressValidation_entity.aod @@ -198,6 +198,9 @@ <jDitoRecordFieldMapping> <name>LAT.value</name> </jDitoRecordFieldMapping> + <jDitoRecordFieldMapping> + <name>VALUE.value</name> + </jDitoRecordFieldMapping> </recordFieldMappings> </jDitoRecordContainer> </recordContainers> diff --git a/entity/AddressValidation_entity/contentTitleProcess.js b/entity/AddressValidation_entity/contentTitleProcess.js index 30fb575601..64f2ed681b 100644 --- a/entity/AddressValidation_entity/contentTitleProcess.js +++ b/entity/AddressValidation_entity/contentTitleProcess.js @@ -1,4 +1,5 @@ -import("system.vars"); -import("system.result"); - -result.string(vars.get("$field.VALUE")); \ No newline at end of file +import("system.vars"); +import("system.result"); + +result.string(vars.get("$field.VALUE")); +//result.string("sdfghj") \ No newline at end of file diff --git a/entity/AddressValidation_entity/recordcontainers/jdito/contentProcess.js b/entity/AddressValidation_entity/recordcontainers/jdito/contentProcess.js index 23d093d4cf..08e0650767 100644 --- a/entity/AddressValidation_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/AddressValidation_entity/recordcontainers/jdito/contentProcess.js @@ -26,4 +26,6 @@ if (!filter && vars.exists("$param.CurrentValue_param") && vars.get("$param.Curr filter = vars.get("$param.CurrentValue_param"); var foundAddresses = WsValidationUtils.validate(filter, type, country, city); -result.object(foundAddresses); \ No newline at end of file +result.object(foundAddresses.map(function(row) { + return row.concat([filter]) +})); \ No newline at end of file diff --git a/entity/Address_entity/Address_entity.aod b/entity/Address_entity/Address_entity.aod index 5af0dc7e06..b1c3d49e57 100644 --- a/entity/Address_entity/Address_entity.aod +++ b/entity/Address_entity/Address_entity.aod @@ -15,6 +15,7 @@ <consumer>StreetValidation</consumer> <mandatoryProcess>%aditoprj%/entity/Address_entity/entityfields/address/mandatoryProcess.js</mandatoryProcess> <textInputAllowed v="true" /> + <valueProcess>%aditoprj%/entity/Address_entity/entityfields/address/valueProcess.js</valueProcess> <displayValueProcess>%aditoprj%/entity/Address_entity/entityfields/address/displayValueProcess.js</displayValueProcess> <onValueChange>%aditoprj%/entity/Address_entity/entityfields/address/onValueChange.js</onValueChange> <onValueChangeTypes> @@ -50,6 +51,7 @@ <consumer>CityValidation</consumer> <mandatoryProcess>%aditoprj%/entity/Address_entity/entityfields/city/mandatoryProcess.js</mandatoryProcess> <textInputAllowed v="true" /> + <valueProcess>%aditoprj%/entity/Address_entity/entityfields/city/valueProcess.js</valueProcess> <displayValueProcess>%aditoprj%/entity/Address_entity/entityfields/city/displayValueProcess.js</displayValueProcess> <onValueChange>%aditoprj%/entity/Address_entity/entityfields/city/onValueChange.js</onValueChange> <onValueChangeTypes> @@ -62,7 +64,6 @@ <consumer>Countries</consumer> <mandatory v="true" /> <valueProcess>%aditoprj%/entity/Address_entity/entityfields/country/valueProcess.js</valueProcess> - <displayValueProcess>%aditoprj%/entity/Address_entity/entityfields/country/displayValueProcess.js</displayValueProcess> </entityField> <entityField> <name>DISTRICT</name> @@ -88,6 +89,7 @@ <consumer>ZipValidation</consumer> <mandatoryProcess>%aditoprj%/entity/Address_entity/entityfields/zip/mandatoryProcess.js</mandatoryProcess> <textInputAllowed v="true" /> + <valueProcess>%aditoprj%/entity/Address_entity/entityfields/zip/valueProcess.js</valueProcess> <displayValueProcess>%aditoprj%/entity/Address_entity/entityfields/zip/displayValueProcess.js</displayValueProcess> <onValueChange>%aditoprj%/entity/Address_entity/entityfields/zip/onValueChange.js</onValueChange> <onValueChangeTypes> @@ -347,7 +349,7 @@ <title>Search</title> <consumer>FullAddressValidation</consumer> <stateProcess>%aditoprj%/entity/Address_entity/entityfields/addresssearch/stateProcess.js</stateProcess> - <displayValueProcess>%aditoprj%/entity/Address_entity/entityfields/addresssearch/displayValueProcess.js</displayValueProcess> + <valueProcess>%aditoprj%/entity/Address_entity/entityfields/addresssearch/valueProcess.js</valueProcess> <onValueChange>%aditoprj%/entity/Address_entity/entityfields/addresssearch/onValueChange.js</onValueChange> <onValueChangeTypes> <element>MASK</element> diff --git a/entity/Address_entity/entityfields/address/displayValueProcess.js b/entity/Address_entity/entityfields/address/displayValueProcess.js index 361195b279..10012b6d85 100644 --- a/entity/Address_entity/entityfields/address/displayValueProcess.js +++ b/entity/Address_entity/entityfields/address/displayValueProcess.js @@ -1,5 +1,5 @@ import("system.vars"); import("system.result"); -// needed for instant display name change if value set by neon.setFieldValue +// Needed for instant refresh if set by neon.setFieldValue result.string(vars.get("$field.ADDRESS")); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/address/mandatoryProcess.js b/entity/Address_entity/entityfields/address/mandatoryProcess.js index 80757d2ad1..7c898f0182 100644 --- a/entity/Address_entity/entityfields/address/mandatoryProcess.js +++ b/entity/Address_entity/entityfields/address/mandatoryProcess.js @@ -1,5 +1,5 @@ import("Entity_lib"); import("system.result"); import("AddressEntity_lib"); -// TODO: fix validation, then remove comment. -// result.object(AddressEntityValidation.isMandatoryField()); \ No newline at end of file + +result.object(AddressEntityValidation.isMandatoryField()); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/address/onValueChange.js b/entity/Address_entity/entityfields/address/onValueChange.js index 5634474c9d..c19e660f10 100644 --- a/entity/Address_entity/entityfields/address/onValueChange.js +++ b/entity/Address_entity/entityfields/address/onValueChange.js @@ -1,3 +1,4 @@ +import("system.vars"); import("WsValidation_lib"); -WsValidationUtils.setAddressFields(); \ No newline at end of file +WsValidationUtils.setAddressFields(vars.get("$local.value")); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/address/valueProcess.js b/entity/Address_entity/entityfields/address/valueProcess.js new file mode 100644 index 0000000000..e5e514c908 --- /dev/null +++ b/entity/Address_entity/entityfields/address/valueProcess.js @@ -0,0 +1,5 @@ +import("system.result"); +import("WsValidation_lib"); +import("system.vars"); + +result.string(WsValidationUtils.valueFromJSON(vars.get("$this.value"))); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/addresssearch/displayValueProcess.js b/entity/Address_entity/entityfields/addresssearch/displayValueProcess.js deleted file mode 100644 index a621c8b6d2..0000000000 --- a/entity/Address_entity/entityfields/addresssearch/displayValueProcess.js +++ /dev/null @@ -1,5 +0,0 @@ -import("system.vars"); -import("system.result"); - -// needed for instant display name change if value set by neon.setFieldValue -result.string(vars.get("$field.AddressSearch")); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/addresssearch/onValueChange.js b/entity/Address_entity/entityfields/addresssearch/onValueChange.js index 57c7beb53f..c19e660f10 100644 --- a/entity/Address_entity/entityfields/addresssearch/onValueChange.js +++ b/entity/Address_entity/entityfields/addresssearch/onValueChange.js @@ -1,3 +1,4 @@ +import("system.vars"); import("WsValidation_lib"); -WsValidationUtils.setAddressFields("$field.AddressSearch"); \ No newline at end of file +WsValidationUtils.setAddressFields(vars.get("$local.value")); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/addresssearch/valueProcess.js b/entity/Address_entity/entityfields/addresssearch/valueProcess.js new file mode 100644 index 0000000000..e5e514c908 --- /dev/null +++ b/entity/Address_entity/entityfields/addresssearch/valueProcess.js @@ -0,0 +1,5 @@ +import("system.result"); +import("WsValidation_lib"); +import("system.vars"); + +result.string(WsValidationUtils.valueFromJSON(vars.get("$this.value"))); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/city/displayValueProcess.js b/entity/Address_entity/entityfields/city/displayValueProcess.js index 3dfaf91d9c..60c162e202 100644 --- a/entity/Address_entity/entityfields/city/displayValueProcess.js +++ b/entity/Address_entity/entityfields/city/displayValueProcess.js @@ -1,5 +1,5 @@ import("system.vars"); import("system.result"); -// needed for instant display name change if value set by neon.setFieldValue +// Needed for instant refresh if set by neon.setFieldValue result.string(vars.get("$field.CITY")); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/city/mandatoryProcess.js b/entity/Address_entity/entityfields/city/mandatoryProcess.js index ced83548f6..7c898f0182 100644 --- a/entity/Address_entity/entityfields/city/mandatoryProcess.js +++ b/entity/Address_entity/entityfields/city/mandatoryProcess.js @@ -2,5 +2,4 @@ import("Entity_lib"); import("system.result"); import("AddressEntity_lib"); -// TODO: fix validation, then remove comment. -// result.object(AddressEntityValidation.isMandatoryField()); \ No newline at end of file +result.object(AddressEntityValidation.isMandatoryField()); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/city/onValueChange.js b/entity/Address_entity/entityfields/city/onValueChange.js index b8245bb197..c19e660f10 100644 --- a/entity/Address_entity/entityfields/city/onValueChange.js +++ b/entity/Address_entity/entityfields/city/onValueChange.js @@ -1,3 +1,4 @@ -import("WsValidation_lib"); - -WsValidationUtils.setAddressFields(); \ No newline at end of file +import("system.vars"); +import("WsValidation_lib"); + +WsValidationUtils.setAddressFields(vars.get("$local.value")); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/city/valueProcess.js b/entity/Address_entity/entityfields/city/valueProcess.js new file mode 100644 index 0000000000..e5e514c908 --- /dev/null +++ b/entity/Address_entity/entityfields/city/valueProcess.js @@ -0,0 +1,5 @@ +import("system.result"); +import("WsValidation_lib"); +import("system.vars"); + +result.string(WsValidationUtils.valueFromJSON(vars.get("$this.value"))); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/country/displayValueProcess.js b/entity/Address_entity/entityfields/country/displayValueProcess.js deleted file mode 100644 index 91e2f20f24..0000000000 --- a/entity/Address_entity/entityfields/country/displayValueProcess.js +++ /dev/null @@ -1,8 +0,0 @@ -import("system.vars"); -import("system.result"); -import("CountryInfo_lib"); - -//TODO: temporary testing code -> will be replaced with title-mechanic -var isoCode = vars.get("$field.COUNTRY"); -var countryName = CountryUtils.getLatinNameByIso2(isoCode); -result.string(countryName); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/state/mandatoryProcess.js b/entity/Address_entity/entityfields/state/mandatoryProcess.js index ced83548f6..7c898f0182 100644 --- a/entity/Address_entity/entityfields/state/mandatoryProcess.js +++ b/entity/Address_entity/entityfields/state/mandatoryProcess.js @@ -2,5 +2,4 @@ import("Entity_lib"); import("system.result"); import("AddressEntity_lib"); -// TODO: fix validation, then remove comment. -// result.object(AddressEntityValidation.isMandatoryField()); \ No newline at end of file +result.object(AddressEntityValidation.isMandatoryField()); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/zip/displayValueProcess.js b/entity/Address_entity/entityfields/zip/displayValueProcess.js index 199cb7a79d..bb62a2e6ba 100644 --- a/entity/Address_entity/entityfields/zip/displayValueProcess.js +++ b/entity/Address_entity/entityfields/zip/displayValueProcess.js @@ -1,5 +1,5 @@ import("system.vars"); import("system.result"); -// needed for instant display name change if value set by neon.setFieldValue +// Needed for instant refresh if set by neon.setFieldValue result.string(vars.get("$field.ZIP")); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/zip/mandatoryProcess.js b/entity/Address_entity/entityfields/zip/mandatoryProcess.js index ced83548f6..7c898f0182 100644 --- a/entity/Address_entity/entityfields/zip/mandatoryProcess.js +++ b/entity/Address_entity/entityfields/zip/mandatoryProcess.js @@ -2,5 +2,4 @@ import("Entity_lib"); import("system.result"); import("AddressEntity_lib"); -// TODO: fix validation, then remove comment. -// result.object(AddressEntityValidation.isMandatoryField()); \ No newline at end of file +result.object(AddressEntityValidation.isMandatoryField()); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/zip/onValueChange.js b/entity/Address_entity/entityfields/zip/onValueChange.js index b8245bb197..c19e660f10 100644 --- a/entity/Address_entity/entityfields/zip/onValueChange.js +++ b/entity/Address_entity/entityfields/zip/onValueChange.js @@ -1,3 +1,4 @@ -import("WsValidation_lib"); - -WsValidationUtils.setAddressFields(); \ No newline at end of file +import("system.vars"); +import("WsValidation_lib"); + +WsValidationUtils.setAddressFields(vars.get("$local.value")); \ No newline at end of file diff --git a/entity/Address_entity/entityfields/zip/valueProcess.js b/entity/Address_entity/entityfields/zip/valueProcess.js new file mode 100644 index 0000000000..86705dc473 --- /dev/null +++ b/entity/Address_entity/entityfields/zip/valueProcess.js @@ -0,0 +1,5 @@ +import("system.vars"); +import("system.result"); +import("WsValidation_lib"); + +result.string(WsValidationUtils.valueFromJSON(vars.get("$this.value"))); \ No newline at end of file diff --git a/entity/Address_entity/recordcontainers/db/onDBUpdate.js b/entity/Address_entity/recordcontainers/db/onDBUpdate.js index c20ad6c82f..70056d7ef3 100644 --- a/entity/Address_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Address_entity/recordcontainers/db/onDBUpdate.js @@ -1,4 +1,6 @@ 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 diff --git a/entity/Communication_entity/Communication_entity.aod b/entity/Communication_entity/Communication_entity.aod index 782a4ac540..7d3fb4a4ba 100644 --- a/entity/Communication_entity/Communication_entity.aod +++ b/entity/Communication_entity/Communication_entity.aod @@ -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> diff --git a/entity/Communication_entity/entityfields/addr/onValueChange.js b/entity/Communication_entity/entityfields/addr/onValueChange.js deleted file mode 100644 index 33c6de3393..0000000000 --- a/entity/Communication_entity/entityfields/addr/onValueChange.js +++ /dev/null @@ -1,30 +0,0 @@ -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 diff --git a/entity/Communication_entity/entityfields/addr/valueProcess.js b/entity/Communication_entity/entityfields/addr/valueProcess.js index 4485a97535..62136f533a 100644 --- a/entity/Communication_entity/entityfields/addr/valueProcess.js +++ b/entity/Communication_entity/entityfields/addr/valueProcess.js @@ -1,3 +1,5 @@ +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 diff --git a/entity/Communication_entity/recordcontainers/db/onDBUpdate.js b/entity/Communication_entity/recordcontainers/db/onDBUpdate.js index c6e55a7c46..7c2c746ae9 100644 --- a/entity/Communication_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/Communication_entity/recordcontainers/db/onDBUpdate.js @@ -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")); diff --git a/process/WsValidation_lib/process.js b/process/WsValidation_lib/process.js index c5ad40dd0c..69379c6adf 100644 --- a/process/WsValidation_lib/process.js +++ b/process/WsValidation_lib/process.js @@ -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 -- GitLab