GrapesJsEmail.xml 2.55 KB
<?xml version="1.0" encoding="UTF-8"?>
<!--
This software is in the public domain under CC0 1.0 Universal plus a
Grant of Patent License.

To the extent possible under law, the author(s) have dedicated all
copyright and related and neighboring rights to this software to the
public domain worldwide. This software is distributed without any
warranty.

You should have received a copy of the CC0 Public Domain Dedication
along with this software (see the LICENSE.md file). If not, see
<http://creativecommons.org/publicdomain/zero/1.0/>.
-->

<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/xml-screen-3.xsd">

    <actions>
        <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
        <entity-find-one entity-name="moqui.resource.DbResource" value-field="dbResource" auto-field-map="[resourceId:emailTemplate.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
                }
            }
        </script>
        <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[${renderedText}]]></text></render-mode>
    </widgets>
</screen>