384b5832 by Michael Jones

Merge branch 'BF-11979' into 'master'

Bf 11979

See merge request !2
2 parents 3169a2e4 312f9bfe
...@@ -16,7 +16,9 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -16,7 +16,9 @@ along with this software (see the LICENSE.md file). If not, see
16 16
17 <extend-entity entity-name="EmailTemplate" package="moqui.basic.email"> 17 <extend-entity entity-name="EmailTemplate" package="moqui.basic.email">
18 <field name="grapesLocation" type="text-medium"/> 18 <field name="grapesLocation" type="text-medium"/>
19 <field name="grapesPublishedVersionName" type="text-short"/>
19 <field name="htmlLocation" type="text-medium"/> 20 <field name="htmlLocation" type="text-medium"/>
21 <field name="htmlPublishedVersionName" type="text-short"/>
20 </extend-entity> 22 </extend-entity>
21 <view-entity entity-name="ProductStoreEmailDetail" package="mantle.product.store"> 23 <view-entity entity-name="ProductStoreEmailDetail" package="mantle.product.store">
22 <member-entity entity-alias="PSE" entity-name="mantle.product.store.ProductStoreEmail"/> 24 <member-entity entity-alias="PSE" entity-name="mantle.product.store.ProductStoreEmail"/>
......
...@@ -17,11 +17,34 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -17,11 +17,34 @@ along with this software (see the LICENSE.md file). If not, see
17 17
18 <actions> 18 <actions>
19 <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/> 19 <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
20 <if condition="!emailTemplate"> 20 <if condition="!emailTemplate || !emailTemplate.htmlLocation">
21 <return error="true" message="Email Template not found"/> 21 <return error="true" message="Email Template not found"/>
22 </if> 22 </if>
23 <set field="dataPre" from="ec.resource.getLocationReference(emailTemplate.htmlLocation).getText(emailTemplate.htmlPublishedVersionName)"/>
24 <script><![CDATA[
25 String location = "template.ftl";
23 26
24 <set field="renderedText" from="ec.resource.template(emailTemplate.htmlLocation, 'ftl')"/> 27 freemarker.template.Template newTemplate;
28 Reader templateReader = null;
29
30 try {
31 templateReader = new StringReader(context.dataPre);
32 // Use the getFtlConfiguration method from ec.resource.templateRenderers.ftl
33 newTemplate = new freemarker.template.Template(location, templateReader, ec.resource.templateRenderers.ftl.getFtlConfiguration());
34 } catch (Exception e) {
35 throw new org.moqui.BaseArtifactException("Error while initializing template at " + location, e);
36 } finally {
37 if (templateReader != null) {
38 try { templateReader.close(); }
39 catch (Exception e) { logger.error("Error closing template reader", e); }
40 }
41 }
42 StringWriter sw = new StringWriter()
43 try {
44 newTemplate.createProcessingEnvironment(ec.contextStack, sw).process();
45 } catch (Exception e) { throw new org.moqui.BaseArtifactException("Error rendering template at " + location, e); }
46 context.renderedText = sw.toString();
47 ]]></script>
25 </actions> 48 </actions>
26 49
27 <widgets> 50 <widgets>
......
...@@ -21,6 +21,9 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -21,6 +21,9 @@ along with this software (see the LICENSE.md file). If not, see
21 <resource name="mjml"> 21 <resource name="mjml">
22 <method type="get"><service name="mjml.MjmlServices.load#GrapeJs"/></method> 22 <method type="get"><service name="mjml.MjmlServices.load#GrapeJs"/></method>
23 <method type="post"><service name="mjml.MjmlServices.store#GrapeJs"/></method> 23 <method type="post"><service name="mjml.MjmlServices.store#GrapeJs"/></method>
24 <resource name="afterMjmlStore">
25 <method type="get"><service name="mjml.MjmlServices.get#AfterMjmlStore"/></method>
26 </resource>
24 </resource> 27 </resource>
25 28
26 </resource> 29 </resource>
......