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

Bulkmail fixes

parent f159a649
No related branches found
No related tags found
No related merge requests found
Showing
with 85 additions and 62 deletions
......@@ -45,6 +45,9 @@
<consumer>Templates</consumer>
<mandatory v="false" />
<onValueChange>%aditoprj%/entity/BulkMail_entity/entityfields/documenttemplate_id/onValueChange.js</onValueChange>
<onValueChangeTypes>
<element>MASK</element>
</onValueChangeTypes>
</entityField>
<entityConsumer>
<name>Recipients</name>
......@@ -114,6 +117,10 @@
<name>bindata</name>
<contentType>FILE</contentType>
<stateProcess>%aditoprj%/entity/BulkMail_entity/entityfields/bindata/stateProcess.js</stateProcess>
<onValueChange>%aditoprj%/entity/BulkMail_entity/entityfields/bindata/onValueChange.js</onValueChange>
<onValueChangeTypes>
<element>MASK</element>
</onValueChangeTypes>
<onValidation>%aditoprj%/entity/BulkMail_entity/entityfields/bindata/onValidation.js</onValidation>
</entityField>
<entityFieldGroup>
......@@ -130,7 +137,9 @@
<entityField>
<name>content</name>
<title>Content</title>
<contentType>HTML</contentType>
<contentTypeProcess>%aditoprj%/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js</contentTypeProcess>
<state>EDITABLE</state>
<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>
......@@ -241,7 +250,7 @@
<entityField>
<name>preview</name>
<title>Preview</title>
<contentTypeProcess>%aditoprj%/entity/BulkMail_entity/entityfields/preview/contentTypeProcess.js</contentTypeProcess>
<contentType>HTML</contentType>
<valueProcess>%aditoprj%/entity/BulkMail_entity/entityfields/preview/valueProcess.js</valueProcess>
</entityField>
</entityFields>
......
import("system.logging");
import("DocumentTemplate_lib");
import("system.neon");
import("system.vars");
// note: could not use only the valueProcess from $field.content because then it refreshed $field.content just before save.
// --> only set in $field.content.valueProcess if $field.content is null and set it from here only if MASK triggered change
if(vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET)
{
[content, type] = DocumentTemplateUtils.getTemplateContent(vars.get("$field.DOCUMENTTEMPLATE_ID"), new FileUpload(vars.get("$local.value")));
vars.set("$context.currentTemplateType", type)
vars.set("$field.content", content)
}
......@@ -4,5 +4,5 @@ import("system.neon");
var state = neon.COMPONENTSTATE_EDITABLE;
if (vars.get("$field.DOCUMENTTEMPLATE_ID"))
state = neon.COMPONENTSTATE_READONLY;
state = neon.COMPONENTSTATE_INVISIBLE;
result.string(state);
\ No newline at end of file
import("system.neon");
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)
{
type = DocumentTemplate.types.fromMimeType(mimeType);
}
else
{
let template = BulkMailUtils.getBulkMailTemplate(vars.get("$field.BULKMAILID"), vars.get("$field.DOCUMENTTEMPLATE_ID"), false);
type = template.type;
}
*/
result.string(vars.get("$context.currentTemplateType") == DocumentTemplate.types.TXT
result.string(vars.get("$context.currentTemplateType") == DocumentTemplate.types.TXT// && vars.get("$sys.recordstate") != neon.OPERATINGSTATE_VIEW
? "LONG_TEXT"
: "HTML");
\ No newline at end of file
import("system.logging");
import("Bulkmail_lib");
import("system.text");
import("Employee_lib");
......@@ -14,5 +15,9 @@ if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET)
var contactId = EmployeeUtils.getCurrentContactId();
var preview = template.getReplacedContentByContactId(contactId, false, true);
result.string(preview);
if (vars.get("$context.currentTemplateType") == DocumentTemplate.types.TXT)
result.string(text.text2html(preview, false));
else
result.string(preview);
}
\ No newline at end of file
......@@ -3,7 +3,9 @@ import("system.vars");
import("system.neon");
import("DocumentTemplate_lib");
if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_VIEW && vars.get("$context.currentTemplateType") == DocumentTemplate.types.EML)
if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_VIEW &&
(vars.get("$context.currentTemplateType") == DocumentTemplate.types.EML
|| vars.get("$context.currentTemplateType") == DocumentTemplate.types.HTML)) // TODO: invisible for html as there are problems with images which are removed by the html-editor
{
result.string(neon.COMPONENTSTATE_INVISIBLE);
}
\ No newline at end of file
......@@ -6,19 +6,14 @@ import("system.db");
import("DocumentTemplate_lib");
import("Bulkmail_lib");
if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET)
if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET && vars.get("$this.value") == null)
{
var upload = new FileUpload(vars.get("$field.bindata"));
var template;
if (upload.bindata)
template = DocumentTemplate.fromUpload(upload);
else
template = BulkMailUtils.getBulkMailTemplate(vars.get("$field.BULKMAILID"), vars.get("$field.DOCUMENTTEMPLATE_ID"), false);
vars.set("$context.currentTemplateType", template.type);
var content = template.getReplacedContent({});
if (content)
result.string(content);
[content, type] = DocumentTemplateUtils.getTemplateContent(vars.get("$field.DOCUMENTTEMPLATE_ID"), new FileUpload(vars.get("$field.bindata")));
vars.set("$context.currentTemplateType", type);
result.string(content);
}
else if (!vars.get("$field.DOCUMENTTEMPLATE_ID"))
{
result.string("");
vars.set("$context.currentTemplateType", "");
}
\ No newline at end of file
......@@ -7,6 +7,13 @@ import("Entity_lib");
if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
{
// note: could not use only the valueProcess from $field.content because then it refreshed $field.content just before save.
// --> only set in $field.content.valueProcess if $field.content is null and set it from here only if MASK triggered change
[content, type] = DocumentTemplateUtils.getTemplateContent(vars.get("$local.value"), new FileUpload(vars.get("$field.bindata")));
vars.set("$context.currentTemplateType", type);
vars.set("$field.content", content)
// TODO: load subject without loadTemplate again... maybe return with getTemplateContent() above?
var templateId = vars.get("local.value");
var template = DocumentTemplate.loadTemplate(templateId, undefined, false);
if (template.type == DocumentTemplate.types.EML)
......
import("system.vars");
import("system.result");
import("DocumentTemplate_lib");
result.string(vars.get("$context.currentTemplateType") == DocumentTemplate.types.TXT
? "LONG_TEXT"
: "HTML");
\ No newline at end of file
......@@ -6,5 +6,7 @@ import("system.vars");
// --> only set in $field.Content.valueProcess if $field.Content is null and set it from here only if MASK triggered change
if((vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT || vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW))
{
vars.set("$field.Content", DocumentTemplateUtils.getTemplateContent(vars.get("$field.DOCUMENTTEMPLATEID"), new FileUpload(vars.get("$local.value"))))
[content, type] = DocumentTemplateUtils.getTemplateContent(vars.get("$field.DOCUMENTTEMPLATEID"), new FileUpload(vars.get("$local.value")));
vars.set("$context.currentTemplateType", type);
vars.set("$field.content", content)
}
......@@ -6,5 +6,7 @@ import("system.vars");
if((vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT || vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW) && vars.get("$this.value") == null)
{
result.string(DocumentTemplateUtils.getTemplateContent(vars.get("$field.DOCUMENTTEMPLATEID"), new FileUpload(vars.get("$field.BINDATA"))))
[content, type] = DocumentTemplateUtils.getTemplateContent(vars.get("$field.DOCUMENTTEMPLATEID"), new FileUpload(vars.get("$field.BINDATA")));
vars.set("$context.currentTemplateType", type);
result.string(content);
}
......@@ -69,7 +69,7 @@ DocumentTemplate.prototype.toString = function (pWithSubtemplates)
}
DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
{
{
// currently we support only txt and html as others would need special caution.
if (this.content != null && (this.type == DocumentTemplate.types.TXT || this.type == DocumentTemplate.types.HTML))
{
......@@ -88,7 +88,7 @@ DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
if (this.type == DocumentTemplate.types.HTML)
{
templates.concat(db.table(SqlCondition.begin()
templates = templates.concat(db.table(SqlCondition.begin()
.andPrepare("DOCUMENTTEMPLATE.KIND", $KeywordRegistry.documentTemplateType$textModular())
.andPrepare("DOCUMENTTEMPLATE.CLASSIFICATION", $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate())
.buildSql("select DOCUMENTTEMPLATEID, REPLACEMENTNAME from DOCUMENTTEMPLATE")));
......@@ -287,10 +287,27 @@ DocumentTemplate.prototype.getReplacedContent = function (pReplacements, pEncode
{
// if there exists a _subtemplatedContent we use it because then I assume that the replacements are already based on content + subtemplates
var content = this._getTemplatedContent(true);
switch (this.type)
{
case DocumentTemplate.types.EML:
let emlContent
if (pEmlOnlyBody)
{
// get only body and treat it as html (next case)
var email = Email.fromRFC(content);
content = util.encodeBase64String(email.body);
}
else
{
emlContent = util.decodeBase64String(content);
emlContent = TemplateHelper._replaceText(emlContent, pReplacements, TemplateHelper._getSpecialRegexp(this));
if (pEncoded)
emlContent = util.encodeBase64String(emlContent);
return emlContent;
}
case DocumentTemplate.types.HTML:
// replaces ä, ö, ü, ... with html escape signs
for (let i in pReplacements)
pReplacements[i] = text.text2html(pReplacements[i], false);
case DocumentTemplate.types.TXT:
......@@ -299,19 +316,6 @@ DocumentTemplate.prototype.getReplacedContent = function (pReplacements, pEncode
if (pEncoded)
encodedContent = util.encodeBase64String(encodedContent);
return encodedContent;
case DocumentTemplate.types.EML:
let emlContent
if (pEmlOnlyBody)
{
var email = Email.fromRFC(content)
emlContent = email.body
}
else
emlContent = util.decodeBase64String(content);
emlContent = TemplateHelper._replaceText(emlContent, pReplacements, TemplateHelper._getSpecialRegexp(this));
if (pEncoded)
emlContent = util.encodeBase64String(emlContent);
return emlContent;
case DocumentTemplate.types.ODT:
return TemplateHelper._getReplacedODT(this, pReplacements);
case DocumentTemplate.types.DOCX:
......@@ -479,7 +483,6 @@ TemplateHelper._getRequiredPlaceholders = function (pTemplate)
{
return foundPlaceholders.indexOf(pPlaceholder.placeholderName) != -1;
});
logging.log(JSON.stringify([placeholders], null, "\t"))
return placeholders;
}
......@@ -770,10 +773,11 @@ DocumentTemplateUtils.updateTemplateData = function (pTemplateId, pFileUpload, p
* @param {String} pTemplateId the id of the template
* @param {FileUpload} pFileUpload upload object
*
* @return {String} content or ""
* @return {String[]} [content, type] or ["", null]
*/
DocumentTemplateUtils.getTemplateContent = function (pTemplateId, pFileUpload)
{
logging.log(JSON.stringify([pTemplateId, pFileUpload.isFilled()], null, "\t"))
var type;
var bindata;
......@@ -798,12 +802,14 @@ DocumentTemplateUtils.getTemplateContent = function (pTemplateId, pFileUpload)
}
}
if (type == DocumentTemplate.types.HTML || type == DocumentTemplate.types.TXT)
logging.log("asd" + JSON.stringify([type], null, "\t"))
if (type == DocumentTemplate.types.HTML || type == DocumentTemplate.types.TXT || type == DocumentTemplate.types.EML)
{
return util.decodeBase64String(bindata);
return [util.decodeBase64String(bindata), type];
}
return "";
return ["", null];
}
/**
......
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