Skip to content
Snippets Groups Projects
Commit ef284582 authored by S.Listl's avatar S.Listl
Browse files

Placeholder replacement

parent 33622424
No related branches found
No related tags found
No related merge requests found
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<changeSet author="s.listl" id="f236804e-e3f2-43e4-8e5a-1ba48522d8c5">
<insert tableName="AB_KEYWORD_ENTRY">
<column name="AB_KEYWORD_ENTRYID" value="bdecb990-19ce-4710-afd7-321ed5bae93d"/>
<column name="KEYID" value="letterSalutation"/>
<column name="TITLE" value="Letter salutation"/>
<column name="CONTAINER" value="TextPlaceholder"/>
<column name="SORTING" valueNumeric="0"/>
<column name="ISACTIVE" valueNumeric="1"/>
<column name="ISESSENTIAL" valueNumeric="1"/>
</insert>
<insert tableName="AB_KEYWORD_ENTRY">
<column name="AB_KEYWORD_ENTRYID" value="5f31c2cd-dce9-4eeb-872c-1a3005ea3210"/>
<column name="KEYID" value="country"/>
<column name="TITLE" value="Country"/>
<column name="CONTAINER" value="TextPlaceholder"/>
<column name="SORTING" valueNumeric="1"/>
<column name="ISACTIVE" valueNumeric="1"/>
<column name="ISESSENTIAL" valueNumeric="1"/>
</insert>
<insert tableName="AB_KEYWORD_ENTRY">
<column name="AB_KEYWORD_ENTRYID" value="fd9dba2b-92aa-4957-841b-4ec85dc92817"/>
<column name="KEYID" value="zipCode"/>
<column name="TITLE" value="ZIP"/>
<column name="CONTAINER" value="TextPlaceholder"/>
<column name="SORTING" valueNumeric="2"/>
<column name="ISACTIVE" valueNumeric="1"/>
<column name="ISESSENTIAL" valueNumeric="1"/>
</insert>
<insert tableName="AB_KEYWORD_ATTRIBUTE">
<column name="AB_KEYWORD_ATTRIBUTEID" value="ebf7de02-1873-4068-b551-c5348bab4fc6"/>
<column name="NAME" value="addressFormat"/>
<column name="CONTAINER" value="TextPlaceholder"/>
<column name="TYPE" value="CHAR_VALUE"/>
</insert>
<insert tableName="AB_KEYWORD_ATTRIBUTERELATION">
<column name="AB_KEYWORD_ATTRIBUTERELATIONID" value="4cd39532-0cd1-4828-961d-76165af2f4c3"/>
<column name="AB_KEYWORD_ENTRY_ID" value="bdecb990-19ce-4710-afd7-321ed5bae93d"/>
<column name="AB_KEYWORD_ATTRIBUTE_ID" value="ebf7de02-1873-4068-b551-c5348bab4fc6"/>
<column name="CHAR_VALUE" value=""/>
</insert>
<insert tableName="AB_KEYWORD_ATTRIBUTERELATION">
<column name="AB_KEYWORD_ATTRIBUTERELATIONID" value="dd5279a9-920e-4ed3-9438-56fac9c68f31"/>
<column name="AB_KEYWORD_ENTRY_ID" value="5f31c2cd-dce9-4eeb-872c-1a3005ea3210"/>
<column name="AB_KEYWORD_ATTRIBUTE_ID" value="ebf7de02-1873-4068-b551-c5348bab4fc6"/>
<column name="CHAR_VALUE" value="{cc}"/>
</insert>
<insert tableName="AB_KEYWORD_ATTRIBUTERELATION">
<column name="AB_KEYWORD_ATTRIBUTERELATIONID" value="54b34ffe-178e-410b-a32e-3519ebf5f550"/>
<column name="AB_KEYWORD_ENTRY_ID" value="fd9dba2b-92aa-4957-841b-4ec85dc92817"/>
<column name="AB_KEYWORD_ATTRIBUTE_ID" value="ebf7de02-1873-4068-b551-c5348bab4fc6"/>
<column name="CHAR_VALUE" value="{zc}"/>
</insert>
</changeSet>
</databaseChangeLog>
......@@ -14,7 +14,7 @@
<entityDependency>
<name>5cc2e566-309c-4b47-84f3-52376e919b9b</name>
<entityName>Email_entity</entityName>
<fieldName>DocumnetTemplates</fieldName>
<fieldName>DocumentTemplates</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
......@@ -233,6 +233,12 @@
<fieldName>DocumentTemplateTexFooter</fieldName>
<isConsumer v="false" />
</entityDependency>
<entityDependency>
<name>57f408e3-aeb7-4006-a20d-287dae1f0922</name>
<entityName>Mail_entity</entityName>
<fieldName>DocumentTemplates</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
</entityProvider>
<entityParameter>
......
......@@ -13,11 +13,11 @@
<entityField>
<name>DOCUMENT_TEMPLATE</name>
<title>Document Template</title>
<consumer>DocumnetTemplates</consumer>
<consumer>DocumentTemplates</consumer>
<linkedContext>DocumentTemplate</linkedContext>
</entityField>
<entityConsumer>
<name>DocumnetTemplates</name>
<name>DocumentTemplates</name>
<dependency>
<name>dependency</name>
<entityName>DocumentTemplate_entity</entityName>
......
......@@ -2,4 +2,4 @@ import("Employee_lib");
import("system.vars");
import("Email_lib");
EmailUtils.openMailTemplate(vars.get("$field.RECIPIENT"), EmployeeUtils.getCurrentContactId(), vars.get("$field.DOCUMENT_TEMPLATE"));
\ No newline at end of file
EmailUtils.openMailTemplate(vars.get("$field.RECIPIENT"), EmployeeUtils.getCurrentContactId(), vars.get("$field.DOCUMENT_TEMPLATE"), vars.get("$param.ContactId_param"));
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.6" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.6">
<name>Mail_entity</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<recordContainer>jdito</recordContainer>
<entityFields>
<entityProvider>
<name>#PROVIDER</name>
</entityProvider>
<entityField>
<name>UID</name>
</entityField>
<entityField>
<name>DOCUMENT_TEMPLATE</name>
<consumer>DocumentTemplates</consumer>
<linkedContext>DocumentTemplate</linkedContext>
</entityField>
<entityConsumer>
<name>DocumentTemplates</name>
<dependency>
<name>dependency</name>
<entityName>DocumentTemplate_entity</entityName>
<fieldName>DocumentTemplateProvider</fieldName>
</dependency>
</entityConsumer>
</entityFields>
<recordContainers>
<jDitoRecordContainer>
<name>jdito</name>
<jDitoRecordAlias>Data_alias</jDitoRecordAlias>
<recordFields>
<element>UID.value</element>
</recordFields>
</jDitoRecordContainer>
</recordContainers>
</entity>
<?xml version="1.0" encoding="UTF-8"?>
<neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.1.0">
<name>Mail</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<entity>Mail_entity</entity>
</neonContext>
This diff is collapsed.
......@@ -66,8 +66,8 @@ CachedData.prototype.load = function(pDataCallbackFunction)
//currently it's not possible to cache the data within the serer-context, so instead the Data-function is called everytime
if (this.runningOnServer)
cachingEnabled = false;
else if (JSON.parse(project.getInstanceConfigValue("custom.dataCaching.client.forceDisable")) == true)
cachingEnabled = false;
// else if (JSON.parse(project.getInstanceConfigValue("custom.dataCaching.client.forceDisable")) == true)
// cachingEnabled = false;
if (!cachingEnabled)
return pDataCallbackFunction.call(this, this.keepPerLanguage, this.locale);
......
import("Employee_lib");
import("KeywordRegistry_basic");
import("Document_lib");
import("KeywordData_lib");
......@@ -6,16 +7,12 @@ import("Address_lib");
import("system.process");
import("system.vars");
import("system.db");
import("system.swing");
import("system.util");
import("system.pack");
import("system.fileIO");
import("system.translate");
import("system.question");
import("system.datetime");
import("system.logging");
import("system.text");
import("system.eMath");
import("system.mail");
import("Keyword_lib");
......@@ -63,15 +60,15 @@ DocumentTemplate.loadTemplate = function (pTemplateId)
DocumentTemplate.prototype.toString = function ()
{
return this.templateText;
return this.content;
}
/**
* returns the template text with replaced placeholders
* returns the template content with replaced placeholders
*
* @param {Object} pReplacements map, the structure is {placeholder : value} (the placeholder should have the prefix @@)
* @param {Object} pReplacements map, the structure is {placeholder : value}
*/
DocumentTemplate.prototype.getReplacedText = function (pReplacements)
DocumentTemplate.prototype.getReplacedContent = function (pReplacements)
{
switch (this.type)
{
......@@ -83,20 +80,24 @@ DocumentTemplate.prototype.getReplacedText = function (pReplacements)
case DocumentTemplate.types.EML:
return this._getReplacedEML(pReplacements);
case DocumentTemplate.types.ODT:
// return this._getReplacedODT(pReplacements);
return this._getReplacedODT(pReplacements);
case DocumentTemplate.types.DOCX:
// return this._getReplacedDOCX(pReplacements);
return this._getReplacedDOCX(pReplacements);
default:
return null;
}
}
DocumentTemplate.prototype.getReplacedTextByContactId = function (pContactId)
DocumentTemplate.prototype.getReplacedContentByContactId = function (pContactId)
{
var config = DocumentTemplate._getPlaceholderConfig();
var replacements = getAddressesData([pContactId], config, pSenderID, pAddressID);
//TODO: build the replacement map here
return this.getReplacedText(replacements);
var config = PlaceholderUtils.getPlaceholders();
var addressData = getAddressesData([pContactId], config, EmployeeUtils.getCurrentContactId()); //TODO: add sender selection
var replacements = {};
for (let i = 0, l = addressData[0].length; i < l; i++)
{
replacements[addressData[0][i]] = addressData[1][i];
}
return this.getReplacedContent(replacements);
}
DocumentTemplate.prototype._getReplacedEML = function (pReplacements)
......@@ -105,92 +106,85 @@ DocumentTemplate.prototype._getReplacedEML = function (pReplacements)
}
/*
* replaces a given Odt-File on the server and returns the replaced base64-file
*
* @deprecated needs refactoring
*
* @param {String} pTemplateData req base64-encoded input file with placeholders
* @param {String} pTemplateName req name of the input file
* @param {String|String[]} pAddrDataCondition req a SQL-Condition or an Array of Relation-Ids for reducing the default-placeholders
* @param {String} pAddressID opt if you want to use the standard address you can pass undefined, otherwise you need to specify a Address-Id
* @param {Object} pAdditionalData opt additional placeholders with data (e.g. offercode); for format check the example
* @param {Object[]} pTableData opt data for odt-tables; for format check the example
*
* @return {String} base64-encoded replaced file
*
* @example
* //examples for additionalData:
* //2 Methods: 1) SQL 2) Array - no matter what you're using: the first column has to be the RELATIONID-Value
* //1) you can use a SQL-Statement for passing Data
* additionalData = {
* Fields: ["RELID", "myPlaceholder 1","myPlaceholder N"]
* ,SQLStr: "select RELATION_ID, ADDR, MEDIUM_ID from COMM"
* };
* //if you pass the (optional) property "ID" a condition with ID in <<relationids>> is added to the SQL-Data-query:
* additionalData.ID = "COMM.RELATION_ID";
*
*
* //2) another option is to pass data as a 2D-Array like this
* additionalData = {
* Fields: ["RELID", "myPlaceholder 1","myPlaceholder N"]
* ,Data: [
* ["myRelIdValue 1", "my Value 1", "my Value N"]
* ,["myRelIdValue M", "my other Value 1", "my other Value N"]
* ]
* };
*
*
* //examples for tableData:
* //you can define multible data-sources
* tableData = [];
* //2 Methods: 1) SQL 2) Array - no matter what you're using: the first column has to be the RELATIONID-Value
* //the placeholder can be accessed by <<Table>>.<<Field>>
* //1) if you use a SQL-Statement for defining the data you've got some optional properties
* var sqlSource = {
* Table: "ADDR"
* ,Fields: ["RELID", "Type", "Strasse", "PLZ", "Ort", "Staat", "Land"],
* ,SQLStr: "select RELATION_ID, ADDR_TYPE, " + concat(["ADDRESS", "BUILDINGNO"]) + ", ZIP, CITY, STATE, NAME_DE from ADDRESS join COUNTRYINFO on COUNTRY = ISO2"
* };
* //if you pass the (optional) property "ID" a condition with ID in <<relationids>> is added to the SQL-Data-query:
* sqlSource.ID = "ADDRESS.RELATION_ID";
*
* //if you pass the (optional) property "SQLOrder" an order-by clause is added
* sqlSource.SQLOrder = "ADDRESS.ADDR_TYPE asc, ADDRESS.ZIP desc";
*
* tableData.push(sqlSource);
*
* //2) pass data as an Array like this
* var arraySource = {
* Table: "myTablePrefix"
* ,Fields: ["RELID", "myPlaceholder 1","myPlaceholder N"]
* ,Data: [
* ["myRelIdValue 1", "my Value 1", "my Value N"]
* ,["myRelIdValue M", "my other Value 1", "my other Value N"]
* ]
* }
* tableData.push(arraySource);
*
*/
DocumentTemplateUtils.getReplacedODT = function (pTemplateData, pTemplateName, pAddrDataCondition, pAddressID, pAdditionalData, pTableData)
DocumentTemplate.prototype._getReplacedODT = function (pAddrDataCondition, pAddressID)
{
//save the file on the server, replace it on the server file system, then load it because that works for neon and swing
//save the file on the server so it can be unzipped via pack.getFromZip
var serverFilePath = vars.get("$sys.servertemp") + "/clientid_" + vars.get("$sys.clientid")
+ "/" + util.getNewUUID() + "/" + pTemplateName.replace(/\\/g, "/");
+ "/" + util.getNewUUID();
fileIO.storeData(serverFilePath, pTemplateData, util.DATA_BINARY, false);
if ( ! replaceODTFile(pAddrDataCondition, serverFilePath, pAddressID, pAdditionalData, pTableData ))
fileIO.storeData(serverFilePath, this.content, util.DATA_BINARY, false);
if (!_replaceODTFile(pAddrDataCondition, serverFilePath, pAddressID))
return null;
var replacedFileData = fileIO.getData(serverFilePath, util.DATA_BINARY);
fileIO.remove(serverFilePath);
return replacedFileData;
}
DocumentTemplate.prototype._getReplacedODT = function (pReplacements)
{
/*
* ersetzt die Platzhalter in ODT-Datei
*
* @param {String} pCondition req Condition
* @param {String} pODTFileName req Filename des odt-Datei
* @param {String} pAddressID opt ID von der die Adressdaten geholt werden
*
* @return {Boolean}
*/
function _replaceODTFile (pCondition, pODTFileName, pAddressID)
{
// Configuration für die Platzhalter
var config = PlaceholderUtils.getPlaceholders(); //["RELATIONID","fieldname","RELATION.RELATIONID"]
var senderRelId = EmployeeUtils.getCurrentContactId();
if (senderRelId == null)
return false;
var addrdata = getAddressesData(pCondition, config, senderRelId, pAddressID);
if (addrdata.length > 1)
{
var relationids = [];
for (let i = 1; i < addrdata.length; i++ )
relationids.push(addrdata[i][0]);
// ersetzen Platzhalter in content.xml
var textS = util.decodeBase64String(pack.getFromZip(pODTFileName, "content.xml"));
var bodybegin = textS.indexOf("<office:body>");
var bodyend = textS.indexOf("</office:body>") + 14;
var body = textS.substring( bodybegin, bodyend );
var lastbody = textS.substr( bodyend );
textS = textS.substring( 0, bodybegin );
for (let i = 1; i < addrdata.length; i++)
{
var bulkbody = body;
for (let ii = 0; ii < addrdata[0].length; ii++)
{
bulkbody = bulkbody.replace(new RegExp(getDefaultODTplaceholer(addrdata[0][ii]), "ig"),
addrdata[i][ii].replace(/\n/ig, "<text:line-break/>").replace(/&/ig, "&amp;") );
}
textS += bulkbody;
}
textS += lastbody;
pack.addToZip(pODTFile, "content.xml", util.encodeBase64String(textS))
// ersetzen Platzhalter in styles.xml
var styles = util.decodeBase64String(pack.getFromZip(pODTFileName, "styles.xml"));
for (let i = 0; i < addrdata[0].length; i++)
{
styles = styles.replace(new RegExp( getDefaultODTplaceholer(addrdata[0][i]), "ig"),
addrdata[1][i].replace(/\n/ig, "<text:line-break/>").replace(/&/ig, "&amp;"));
}
pack.addToZip(pODTFile, "styles.xml", util.encodeBase64String(styles));
return true;
}
return false;
}
}
/*
......@@ -204,8 +198,8 @@ DocumentTemplate.prototype._getReplacedDOCX = function (pReplacements)
{
//this is executed as a process because of better performance
var documentData = process.execute("getDocxDocument_serverProcess", {
templateb64: this.templateText,
placeholderConfig: JSON.stringify(pPlaceholder) //process.execute is only able to handle strings
templateb64: this.content,
placeholderConfig: JSON.stringify(pReplacements) //process.execute is only able to handle strings
});
return documentData;
......@@ -234,128 +228,68 @@ DocumentTemplateUtils._getPlaceholderConfig = function ()
}
/*
* ersetzt die Platzhalter in ODT-Datei
*
* @deprecated needs refactoring
*
* @param {String} pCondition req Condition
* @param {String} pODTFile req Filename des odt-Datei
* @param {String} pAddressID opt ID von der die Adressdaten geholt werden
*
* @return {void}
*/
DocumentTemplateUtils.replaceODTFile = function (pCondition, pODTFile, pAddressID)
{
// Configuration für die Platzhalter
var config = [["RELATIONID","fieldname","RELATION.RELATIONID"]]
config = config.concat(DocumentTemplateUtils._getPlaceholderConfig());
var senderRelId = getSendRelID();
if (senderRelId == null)
return false;
var addrdata = getAddressesData(pCondition, config, senderRelId, pAddressID);
if (addrdata.length > 1)
{
var relationids = [];
for (let i = 1; i < addrdata.length; i++ )
relationids.push(addrdata[i][0]);
// ersetzen Platzhalter in content.xml
function PlaceholderUtils () {}
var textS = util.decodeBase64String(pack.getFromZip(pODTFile, "content.xml"));
var bodybegin = textS.indexOf("<office:body>");
var bodyend = textS.indexOf("</office:body>") + 14;
var body = textS.substring( bodybegin, bodyend );
var lastbody = textS.substr( bodyend );
textS = textS.substring( 0, bodybegin );
for (let i = 1; i < addrdata.length; i++)
{
var bulkbody = body;
for (let ii = 0; ii < addrdata[0].length; ii++)
{
bulkbody = bulkbody.replace( new RegExp( getDefaultODTplaceholer(addrdata[0][ii]), "ig"),
addrdata[i][ii].replace( new RegExp( "\n", "ig"), "<text:line-break/>").replace( new RegExp( "&", "ig"), "&amp;") );
}
textS += bulkbody;
}
textS += lastbody;
pack.addToZip(pODTFile, "content.xml", util.encodeBase64String(textS))
// ersetzen Platzhalter in styles.xml
var styles = util.decodeBase64String(pack.getFromZip(pODTFile, "styles.xml"));
for (let i = 0; i < addrdata[0].length; i++)
{
styles = styles.replace( new RegExp( getDefaultODTplaceholer(addrdata[0][i]), "ig"),
addrdata[1][i].replace( new RegExp( "\n", "ig"), "<text:line-break/>").replace( new RegExp( "&", "ig"), "&amp;") );
}
pack.addToZip(pODTFile, "styles.xml", util.encodeBase64String(styles));
return true;
}
return false;
}
PlaceholderUtils.types = {
ADDRESSFORMAT : "ADDRESSFORMAT",
SQLPART : "SQLPART",
SQLPARTFUNCTION : "SQLPARTFUNCTION"
};
PlaceholderUtils.targets = {
RECIPIENT : "RECIPIENT",
SENDER : "SENDER",
EMPLOYEE : "EMPLOYEE"
};
/*
* Liefert Vorlage mit ersetzen Platzhalter durch den jeweiligen Text.
*
* @deprecated needs refactoring
*
* @param {String} pContactId req RELATIONID der relation, von der die Adressdaten geholt werden - SQL where condition für getAddressesData()
* @param {Integer[]} pDocuType req OATYPE der Vorlage
* @param {String} pLanguage opt Sprache
* @param {String} pAddressID opt pAddressID
* @param {String} pSenderID opt UserRelationID
* @param {String} pTemplateName opt Name der Vorlage
*
* @return {Obj} { id, name, language, attachments:[[Name, Data]], template:{filename, data},
* exportoption:{fieldids, open, file, fieldseperator, fieldlimit, recordseperator} }
* oder {Boolean:false} wenn keine Vorlage vorhanden ist oder ausgewählt wurde
*/
DocumentTemplateUtils.getReplacedText = function (pContactId, pDocuType, pLanguage, pAddressID, pSenderID, pTemplateName)
/**
* Returns the placeholder with the required prefix and postfix added.
* This function defines the format for placeholders.
*/
PlaceholderUtils.formatPlaceholder = function (pPlaceholder)
{
var document = chooseTemplate( pDocuType, pLanguage, pTemplateName);
if (!document) return null;
return "@@" + pPlaceholder + "@@";
}
var isHtml = document.template.data.substr(0, 6) == "<html>"
if (document.template.filename != undefined)
document.template.data = decode64(document.template.data);
// Configuration für die Platzhalter
var config = KeywordData.getKeywordAttributeRelations("TextPlaceholder"); //->keyword registry
var addrdata = getAddressesData( [pContactId], config, pSenderID, pAddressID );
var value;
var prefix = "@@";
for (let i = 0, l = addrdata[0].length; i < l; i++)
PlaceholderUtils.getPlaceholders = function ()
{
function Placeholder (pName, pType, pValueDef, pTarget)
{
if (isHtml)
value = addrdata[1][i].replace(new RegExp( "\n", "ig"), "<br>");
else
value = addrdata[1][i];
document.template.data = document.template.data.replace(new RegExp(prefix + addrdata[0][i], "ig"), value);
this.placeholderName = PlaceholderUtils.formatPlaceholder(pName);
this.type = pType;
this.target = pTarget || PlaceholderUtils.targets.RECIPIENT;
this.valueDefinition = pValueDef;
}
return document;
}
/*
* transforms a given placeholerformat into the ODT-placeholer thats in the ODT
* if you have to change this (e.g. to @@) you can do this at this 1 position
*
* @deprecated needs refactoring
*
* @param {String} pPlaceholderName req name of the placeholer, e.g. "Anrede"
* @param {bool} pOnlyStart opt if set to true only the leading-symbols are added
*
* @return {String} placeholder with placeholder-symbols, e.g. "{@Anrede@}"
*/
DocumentTemplateUtils.getDefaultODTplaceholer = function (pPlaceholderName, pOnlyStart)
{
if (pOnlyStart)
return "{@" + pPlaceholderName;
return "{@" + pPlaceholderName + "@}";
function _addAddressFormat (pName, pFormat, pTarget)
{
placeholders.push(new Placeholder(pName, PlaceholderUtils.types.ADDRESSFORMAT, pFormat, pTarget));
}
function _addSqlPart (pName, pSqlPart, pAddBraces)
{
placeholders.push(new Placeholder(pName, PlaceholderUtils.types.SQLPART, pAddBraces ? "(" + pSqlPart + ")" : pSqlPart));
}
function _addSqlPartFunction (pName, pSqlPartFunction, pTarget)
{
placeholders.push(new Placeholder(pName, PlaceholderUtils.types.SQLPARTFUNCTION, pSqlPartFunction, pTarget));
}
var placeholders = [];
_addAddressFormat("address", "{street} {buildingno}");
_addAddressFormat("zipCode", "{zip}");
_addAddressFormat("city", "{city}");
_addAddressFormat("district", "{district}");
_addAddressFormat("region", "{region}");
_addAddressFormat("country", "{country}");
_addAddressFormat("letterSalutation", "{letter_salutation}");
_addAddressFormat("fullAddress", "");
_addAddressFormat("senderOrgname", "{organisation_name}", PlaceholderUtils.targets.SENDER);
_addAddressFormat("senderAddress", "{street} {buildingno}", PlaceholderUtils.targets.SENDER);
_addAddressFormat("senderZipCity", "{country} - {zip} {city}", PlaceholderUtils.targets.SENDER);
_addAddressFormat("senderFullAddress", "", PlaceholderUtils.targets.SENDER);
return placeholders;
}
import("system.logging");
import("system.translate");
import("system.text");
import("system.db");
......@@ -16,15 +17,16 @@ function EmailUtils () {}
* In Thunderbird the mail is opened in view mode and you've to manually "edit as new"
*
* @param {String|Array} pToRecipients mailaddresses of the recipients, can either be a 1D-Array with several addresses or a string with one address
* @param {String} pContactId contactId of the sender. the standard mailadress of the contact is used as sender-address
* @param {String} pSenderContactId contactId of the sender. the standard mailadress of the contact is used as sender-address
* @param {String} [pTemplateId] if a document-template shall be used, give the templateId here
* @param {String} [pRecipientContactId] contactId of the recipient, required to fill placeholders
*/
EmailUtils.openMailTemplate = function (pToRecipients, pContactId, pTemplateId)
EmailUtils.openMailTemplate = function (pToRecipients, pSenderContactId, pTemplateId, pRecipientContactId)
{
var email = new Email(pToRecipients);
email.setSender(pContactId);
email.setSender(pSenderContactId);
if (pTemplateId)
email.setTemplate(pTemplateId);
email.setTemplate(pTemplateId, pRecipientContactId);
email.downloadEML();
}
......@@ -71,10 +73,15 @@ function Email (pToRecipients, pSender, pSubject, pBody, pCcRecipients, pBccReci
* loads a document template into the mail body
*
* @param {String} pTemplateId the id of the template
* @param {String} pContactId the id of the template
*/
Email.prototype.setTemplate = function (pTemplateId)
Email.prototype.setTemplate = function (pTemplateId, pContactId)
{
this.body = String(DocumentTemplate.loadTemplate());
var template = DocumentTemplate.loadTemplate(pTemplateId);
//TODO: also set other properties if the template is a eml
if (template)
this.body = template.getReplacedContentByContactId(pContactId);
logging.log(this.body)
}
/**
......
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