b0231d7f by acetousk

Save mjml rendered html and render the html with ftl in the current context of t…

…he parameters passed in through the service.
1 parent 88f3e150
......@@ -224,7 +224,7 @@ along with this software (see the LICENSE.md file). If not, see
// we have to properly update the body before the store and extract the
// project data from the response result.
onStore: data => {
return { id: window.resourceId, data }
return { id: window.resourceId, data, html:window.editor.runCommand('mjml-code-to-html')?.html }
},
onLoad: result => {
if (result.resourceId !== null) {
......
......@@ -39,203 +39,13 @@ along with this software (see the LICENSE.md file). If not, see
}
}
</script>
<set field="locationText" from="ec.resource.getLocationText(actualDbResourcePath)"/>
<set field="htmlDbResourcePath" from="actualDbResourcePath - '.json' + '.html'"/>
<set field="renderedText" from="ec.resource.template(htmlDbResourcePath, 'ftl')"/>
<log level="warn" message="GrapesJsEmail context.toString(): ${context.toString()}"/>
</actions>
<widgets>
<render-mode><text type="html"><![CDATA[
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title>
</title>
<!--[if !mso]><!-->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
#outlook a {
padding:0;
}
body {
margin:0;
padding:0;
-webkit-text-size-adjust:100%;
-ms-text-size-adjust:100%;
}
table, td {
border-collapse:collapse;
mso-table-lspace:0pt;
mso-table-rspace:0pt;
}
img {
border:0;
height:auto;
line-height:100%;
outline:none;
text-decoration:none;
-ms-interpolation-mode:bicubic;
}
p {
display:block;
margin:13px 0;
}
</style>
<!--[if mso]>
<noscript>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
</noscript>
<![endif]-->
<!--[if lte mso 11]>
<style type="text/css">
.mj-outlook-group-fix { width:100% !important; }
</style>
<![endif]-->
<!--[if !mso]><!-->
<link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css">
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);
</style>
<!--<![endif]-->
<style type="text/css">
@media only screen and (min-width:480px) {
.mj-column-per-100 {
width:100% !important;
max-width: 100%;
}
}
</style>
<style media="screen and (min-width:480px)">
.moz-text-html .mj-column-per-100 {
width:100% !important;
max-width: 100%;
}
</style>
<style type="text/css">
@media only screen and (max-width:479px) {
table.mj-full-width-mobile {
width: 100% !important;
}
td.mj-full-width-mobile {
width: auto !important;
}
}
</style>
<style type="text/css">
</style>
</head>
<body style="word-spacing:normal;">
<div style>
<!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" class="" role="presentation" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
<div style="margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
<tbody>
<tr>
<td style="border-bottom:1px solid #aaaaaa;border-left:1px solid #aaaaaa;border-right:1px solid #aaaaaa;direction:ltr;font-size:0px;padding:20px;text-align:center;">
<!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:558px;" ><![endif]-->
<div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
<tbody>
<tr>
<td style="vertical-align:top;padding:0px;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
<tbody>
<tr>
<td align="center" style="font-size:0px;padding:0px;padding-bottom:15px;word-break:break-word;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
<tbody>
<tr>
<td style="width:289px;">
<img alt="Uniquely Me Logo" src="${baseLinkUrl}/umstatic/images/um-logo-large.png" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;font-size:13px;" width="289" height="auto">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;padding-top:11px;padding-right:24px;padding-bottom:11px;padding-left:24px;word-break:break-word;">
<div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:16px;line-height:1;text-align:left;color:#000000;">
<p data-gjs-type="default" draggable="true" id="i6jmu" style="line-height:1.2;">
<span data-gjs-type="default" draggable="true" style="font-size:12pt;font-variant:normal;white-space:pre-wrap;"><span data-gjs-type="default" draggable="true" style="font-family:Calibri,sans-serif;"><span data-gjs-type="default" draggable="true" style="color:#000000;"><span data-gjs-type="default" draggable="true" style="font-weight:400;"><span data-gjs-type="default" draggable="true" style="font-style:normal;"><span data-gjs-type="text" draggable="true" style="text-decoration:none;">Dear ${firstName!},<br>
Thank you for choosing UniquelyMe. We&#39;re excited to support you on your journey to better menopause management. Below are the details of your recent order.<br>
Order Number: ${orderId}<br>
Date: ${entryDate}<br>
Order Summary:<br>
${itemDescription} x ${quantity}<br>
Total: $${grandTotal}<br>
Payment Method: ${paymentMethodDescription}<br>
Billing Information:<br>
Name: ${firstName} ${lastName}<br>
Address: ${billingAddress}<br>
Shipping Information:<br>
Name: ${firstName} ${lastName}<br>
Address: ${shippingAddress}<br>
Estimated Delivery: ${estimatedDeliveryDate}<br>
Important: To access your test results and personalized treatment plan, creating an account with UniquelyMe is essential. This enables us to provide you with a secure and customized experience. If you haven&#39;t already, please set up your account here.<br>
Need Assistance? Our customer care team is here to help you every step of the way. If you have any questions about your order, or need assistance with your account setup, please feel free to contact us at support@uniquely.me.<br>
Thank you for trusting us with your health and wellbeing. We&#39;re committed to providing you with the best care and support during your menopause journey.<br>
Warm regards,<br>
The UniquelyMe Team</span></span></span></span></span></span>
</p>
</div>
</td>
</tr>
<tr>
<td align="center" style="font-size:0px;padding:0px;padding-top:11px;padding-right:0px;padding-bottom:11px;padding-left:0px;word-break:break-word;">
<p style="border-top:solid 4px #000000;font-size:1px;margin:0px auto;width:100%;">
</p>
<!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-top:solid 4px #000000;font-size:1px;margin:0px auto;width:558px;" role="presentation" width="558px" ><tr><td style="height:0;line-height:0;"> &nbsp;
</td></tr></table><![endif]-->
</td>
</tr>
<tr>
<td align="center" style="font-size:0px;padding:0px;padding-top:6px;padding-bottom:6px;word-break:break-word;">
<div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:10px;line-height:14px;text-align:center;color:#45495d;">
<p draggable="true" id="ilpqr">
<span draggable="true" id="iayqh" style="font-size:12px;"><span draggable="true" id="il87k" style="color:#000000;">If you didn't request this email, please contact your administrator.</span></span>
</p>
<p draggable="true" id="ippb7">
<span draggable="true" id="ibb4j" style="color:#000000;"><span draggable="true" id="ihaqs" style="font-size:12px;">@${currentYear} All Rights Reserved</span></span>
</p>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<!--[if mso | IE]></td></tr></table><![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
<!--[if mso | IE]></td></tr></table><![endif]-->
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
<tbody>
<tr>
<td style="width:1px;">
<img alt="Email" src="${baseLinkUrl}/email/${emailMessageId}.png" style="border:0;display:block;outline:none;text-decoration:none;height:1;width:100%;font-size:13px;" title="Email" width="1" height="1">
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
]]></text></render-mode>
<render-mode><text type="html"><![CDATA[${renderedText}]]></text></render-mode>
</widgets>
</screen>
......
......@@ -28,6 +28,15 @@ along with this software (see the LICENSE.md file). If not, see
<if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
<!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
<!-- <log level="warn" message="load context.toString() ${context.toString()}"/>-->
<if condition="emailTemplateId">
<entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
<if condition="!resourceId"><set field="resourceId" from="emailTemplate?.resourceId"/></if>
<if condition="resourceId != emailTemplate?.resourceId">
<!-- This should almost never happen, but if it does it basically creates a resource leak for the previously used resource -->
<log message="Changing resource id from ${resourceId} to ${emailTemplate?.resourceId} for email template ${emailTemplateId}"/>
<service-call name="update#moqui.basic.email.EmailTemplate" in-map="[emailTemplateId:emailTemplateId,resourceId:resourceId]"/>
</if>
</if>
<if condition="!resourceId">
<then>
......@@ -88,23 +97,18 @@ along with this software (see the LICENSE.md file). If not, see
<description>Create MJML</description>
<in-parameters>
<parameter name="resourceId"/>
<parameter name="data"></parameter>
<parameter name="data"/>
<parameter name="html" allow-html="any"/>
</in-parameters>
<out-parameters>
<parameter name="resourceId"/>
</out-parameters>
<actions>
<!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
<if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
<!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
<!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>-->
<set field="data" from="groovy.json.JsonOutput.toJson(new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data)"/>
<!-- <log level="warn" message="store#GrapeJs data ${data}"/>-->
<!-- <log level="warn" message="store context.toString() ${context.toString()}"/>-->
<if condition="!resourceId">
<then>
<!-- <log level="warn" message="resourceId is null"/>-->
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
<service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
<service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId+'.json']" out-map="dbResource"/>
......@@ -112,25 +116,23 @@ along with this software (see the LICENSE.md file). If not, see
<service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/>
<service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/>
<set field="resourceId" from="dbResource.resourceId"/>
<set field="htmlFile" from="grapesJsResource.makeFile(resourceId.toString()+'.html')"/>
<script><![CDATA[htmlFile.putText(html)]]></script>
</then>
<else>
<!-- <log level="warn" message="resourceId is ${resourceId}"/>-->
<entity-find-one entity-name="moqui.resource.DbResource" value-field="dbResource" auto-field-map="[resourceId:resourceId]"/>
<!-- <log level="warn" message="dbResource ${dbResource}"/>-->
<if condition="!dbResource">
<return error="true" message="Resource not found"/>
</if>
<set field="actualDbResourcePath" from="null"/>
<set field="dbResourcePath" from="dbResource.filename"/>
<set field="lastDbResource" from="dbResource"/>
<!-- <log level="warn" message="lastDbResource ${lastDbResource}"/>-->
<script>
while (actualDbResourcePath == null) {
// ec.logger.warn('dbResourcePath: '+dbResourcePath)
if (lastDbResource.parentResourceId == null) {
dbResourcePath = 'dbresource://'+dbResourcePath
actualDbResourcePath = dbResourcePath
// ec.logger.warn('actualDbResourcePath: '+actualDbResourcePath)
} else {
lastDbResource = ec.entity.fastFindOne("moqui.resource.DbResource", true, false, lastDbResource.parentResourceId)
dbResourcePath = lastDbResource.filename+'/'+dbResourcePath
......@@ -142,6 +144,10 @@ along with this software (see the LICENSE.md file). If not, see
putDbResource.putText(data)
</script>
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
<set field="htmlFile" from="grapesJsResource.findChildFile(resourceId.toString()+'.html') ?: grapesJsResource.makeFile(resourceId.toString()+'.html')"/>
<script><![CDATA[htmlFile.putText(html)]]></script>
</else>
</if>
</actions>
......