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

1054585 Additional placeholders for DocumentTemplates

parent 0aa855e7
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET && vars.get("$field
var template = new DocumentTemplate(util.encodeBase64String(vars.get("$field.content")), vars.get("$field.templateType"), undefined, true)
var contactId = EmployeeUtils.getCurrentContactId();
var preview = template.getReplacedContentByContactId(contactId, false, true);
var preview = template.setOptions({onlyBody : true}).getReplacedContentByContactId(contactId);
result.string(preview);
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ if (vars.exists("$context.currentTemplateType"))
var template = new DocumentTemplate(util.encodeBase64String(vars.get("$field.Content")), type, "unknown", true)
var contactId = EmployeeUtils.getCurrentContactId();
var preview = template.getReplacedContentByContactId(contactId, false, true);
var preview = template.setOptions({onlyBody : true}).getReplacedContentByContactId(contactId);
if (type == DocumentTemplate.types.TXT)
result.string(text.text2html(preview, false));
......
......@@ -124,6 +124,10 @@
<iconId>VAADIN:AT</iconId>
<stateProcess>%aditoprj%/entity/Email_entity/entityfields/sendmail/stateProcess.js</stateProcess>
</entityActionField>
<entityParameter>
<name>AdditionalPlaceholders_param</name>
<expose v="true" />
</entityParameter>
</entityFields>
<recordContainers>
<datalessRecordContainer>
......
......@@ -16,6 +16,16 @@ var notificationMsg = vars.get("$param.NotificationMsg_param");
var notificationTitle = translate.text("Offer status changed");
var subject = vars.get("$field.subject");
var additionalPlaceholders = null;
if (vars.exists("$param.AdditionalPlaceholders_param") && vars.get("$param.AdditionalPlaceholders_param"))
{
additionalPlaceholders = JSON.parse(vars.get("$param.AdditionalPlaceholders_param")).map(function (placeholder)
{
//assign the values from the JSON to a new Placeholder, so that the resulting object is an actual instance of Placeholder
return Object.assign(new Placeholder(), placeholder);
});
}
var eml = EmailWritingUtils.openMailTemplate(
vars.get("$field.RECIPIENT"),
EmployeeUtils.getCurrentContactId(),
......@@ -24,8 +34,9 @@ var eml = EmailWritingUtils.openMailTemplate(
bindata,
attachments,
subject,
emailFilename
);
emailFilename,
additionalPlaceholders
);
if (notificationMsg)
......
......@@ -72,6 +72,10 @@
<state>DISABLED</state>
<stateProcess>%aditoprj%/entity/Letter_entity/entityfields/downloadletterandcreateactivity/stateProcess.js</stateProcess>
</entityActionField>
<entityParameter>
<name>AdditionalPlaceholders_param</name>
<expose v="true" />
</entityParameter>
</entityFields>
<recordContainers>
<datalessRecordContainer>
......
......@@ -6,12 +6,22 @@ import("system.vars");
import("system.text");
import("DocumentTemplate_lib");
import("KeywordRegistry_basic");
import("Placeholder_lib");
var template = DocumentTemplate.getSelectedTemplate(vars.get("$field.DOCUMENT_TEMPLATE"), new FileUpload(vars.get("$field.bindata")));
if (template)
{
var contactId = vars.get("$param.ContactId_param");
var content = template.getReplacedContentByContactId(contactId, true);
var additionalPlaceholders = null;
if (vars.exists("$param.AdditionalPlaceholders_param") && vars.get("$param.AdditionalPlaceholders_param"))
{
additionalPlaceholders = JSON.parse(vars.get("$param.AdditionalPlaceholders_param")).map(function (placeholder)
{
//assign the values from the JSON to a new Placeholder, so that the resulting object is an actual instance of Placeholder
return Object.assign(new Placeholder(), placeholder);
});
}
var content = template.setOptions({base64 : true}).getReplacedContentByContactId(contactId, additionalPlaceholders);
if (template.type)
neon.download(content, template.filename);
......
......@@ -6,9 +6,11 @@ import("system.translate");
import("Offer_lib");
import("Email_lib");
import("Sql_lib");
import("MimeType_lib");
import("Placeholder_lib");
var offerReport = new Object();
var attachmentArray = new Array();
var offerReport = {};
var attachmentArray = [];
var notificationMsg = translate.text("The status of the offer was changed to \"Sent\".");
var contactId = vars.get("$field.CONTACT_ID");
var arrayReport = OfferUtils.buildOfferReport(vars.get("$field.OFFERID"));
......@@ -17,12 +19,16 @@ var emailFilename = translate.text("Offerrequest");
if (vars.get("$field.CONTACT_ID") == null || "") contactId = vars.get("$field.CONTACT_ORG_ID");
offerReport.content = arrayReport[1];
offerReport.contentType = "application/pdf";
offerReport.contentType = MimeTypes.PDF();
offerReport.filename = translate.text("Offer No.") + vars.get("$field.#CONTENTTITLE") + ".pdf";
attachmentArray[0] = offerReport;
EmailWritingUtils.sendReportAsMail(contactId, attachmentArray, "Offer", notificationMsg, emailFilename);
var additionalPlaceholders = [
new Placeholder("offerCode", Placeholder.types.FIXEDVALUE, vars.get("$field.OFFERCODE"))
];
EmailWritingUtils.sendReportAsMail(contactId, attachmentArray, "Offer", notificationMsg, emailFilename, additionalPlaceholders);
newWhere("OFFER.OFFERID", "$field.OFFERID")
.updateData(true, "OFFER", ["STATUS"], null, [$KeywordRegistry.offerStatus$sent()]);
......
This diff is collapsed.
......@@ -30,7 +30,7 @@ function EmailWritingUtils () {}
* @param {String} [pEmailFilename] filename of the email.
* @return {Array} the eml document as array with [filename, base64]
*/
EmailWritingUtils.openMailTemplate = function (pToRecipients, pSenderContactId, pTemplateId, pRecipientContactId, pBindata, pAttachments, pSubject, pEmailFilename)
EmailWritingUtils.openMailTemplate = function (pToRecipients, pSenderContactId, pTemplateId, pRecipientContactId, pBindata, pAttachments, pSubject, pEmailFilename, pAdditionalPlaceholders)
{
if (pToRecipients && typeof(pToRecipients) == "string")
pToRecipients = [pToRecipients];
......@@ -39,7 +39,7 @@ EmailWritingUtils.openMailTemplate = function (pToRecipients, pSenderContactId,
if (pTemplateId || (pBindata.bindata != "" && pBindata.bindata != null))
{
email = Email.fromTemplate(pTemplateId, pRecipientContactId, pBindata);
email = Email.fromTemplate(pTemplateId, pRecipientContactId, pBindata, pAdditionalPlaceholders);
if (!email)
email = new Email();
}
......@@ -76,15 +76,17 @@ EmailWritingUtils.openMailTemplate = function (pToRecipients, pSenderContactId,
* @param {String} pNotificationMsg message which will be shown after the operation is done.
* @param {String} pComingFrom source from where you started (e.g. "Person", "Organisation" )
* @param {String} pEmailFilename optional file name of the email.
* @param {String} [pAdditionalPlaceholders] additional placeholders for the email
*/
EmailWritingUtils.openNewMail = function (pToContactId, pToEmailAddress, pComingFrom, pAttachmentArray, pNotificationMsg, pEmailFilename)
EmailWritingUtils.openNewMail = function (pToContactId, pToEmailAddress, pComingFrom, pAttachmentArray, pNotificationMsg, pEmailFilename, pAdditionalPlaceholders)
{
var params = {
"ContactId_param" : pToContactId,
"Attachments_param" : JSON.stringify(pAttachmentArray),
"ComingFrom_param" : pComingFrom,
"NotificationMsg_param" : pNotificationMsg,
"EmailFilename" : pEmailFilename
"EmailFilename" : pEmailFilename,
"AdditionalPlaceholders_param" : JSON.stringify(pAdditionalPlaceholders)
};
if (pToEmailAddress)
......@@ -107,14 +109,15 @@ EmailWritingUtils.getMailbridgeAddress = function ()
* @param {Array} pReportArray array with reports.
* @param {String} pNotificationMsg message which will be shown after the operation is done.
* @param {String} pEmailFilename optional file name of the email.
* @param {String} [pAdditionalPlaceholders] additional placeholders for the email
* Report have to be a object with these attrs: content (base64 encoded report), contentType (mimeType of the report), filename (complete filename with filending)
*/
EmailWritingUtils.sendReportAsMail = function (pRecipient, pReportArray, pComingFrom, pNotificationMsg, pEmailFilename)
EmailWritingUtils.sendReportAsMail = function (pRecipient, pReportArray, pComingFrom, pNotificationMsg, pEmailFilename, pAdditionalPlaceholders)
{
var pRecpientEmail = newSelect("COMMUNICATION.ADDR").from("COMMUNICATION")
.where("COMMUNICATION.CONTACT_ID", pRecipient).and("COMMUNICATION.MEDIUM_ID", "COMMEMAIL").cell();
EmailWritingUtils.openNewMail(pRecipient, pRecpientEmail, pComingFrom, pReportArray, pNotificationMsg, pEmailFilename);
EmailWritingUtils.openNewMail(pRecipient, pRecpientEmail, pComingFrom, pReportArray, pNotificationMsg, pEmailFilename, pAdditionalPlaceholders);
}
/**
......@@ -168,7 +171,7 @@ Email.fromRFC = function (pBase64RFC)
* @param {String} [pBindata] (required)
* @return {Email} a new Email object
*/
Email.fromTemplate = function (pTemplateId, pContactId, pBindata)
Email.fromTemplate = function (pTemplateId, pContactId, pBindata, pAdditionalPlaceholders)
{
var template;
......@@ -184,7 +187,7 @@ Email.fromTemplate = function (pTemplateId, pContactId, pBindata)
return null;
}
return template.getReplacedEmailsByContactIds([pContactId])[pContactId];
return template.getReplacedEmailsByContactIds([pContactId], pAdditionalPlaceholders)[pContactId];
}
/**
......
......@@ -120,14 +120,9 @@ PlaceholderUtils.formatPlaceholder = function (pPlaceholder)
* return "my special replacement"
* });
*/
PlaceholderUtils.getRegexpMatchAll = function (pSpecialCharFilterRegexpPart)
PlaceholderUtils.getRegexpMatchAll = function ()
{
if (pSpecialCharFilterRegexpPart == undefined)
{
pSpecialCharFilterRegexpPart = "";
}
return "{" + pSpecialCharFilterRegexpPart + "@(.(?!{@)|(\\r?\\n))+?@" + pSpecialCharFilterRegexpPart + "}";
return /\{@(.(?!{@)|(\r?\n))+?@\}/gi;
}
/**
......@@ -170,7 +165,15 @@ Placeholder.types = {
/**
* function that returns a sub-sql
*/
SQLPARTFUNCTION : "SQLPARTFUNCTION"
SQLPARTFUNCTION : "SQLPARTFUNCTION",
/**
* a predefined value, useful for own implementations of special placeholders
*/
FIXEDVALUE : "FIXEDVALUE",
/**
* functions that returns the value for the placeholder
*/
CALLBACKFUNCTION : "CALLBACKFUNCTION"
};
/**
......
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