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 ...@@ -224,7 +224,7 @@ along with this software (see the LICENSE.md file). If not, see
224 // we have to properly update the body before the store and extract the 224 // we have to properly update the body before the store and extract the
225 // project data from the response result. 225 // project data from the response result.
226 onStore: data => { 226 onStore: data => {
227 return { id: window.resourceId, data } 227 return { id: window.resourceId, data, html:window.editor.runCommand('mjml-code-to-html')?.html }
228 }, 228 },
229 onLoad: result => { 229 onLoad: result => {
230 if (result.resourceId !== null) { 230 if (result.resourceId !== null) {
......
...@@ -39,203 +39,13 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -39,203 +39,13 @@ along with this software (see the LICENSE.md file). If not, see
39 } 39 }
40 } 40 }
41 </script> 41 </script>
42 <set field="locationText" from="ec.resource.getLocationText(actualDbResourcePath)"/> 42 <set field="htmlDbResourcePath" from="actualDbResourcePath - '.json' + '.html'"/>
43 <set field="renderedText" from="ec.resource.template(htmlDbResourcePath, 'ftl')"/>
43 44
44 <log level="warn" message="GrapesJsEmail context.toString(): ${context.toString()}"/> 45 <log level="warn" message="GrapesJsEmail context.toString(): ${context.toString()}"/>
45 </actions> 46 </actions>
46 47
47 <widgets> 48 <widgets>
48 <render-mode><text type="html"><![CDATA[ 49 <render-mode><text type="html"><![CDATA[${renderedText}]]></text></render-mode>
49 <!doctype html>
50 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
51 <head>
52 <title>
53 </title>
54 <!--[if !mso]><!-->
55 <meta http-equiv="X-UA-Compatible" content="IE=edge">
56 <!--<![endif]-->
57 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
58 <meta name="viewport" content="width=device-width, initial-scale=1">
59 <style type="text/css">
60 #outlook a {
61 padding:0;
62 }
63 body {
64 margin:0;
65 padding:0;
66 -webkit-text-size-adjust:100%;
67 -ms-text-size-adjust:100%;
68 }
69 table, td {
70 border-collapse:collapse;
71 mso-table-lspace:0pt;
72 mso-table-rspace:0pt;
73 }
74 img {
75 border:0;
76 height:auto;
77 line-height:100%;
78 outline:none;
79 text-decoration:none;
80 -ms-interpolation-mode:bicubic;
81 }
82 p {
83 display:block;
84 margin:13px 0;
85 }
86 </style>
87 <!--[if mso]>
88 <noscript>
89 <xml>
90 <o:OfficeDocumentSettings>
91 <o:AllowPNG/>
92 <o:PixelsPerInch>96</o:PixelsPerInch>
93 </o:OfficeDocumentSettings>
94 </xml>
95 </noscript>
96 <![endif]-->
97 <!--[if lte mso 11]>
98 <style type="text/css">
99 .mj-outlook-group-fix { width:100% !important; }
100 </style>
101 <![endif]-->
102 <!--[if !mso]><!-->
103 <link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css">
104 <style type="text/css">
105 @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);
106 </style>
107 <!--<![endif]-->
108 <style type="text/css">
109 @media only screen and (min-width:480px) {
110 .mj-column-per-100 {
111 width:100% !important;
112 max-width: 100%;
113 }
114 }
115 </style>
116 <style media="screen and (min-width:480px)">
117 .moz-text-html .mj-column-per-100 {
118 width:100% !important;
119 max-width: 100%;
120 }
121 </style>
122 <style type="text/css">
123 @media only screen and (max-width:479px) {
124 table.mj-full-width-mobile {
125 width: 100% !important;
126 }
127 td.mj-full-width-mobile {
128 width: auto !important;
129 }
130 }
131 </style>
132 <style type="text/css">
133 </style>
134 </head>
135 <body style="word-spacing:normal;">
136 <div style>
137 <!--[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]-->
138 <div style="margin:0px auto;max-width:600px;">
139 <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
140 <tbody>
141 <tr>
142 <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;">
143 <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:558px;" ><![endif]-->
144 <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%;">
145 <table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
146 <tbody>
147 <tr>
148 <td style="vertical-align:top;padding:0px;">
149 <table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
150 <tbody>
151 <tr>
152 <td align="center" style="font-size:0px;padding:0px;padding-bottom:15px;word-break:break-word;">
153 <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
154 <tbody>
155 <tr>
156 <td style="width:289px;">
157 <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">
158 </td>
159 </tr>
160 </tbody>
161 </table>
162 </td>
163 </tr>
164 <tr>
165 <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;">
166 <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:16px;line-height:1;text-align:left;color:#000000;">
167 <p data-gjs-type="default" draggable="true" id="i6jmu" style="line-height:1.2;">
168 <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>
169 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>
170 Order Number: ${orderId}<br>
171 Date: ${entryDate}<br>
172 Order Summary:<br>
173 ${itemDescription} x ${quantity}<br>
174 Total: $${grandTotal}<br>
175 Payment Method: ${paymentMethodDescription}<br>
176 Billing Information:<br>
177 Name: ${firstName} ${lastName}<br>
178 Address: ${billingAddress}<br>
179 Shipping Information:<br>
180 Name: ${firstName} ${lastName}<br>
181 Address: ${shippingAddress}<br>
182 Estimated Delivery: ${estimatedDeliveryDate}<br>
183 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>
184 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>
185 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>
186 Warm regards,<br>
187 The UniquelyMe Team</span></span></span></span></span></span>
188 </p>
189 </div>
190 </td>
191 </tr>
192 <tr>
193 <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;">
194 <p style="border-top:solid 4px #000000;font-size:1px;margin:0px auto;width:100%;">
195 </p>
196 <!--[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;
197 </td></tr></table><![endif]-->
198 </td>
199 </tr>
200 <tr>
201 <td align="center" style="font-size:0px;padding:0px;padding-top:6px;padding-bottom:6px;word-break:break-word;">
202 <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:10px;line-height:14px;text-align:center;color:#45495d;">
203 <p draggable="true" id="ilpqr">
204 <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>
205 </p>
206 <p draggable="true" id="ippb7">
207 <span draggable="true" id="ibb4j" style="color:#000000;"><span draggable="true" id="ihaqs" style="font-size:12px;">@${currentYear} All Rights Reserved</span></span>
208 </p>
209 </div>
210 </td>
211 </tr>
212 </tbody>
213 </table>
214 </td>
215 </tr>
216 </tbody>
217 </table>
218 </div>
219 <!--[if mso | IE]></td></tr></table><![endif]-->
220 </td>
221 </tr>
222 </tbody>
223 </table>
224 </div>
225 <!--[if mso | IE]></td></tr></table><![endif]-->
226 <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;">
227 <tbody>
228 <tr>
229 <td style="width:1px;">
230 <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">
231 </td>
232 </tr>
233 </tbody>
234 </table>
235 </div>
236 </body>
237 </html>
238
239 ]]></text></render-mode>
240 </widgets> 50 </widgets>
241 </screen> 51 </screen>
......
...@@ -28,6 +28,15 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -28,6 +28,15 @@ along with this software (see the LICENSE.md file). If not, see
28 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if> 28 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
29 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>--> 29 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
30 <!-- <log level="warn" message="load context.toString() ${context.toString()}"/>--> 30 <!-- <log level="warn" message="load context.toString() ${context.toString()}"/>-->
31 <if condition="emailTemplateId">
32 <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
33 <if condition="!resourceId"><set field="resourceId" from="emailTemplate?.resourceId"/></if>
34 <if condition="resourceId != emailTemplate?.resourceId">
35 <!-- This should almost never happen, but if it does it basically creates a resource leak for the previously used resource -->
36 <log message="Changing resource id from ${resourceId} to ${emailTemplate?.resourceId} for email template ${emailTemplateId}"/>
37 <service-call name="update#moqui.basic.email.EmailTemplate" in-map="[emailTemplateId:emailTemplateId,resourceId:resourceId]"/>
38 </if>
39 </if>
31 40
32 <if condition="!resourceId"> 41 <if condition="!resourceId">
33 <then> 42 <then>
...@@ -88,23 +97,18 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -88,23 +97,18 @@ along with this software (see the LICENSE.md file). If not, see
88 <description>Create MJML</description> 97 <description>Create MJML</description>
89 <in-parameters> 98 <in-parameters>
90 <parameter name="resourceId"/> 99 <parameter name="resourceId"/>
91 <parameter name="data"></parameter> 100 <parameter name="data"/>
101 <parameter name="html" allow-html="any"/>
92 </in-parameters> 102 </in-parameters>
93 <out-parameters> 103 <out-parameters>
94 <parameter name="resourceId"/> 104 <parameter name="resourceId"/>
95 </out-parameters> 105 </out-parameters>
96 <actions> 106 <actions>
97 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
98 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if> 107 <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
99 <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
100 <!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>-->
101 <set field="data" from="groovy.json.JsonOutput.toJson(new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data)"/> 108 <set field="data" from="groovy.json.JsonOutput.toJson(new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data)"/>
102 <!-- <log level="warn" message="store#GrapeJs data ${data}"/>-->
103 109
104 <!-- <log level="warn" message="store context.toString() ${context.toString()}"/>-->
105 <if condition="!resourceId"> 110 <if condition="!resourceId">
106 <then> 111 <then>
107 <!-- <log level="warn" message="resourceId is null"/>-->
108 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/> 112 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
109 <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/> 113 <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
110 <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId+'.json']" out-map="dbResource"/> 114 <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 ...@@ -112,25 +116,23 @@ along with this software (see the LICENSE.md file). If not, see
112 <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/> 116 <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/>
113 <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/> 117 <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/>
114 <set field="resourceId" from="dbResource.resourceId"/> 118 <set field="resourceId" from="dbResource.resourceId"/>
119
120 <set field="htmlFile" from="grapesJsResource.makeFile(resourceId.toString()+'.html')"/>
121 <script><![CDATA[htmlFile.putText(html)]]></script>
115 </then> 122 </then>
116 <else> 123 <else>
117 <!-- <log level="warn" message="resourceId is ${resourceId}"/>-->
118 <entity-find-one entity-name="moqui.resource.DbResource" value-field="dbResource" auto-field-map="[resourceId:resourceId]"/> 124 <entity-find-one entity-name="moqui.resource.DbResource" value-field="dbResource" auto-field-map="[resourceId:resourceId]"/>
119 <!-- <log level="warn" message="dbResource ${dbResource}"/>-->
120 <if condition="!dbResource"> 125 <if condition="!dbResource">
121 <return error="true" message="Resource not found"/> 126 <return error="true" message="Resource not found"/>
122 </if> 127 </if>
123 <set field="actualDbResourcePath" from="null"/> 128 <set field="actualDbResourcePath" from="null"/>
124 <set field="dbResourcePath" from="dbResource.filename"/> 129 <set field="dbResourcePath" from="dbResource.filename"/>
125 <set field="lastDbResource" from="dbResource"/> 130 <set field="lastDbResource" from="dbResource"/>
126 <!-- <log level="warn" message="lastDbResource ${lastDbResource}"/>-->
127 <script> 131 <script>
128 while (actualDbResourcePath == null) { 132 while (actualDbResourcePath == null) {
129 // ec.logger.warn('dbResourcePath: '+dbResourcePath)
130 if (lastDbResource.parentResourceId == null) { 133 if (lastDbResource.parentResourceId == null) {
131 dbResourcePath = 'dbresource://'+dbResourcePath 134 dbResourcePath = 'dbresource://'+dbResourcePath
132 actualDbResourcePath = dbResourcePath 135 actualDbResourcePath = dbResourcePath
133 // ec.logger.warn('actualDbResourcePath: '+actualDbResourcePath)
134 } else { 136 } else {
135 lastDbResource = ec.entity.fastFindOne("moqui.resource.DbResource", true, false, lastDbResource.parentResourceId) 137 lastDbResource = ec.entity.fastFindOne("moqui.resource.DbResource", true, false, lastDbResource.parentResourceId)
136 dbResourcePath = lastDbResource.filename+'/'+dbResourcePath 138 dbResourcePath = lastDbResource.filename+'/'+dbResourcePath
...@@ -142,6 +144,10 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -142,6 +144,10 @@ along with this software (see the LICENSE.md file). If not, see
142 putDbResource.putText(data) 144 putDbResource.putText(data)
143 </script> 145 </script>
144 146
147 <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
148 <set field="htmlFile" from="grapesJsResource.findChildFile(resourceId.toString()+'.html') ?: grapesJsResource.makeFile(resourceId.toString()+'.html')"/>
149 <script><![CDATA[htmlFile.putText(html)]]></script>
150
145 </else> 151 </else>
146 </if> 152 </if>
147 </actions> 153 </actions>
......