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

bulkmail preview fixes

parent a9845917
No related branches found
No related tags found
No related merge requests found
Showing
with 70 additions and 29 deletions
......@@ -131,6 +131,7 @@
<name>content</name>
<title>Content</title>
<contentTypeProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js</contentTypeProcess>
<stateProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/stateProcess.js</stateProcess>
<valueProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/valueProcess.js</valueProcess>
<displayValueProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/displayValueProcess.js</displayValueProcess>
</entityField>
......@@ -237,6 +238,11 @@
</entityParameter>
</children>
</entityConsumer>
<entityField>
<name>preview</name>
<title>Preview</title>
<valueProcess>%aditoprj%/entity/BulkMail_entity/entityfields/preview/valueProcess.js</valueProcess>
</entityField>
</entityFields>
<recordContainers>
<dbRecordContainer>
......
import("system.logging");
import("Bulkmail_lib");
import("system.result");
import("Document_lib");
import("system.vars");
import("DocumentTemplate_lib");
/*
var mimeType = DocumentUtil.getMimeTypeFromUpload(vars.get("$field.bindata"));
var type;
if (mimeType)
......@@ -16,7 +15,7 @@ else
let template = BulkMailUtils.getBulkMailTemplate(vars.get("$field.BULKMAILID"), vars.get("$field.DOCUMENTTEMPLATE_ID"), false);
type = template.type;
}
logging.log(JSON.stringify([type], null, "\t"))
result.string(type == DocumentTemplate.types.TXT
*/
result.string(vars.get("$context.currentTemplateType") == DocumentTemplate.types.TXT
? "LONG_TEXT"
: "HTML");
\ No newline at end of file
......@@ -2,17 +2,17 @@ import("Bulkmail_lib");
import("system.text");
import("Employee_lib");
import("system.vars");
import("system.util");
import("system.result");
import("system.neon");
import("DocumentTemplate_lib");
//if this was done for every row, like in a lookup, the performance would be very bad
// if this was done for every row, like in a lookup, the performance would be very bad
if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET)
{
var template = BulkMailUtils.getBulkMailTemplate(vars.get("$field.BULKMAILID"), vars.get("$field.DOCUMENTTEMPLATE_ID"), true);
var template = new DocumentTemplate(util.encodeBase64String(vars.get("$field.content")), vars.get("$context.currentTemplateType"), undefined, true)
var contactId = EmployeeUtils.getCurrentContactId();
var preview = template.getReplacedContentByContactId(contactId);
var preview = template.getReplacedContentByContactId(contactId, false, true);
result.string(preview);
}
\ No newline at end of file
import("system.result");
import("system.vars");
import("system.neon");
import("DocumentTemplate_lib");
if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_VIEW && vars.get("$context.currentTemplateType") == DocumentTemplate.types.EML)
{
result.string(neon.COMPONENTSTATE_INVISIBLE);
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ import("system.db");
import("DocumentTemplate_lib");
import("Bulkmail_lib");
if (vars.get("$this.value") == null && vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET)
if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET)
{
var upload = new FileUpload(vars.get("$field.bindata"));
var template;
......@@ -15,8 +15,9 @@ if (vars.get("$this.value") == null && vars.get("$sys.viewmode") == neon.FRAME_V
template = DocumentTemplate.fromUpload(upload);
else
template = BulkMailUtils.getBulkMailTemplate(vars.get("$field.BULKMAILID"), vars.get("$field.DOCUMENTTEMPLATE_ID"), false);
// TODO: @SL why replace with {}?
vars.set("$context.currentTemplateType", template.type);
var content = template.getReplacedContent({});
if (content)
result.string(content);
......
import("system.vars");
import("system.result");
result.string(vars.get("$field.content.displayValue"));
\ No newline at end of file
......@@ -7,7 +7,9 @@ import("system.util");
import("Document_lib");
import("Bulkmail_lib");
var content = vars.get("$field.content");
if (vars.get("$context.currentTemplateType") != DocumentTemplate.types.EML)
var content = vars.get("$field.content");
var bindata = vars.get("$field.bindata");
var rowdata = vars.get("$local.rowdata");
var bulkMailId = rowdata["BULKMAIL.BULKMAILID"];
......
......@@ -7,7 +7,10 @@ import("system.db");
import("Document_lib");
import("Bulkmail_lib");
var content = vars.get("$field.content");
// eml is not editable
if (vars.get("$context.currentTemplateType") != DocumentTemplate.types.EML)
var content = vars.get("$field.content");
var bindata = vars.get("$field.bindata");
var rowdata = vars.get("$local.rowdata");
var bulkMailId = rowdata["BULKMAIL.BULKMAILID"];
......
......@@ -61,5 +61,15 @@
</entityFieldLink>
</fields>
</genericViewTemplate>
<genericViewTemplate>
<name>Preview</name>
<entityField>#ENTITY</entityField>
<fields>
<entityFieldLink>
<name>cd6a398f-de68-433d-aa67-4f1084ab4971</name>
<entityField>preview</entityField>
</entityFieldLink>
</fields>
</genericViewTemplate>
</children>
</neonView>
......@@ -55,14 +55,18 @@ function DocumentTemplate(pTemplateContent, pType, pFilename, pResolveSubtemplat
/**
* @return {String} the text of the content
*/
DocumentTemplate.prototype.toString = function (pWithSubtemplates)
DocumentTemplate.prototype.toString = function (pWithSubtemplates, pEmlOnlyBody)
{
if (this._stringCache == null)
{
var content = this._getTemplatedContent(pWithSubtemplates);
logging.log(JSON.stringify([content], null, "\t"))
if (this.type == DocumentTemplate.types.PLAIN)
this._stringCache = content;
else if (pEmlOnlyBody && this.type == DocumentTemplate.types.EML)
{
let email = Email.fromRFC(util.encodeBase64String(content))
this._stringCache = email.body;
}
else
this._stringCache = text.parseDocument(content);
}
......@@ -284,14 +288,17 @@ DocumentTemplate.getSelectedTemplate = function (pTemplateId, pDocumentUpload, p
*
* @return {String} the replaced content
*/
DocumentTemplate.prototype.getReplacedContent = function (pReplacements, pEncoded)
DocumentTemplate.prototype.getReplacedContent = function (pReplacements, pEncoded, pEmlOnlyBody)
{
// if there exists a _subtemplatedContent we use it because then I assume that the replacements are already based on content + subtemplates
var content;
if (this._subtemplatedContent == null)
content = this.content
else
content = this._subtemplatedContent
if (!pEmlOnlyBody)
{
var content;
if (this._subtemplatedContent == null)
content = this.content
else
content = this._subtemplatedContent
}
switch (this.type)
{
......@@ -305,7 +312,11 @@ DocumentTemplate.prototype.getReplacedContent = function (pReplacements, pEncode
encodedContent = util.encodeBase64String(encodedContent);
return encodedContent;
case DocumentTemplate.types.EML:
let emlContent = util.decodeBase64String(content);
let emlContent
if (pEmlOnlyBody)
emlContent = this.toString(true, true)
else
emlContent = util.decodeBase64String(content);
emlContent = TemplateHelper._replaceText(emlContent, pReplacements, TemplateHelper._getSpecialRegexp(this));
if (pEncoded)
emlContent = util.encodeBase64String(emlContent);
......@@ -327,10 +338,10 @@ DocumentTemplate.prototype.getReplacedContent = function (pReplacements, pEncode
/**
* replaces the placeholders with data from one contact and returns the result
*/
DocumentTemplate.prototype.getReplacedContentByContactId = function (pContactId, pEncoded)
DocumentTemplate.prototype.getReplacedContentByContactId = function (pContactId, pEncoded, pEmlOnlyBody)
{
var replacements = TemplateHelper._getReplacementsByContactIds(this, [pContactId]);
var content = this.getReplacedContent(replacements[pContactId], pEncoded);
var content = this.getReplacedContent(replacements[pContactId], pEncoded, pEmlOnlyBody);
return content;
}
......@@ -455,10 +466,7 @@ TemplateHelper._getRequiredPlaceholders = function (pTemplate)
{
var content = "";
// for eml search the whole file not just the body text as placeholders could be anywhere (e.g. subject)
if (pTemplate.type == DocumentTemplate.types.EML)
content = pTemplate._getTemplatedContent(true);
else
content = pTemplate.toString(true);
content = pTemplate.toString(true, false);
// get special regexp (e.g. to filter '=' in emls)
var filterRegexpPart = TemplateHelper._getSpecialRegexp(pTemplate);
......
......@@ -94,7 +94,6 @@ Email.fromRFC = function (pBase64RFC)
{
var decoded = util.decodeBase64String(pBase64RFC);
var mailData = mail.parseRFC(decoded);
var newMail = new Email();
newMail.subject = mailData[mail.MAIL_SUBJECT];
newMail.body = mailData[mail.MAIL_HTMLTEXT];
......
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