From b532f0ca094777953b1c9ac126f97a2fe67ea4ac Mon Sep 17 00:00:00 2001 From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local> Date: Tue, 14 Jul 2020 10:54:56 +0200 Subject: [PATCH] Placeholders: splitting the placeholder name and the delimiters --- .../entityfields/field/dropDownProcess.js | 2 +- .../recordcontainers/jdito/onUpdate.js | 7 +++- .../WorkflowDefinitionPreview_view.aod | 4 ++ process/Address_lib/process.js | 10 ++--- .../DocumentTemplate_lib/documentation.adoc | 2 +- process/DocumentTemplate_lib/process.js | 16 +++++--- process/ExportTemplate_lib/process.js | 2 +- process/Placeholder_lib/process.js | 37 ++++++++++++++++--- 8 files changed, 60 insertions(+), 20 deletions(-) diff --git a/entity/ExportTemplateField_entity/entityfields/field/dropDownProcess.js b/entity/ExportTemplateField_entity/entityfields/field/dropDownProcess.js index f5b8c99880..3c830477d5 100644 --- a/entity/ExportTemplateField_entity/entityfields/field/dropDownProcess.js +++ b/entity/ExportTemplateField_entity/entityfields/field/dropDownProcess.js @@ -9,7 +9,7 @@ import("system.text") var placeholders = PlaceholderUtils.getPlaceholders(null, true).map(function (placeholder){ - return [placeholder.placeholderName, placeholder.title || placeholder.placeholderName]; + return [placeholder.getFormattedName(), placeholder.title || placeholder.getFormattedName()]; }) result.object(placeholders); \ No newline at end of file diff --git a/entity/WorkflowDefinition_entity/recordcontainers/jdito/onUpdate.js b/entity/WorkflowDefinition_entity/recordcontainers/jdito/onUpdate.js index 2afd61402e..3dcde8317a 100644 --- a/entity/WorkflowDefinition_entity/recordcontainers/jdito/onUpdate.js +++ b/entity/WorkflowDefinition_entity/recordcontainers/jdito/onUpdate.js @@ -4,11 +4,14 @@ import("system.workflow"); import("Document_lib"); var rowdata = vars.get("$local.rowdata"); +var changedFields = vars.get("$local.changed"); -if (vars.get("$local.changed").indexOf("ISACTIVE.value") !== -1) +if (changedFields.includes("ISACTIVE.value")) workflow.setProcessActive(rowdata["UID.value"], rowdata["ISACTIVE.value"] == "true"); - +if (changedFields.includes("CATEGORY.value")) + workflow.setProcessDefinitionCategory(rowdata["UID.value"], rowdata["CATEGORY.value"]); + var upload = new FileUpload(vars.get("$field.FILEUPLOAD")); if (upload.isFilled()) { diff --git a/neonView/WorkflowDefinitionPreview_view/WorkflowDefinitionPreview_view.aod b/neonView/WorkflowDefinitionPreview_view/WorkflowDefinitionPreview_view.aod index de087d4217..4b0e3f5af6 100644 --- a/neonView/WorkflowDefinitionPreview_view/WorkflowDefinitionPreview_view.aod +++ b/neonView/WorkflowDefinitionPreview_view/WorkflowDefinitionPreview_view.aod @@ -35,6 +35,10 @@ <name>9ae7bada-afb2-48d4-9aa0-b2bd5bd17379</name> <entityField>ISACTIVE</entityField> </entityFieldLink> + <entityFieldLink> + <name>f5a0addd-becc-4c4f-b381-65612127acaf</name> + <entityField>CATEGORY</entityField> + </entityFieldLink> <entityFieldLink> <name>6b06cf99-37b1-4901-a502-81bb590faa92</name> <entityField>DESCRIPTION</entityField> diff --git a/process/Address_lib/process.js b/process/Address_lib/process.js index d68036c8e5..ecd34ddbbc 100644 --- a/process/Address_lib/process.js +++ b/process/Address_lib/process.js @@ -168,12 +168,12 @@ function fetchAddressData( pCondition, pConfig, AddressID, pPerson) case Placeholder.types.SQLPART: //sql part fields.push( pConfig[i].valueDefinition ); output.push([pos++, pConfig[i].type]); - header.push( pConfig[i].placeholderName ); + header.push( pConfig[i].getFormattedName() ); break; case Placeholder.types.SQLPARTFUNCTION: // adito SQL functions fields.push("(" + pConfig[i].valueDefinition.call() + ")"); output.push([pos++, pConfig[i].type]); - header.push( pConfig[i].placeholderName ); + header.push( pConfig[i].getFormattedName() ); break; case Placeholder.types.ADDRESSFORMAT: if ( posaddrfields == -1 ) @@ -184,7 +184,7 @@ function fetchAddressData( pCondition, pConfig, AddressID, pPerson) pos += addrfields.length; } output.push([posaddrfields, pConfig[i].type, pConfig[i].valueDefinition]); - header.push( pConfig[i].placeholderName ); + header.push( pConfig[i].getFormattedName() ); break; case "afunction": // adito functions @@ -192,7 +192,7 @@ function fetchAddressData( pCondition, pConfig, AddressID, pPerson) { fields.push( "'" + evalScript("Address_lib.fetchAddressData", vars.resolveVariables(pConfig[i].valueDefinition), {}, ["Attribute_lib", "Sql_lib", "Keyword_lib", "Person_lib"], true).replace(new RegExp("'","g"), "''") + "'" ); output.push([pos++, pConfig[i].type]); - header.push( pConfig[i].placeholderName ); + header.push( pConfig[i].getFormattedName() ); } catch( err ) { @@ -209,7 +209,7 @@ function fetchAddressData( pCondition, pConfig, AddressID, pPerson) configJSON.localVars]); output.push([pos++, pConfig[i].type]); - header.push( pConfig[i].placeholderName ); + header.push( pConfig[i].getFormattedName() ); break; } } diff --git a/process/DocumentTemplate_lib/documentation.adoc b/process/DocumentTemplate_lib/documentation.adoc index 03dd0265d5..8f3be0327a 100644 --- a/process/DocumentTemplate_lib/documentation.adoc +++ b/process/DocumentTemplate_lib/documentation.adoc @@ -55,7 +55,7 @@ var getProductCountFn = function (pContactId) ... //fancy code } var additionalPlaceholders = [ - new Placeholder("offercode", Placeholder.types.FIXEDVALUE, vars.get("$field.FullOfferCode"), + new Placeholder("offercode", Placeholder.types.FIXEDVALUE, vars.get("$field.FullOfferCode")), new Placeholder("productCount", Placeholder.types.CALLBACKFUNCTION, getProductCountFn) ]; var myContent = myTemplate.getReplacedContentByContactId(vars.get("$field.CONTACTID"), additionalPlaceholders); diff --git a/process/DocumentTemplate_lib/process.js b/process/DocumentTemplate_lib/process.js index 9cbc66c99c..4ced5f9f03 100644 --- a/process/DocumentTemplate_lib/process.js +++ b/process/DocumentTemplate_lib/process.js @@ -269,9 +269,13 @@ DocumentTemplate.types = { return { base64 : false }; - case this.ODT: case this.DOCX: case this.DOCM: + return { + startDelimiter : "{@", + endDelimiter : "@}" + }; + case this.ODT: default: return {}; } @@ -613,7 +617,7 @@ DocumentTemplate.prototype._getRequiredPlaceholders = function (pForcedPlacehold // filter the possible placeholders by all placeholders found placeholders = placeholders.filter(function(placeholder) { - return foundPlaceholders.includes(placeholder.placeholderName) || pForcedPlaceholders.includes(placeholder.placeholderName); + return foundPlaceholders.includes(placeholder.getFormattedName()) || pForcedPlaceholders.includes(placeholder.getFormattedName()); }); return placeholders; @@ -644,7 +648,7 @@ DocumentTemplate.prototype.getReplacementsByContactIds = function (pContactIds, break; case Placeholder.types.FIXEDVALUE: case Placeholder.types.CALLBACKFUNCTION: - additionalPlaceholders[placeholder.placeholderName] = placeholder; + additionalPlaceholders[placeholder.getFormattedName()] = placeholder; } }); var contactIdPlaceholder = new Placeholder("contactId", Placeholder.types.SQLPART, "CONTACT.CONTACTID"); @@ -818,10 +822,12 @@ DocumentTemplate.prototype._getReplacedODT = function (pReplacements, pTableData DocumentTemplate.prototype._getReplacedDOCX = function (pReplacements) { var replacements = {}; + var startDelimiter = this.options.startDelimiter; + var endDelimiter = this.options.endDelimiter; for (let placeholder in pReplacements) //removes the prefix and postfix, the process needs it like this - replacements[placeholder.slice(2, -2)] = pReplacements[placeholder]; + replacements[placeholder.slice(startDelimiter.length, -endDelimiter.length)] = pReplacements[placeholder]; - var documentData = DocxtemplaterUtils.generateDocument(this.content, replacements, "{@", "@}"); + var documentData = DocxtemplaterUtils.generateDocument(this.content, replacements, startDelimiter, endDelimiter); return documentData; } diff --git a/process/ExportTemplate_lib/process.js b/process/ExportTemplate_lib/process.js index 0272a91c61..a8c0991155 100644 --- a/process/ExportTemplate_lib/process.js +++ b/process/ExportTemplate_lib/process.js @@ -71,7 +71,7 @@ ExportTemplateUtils.buildExport = function (pExportTemplateId, pSelection, pComi var affectedPlaceholders = []; for (var i = 0; i < fields.length; i++) { var placeholderField = placeholders.find(function(placeholder){ - return placeholder.placeholderName == fields[i]; + return placeholder.getFormattedName() == fields[i]; }) if(placeholderField) affectedPlaceholders.push(placeholderField); diff --git a/process/Placeholder_lib/process.js b/process/Placeholder_lib/process.js index 7a78b088bb..4f271fa114 100644 --- a/process/Placeholder_lib/process.js +++ b/process/Placeholder_lib/process.js @@ -68,7 +68,7 @@ PlaceholderUtils.getPlaceholders = function (pLocale, pIsExportTemplateField) if(placeholders[i]["target"] != "RECIPIENT"){ placeholders.splice(i, 1); i--} - else if(placeholders[i]["placeholderName"] == "{@letterSalutation@}"){ + else if(placeholders[i].getFormattedName() == "{@letterSalutation@}"){ placeholders.splice(i, 1); i--} } @@ -106,11 +106,12 @@ PlaceholderUtils.getPlaceholders = function (pLocale, pIsExportTemplateField) /** * Returns the placeholder with the required prefix and postfix added. - * This function defines the format for placeholders. + * + * @deprecated */ PlaceholderUtils.formatPlaceholder = function (pPlaceholder) { - return "{@" + pPlaceholder + "@}"; + return Placeholder.getDefaultStartDelimiter() + pPlaceholder + Placeholder.getDefaultEndDelimiter(); } /** @@ -136,16 +137,42 @@ PlaceholderUtils.getRegexpMatchAll = function () */ function Placeholder (pName, pType, pValueDef, pTarget, pTitle) { - this.placeholderName = PlaceholderUtils.formatPlaceholder(pName); + this.startDelimiter = Placeholder.getDefaultStartDelimiter(); + this.endDelimiter = Placeholder.getDefaultEndDelimiter(); + this.placeholderName = pName; this.type = pType; this.target = pTarget || Placeholder.targets.RECIPIENT; this.valueDefinition = pValueDef; this.title = pTitle; } +/** + * Returns the default placeholder start delimiter + */ +Placeholder.getDefaultStartDelimiter = function () +{ + return "{@"; +} + +/** + * Returns the default placeholder end delimiter + */ +Placeholder.getDefaultEndDelimiter = function () +{ + return "@}"; +} + +/** + * Returns the placeholderName with startDelimiter and endDelimiter added + */ +Placeholder.prototype.getFormattedName = function () +{ + return this.startDelimiter + this.placeholderName + this.endDelimiter; +} + Placeholder.prototype.toString = function () { - return this.placeholderName; + return this.getFormattedName(); } /** -- GitLab