diff --git a/entity/BulkMail_entity/BulkMail_entity.aod b/entity/BulkMail_entity/BulkMail_entity.aod index b87e4b9166b42e4bf73b1aa642a711252aa23317..8b2e3954980f2e9f11197483db244e9549c4ffb3 100644 --- a/entity/BulkMail_entity/BulkMail_entity.aod +++ b/entity/BulkMail_entity/BulkMail_entity.aod @@ -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> diff --git a/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js b/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js index ce40fda369cf3c536c09eccdf1d9ab6b9302a3d1..3213243e36f55cfa8df7f82383779871968e5e69 100644 --- a/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js +++ b/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js @@ -1,10 +1,9 @@ -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 diff --git a/entity/BulkMail_entity/entityfields/content/displayValueProcess.js b/entity/BulkMail_entity/entityfields/content/displayValueProcess.js index d0a29fe5c7c88d61e854758f687ae47b82cc8ab2..792b6ffb622b127dedf6dc06b47567bdf60db289 100644 --- a/entity/BulkMail_entity/entityfields/content/displayValueProcess.js +++ b/entity/BulkMail_entity/entityfields/content/displayValueProcess.js @@ -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 diff --git a/entity/BulkMail_entity/entityfields/content/stateProcess.js b/entity/BulkMail_entity/entityfields/content/stateProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..1674111c065d736b00d05453dd1ca9c3201b2910 --- /dev/null +++ b/entity/BulkMail_entity/entityfields/content/stateProcess.js @@ -0,0 +1,9 @@ +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 diff --git a/entity/BulkMail_entity/entityfields/content/valueProcess.js b/entity/BulkMail_entity/entityfields/content/valueProcess.js index 708ad314bbe3d01b14e1e24026174ecc7108d14a..9b8c05e63037cd20157a5449c090f1d64902886a 100644 --- a/entity/BulkMail_entity/entityfields/content/valueProcess.js +++ b/entity/BulkMail_entity/entityfields/content/valueProcess.js @@ -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); diff --git a/entity/BulkMail_entity/entityfields/preview/valueProcess.js b/entity/BulkMail_entity/entityfields/preview/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..03c92562f2268f628be6f866b95376c0ff732191 --- /dev/null +++ b/entity/BulkMail_entity/entityfields/preview/valueProcess.js @@ -0,0 +1,4 @@ +import("system.vars"); +import("system.result"); + +result.string(vars.get("$field.content.displayValue")); \ No newline at end of file diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js b/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js index d6c1ea5f0061d78eef117c230c9349b2ae29e659..6e8433aa60be6348840a4242cfff37db8b065039 100644 --- a/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js +++ b/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js @@ -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"]; diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js index 65b9343a72ec1b1cc63fd22a99e29fcf25173c4c..66566af554fd1503c674be57f87dcb836b56f738 100644 --- a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js @@ -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"]; diff --git a/neonView/BulkMailEdit_view/BulkMailEdit_view.aod b/neonView/BulkMailEdit_view/BulkMailEdit_view.aod index 0e84b40866b2a7da76fecff0a527f14a6495abbb..d1f4d906a0b6a95504a97ad247ab4dce8f44957b 100644 --- a/neonView/BulkMailEdit_view/BulkMailEdit_view.aod +++ b/neonView/BulkMailEdit_view/BulkMailEdit_view.aod @@ -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> diff --git a/process/DocumentTemplate_lib/process.js b/process/DocumentTemplate_lib/process.js index 790fc7e0fc72d4093c6bff3bd0f5c1d41f2b0553..3746e3e3167b4e247525ab99143f0563796ab92b 100644 --- a/process/DocumentTemplate_lib/process.js +++ b/process/DocumentTemplate_lib/process.js @@ -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); diff --git a/process/Email_lib/process.js b/process/Email_lib/process.js index 4aff8cc61629ae377c2d1208ef261035955e69c3..96c8f49a9dc71a920a88fa5a45540250f2a94e70 100644 --- a/process/Email_lib/process.js +++ b/process/Email_lib/process.js @@ -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];