<commit_before>{% macro renderAvailableVariablesWidget(entityName, dependentFieldId) %}
    <script type="text/javascript">
        $(function() {
            'use strict';

            var availableVariables = {{ render(path('oro_api_get_emailtemplate_available_variables', { 'entityName': entityName }))}};

            new Oro.Email.VariablesUpdater.View({
                el:         $('#oro-email-available-variables'),
                template:   $('#available-variables-lists-template'),
                target:     $('#{{ dependentFieldId }}'),
                model:      new Oro.Email.VariablesUpdater.Variable(availableVariables)
            });
        })
    </script>

    <script type="text/template" id="available-variables-lists-template">
        <% if (userVars.length > 0) { %>
        <div>
            <h4>{{ 'Logged in user:'|trans }}</h4>
            <ul class="nav nav-list">
                <% _.each(userVars, function(variable, i) { %>
                    <li><a href="javascript:void(0);">{% verbatim %}{{ user.<%= variable %> }}{% endverbatim %}</a></li>
                <% }); %>
            </ul>
        </div>
        <% } %>
        <% if (entityVars.length > 0) { %>
        <div>
            <h4>{{ 'Related entity:'|trans }}</h4>
            <ul class="nav nav-list">
                <% _.each(entityVars, function(variable, i) { %>
                    <li><a href="javascript:void(0);">{% verbatim %}{{ entity.<%= variable %> }}{% endverbatim %}</a></li>
                <% }); %>
            </ul>
        </div>
        <% } %>
    </script>

    <div class="well well-small span5" id="oro-email-available-variables"></div>
{% endmacro %}

{% macro renderPreviewDialog(formName, title) %}
    <script type="text/javascript">
        $(function () {
            var showEmailPreviewDialog = function (el) {
                var iframe = $('<iframe />',
                        {
                            name: "preview-frame",
                            id: "preview-frame",
                            'class': "scrollable-container",
                            frameborder: 0,
                            marginwidth: 0,
                            marginheight: 0,
                            allowfullscreen: true,
                            width: "100%"
                        });

                $('body').append(iframe);
                var form = $('#{{ formName }}');
                var formAction = form.attr('action');

                form.bindFirst('submit', function(e) {
                    // prevent hash navigation form processing
                    new Oro.widget.DialogView({
                        el: $('<div id="inject-content"></div>'),
                        url: false,
                        dialogOptions: {
                            allowMaximize: true,
                            allowMinimize: true,
                            dblclick: 'maximize',
                            maximizedHeightDecreaseBy: 'minimize-bar',
                            minWidth: 600,
                            minHeight: 400,
                            title: $(el).attr('title')
                        }
                    }).render();

                    $('#inject-content').append(iframe);
                    form.attr('target', 'preview-frame');
                    form.attr('action', $(el).attr('href'));
                    e.stopImmediatePropagation();
                });

                iframe.load(function() {
                    $(this).show();
                    form.attr('action', formAction);
                    form.removeAttr('target');
                });

                form.submit();
            };

            $('.dialog-form-renderer').click(function (e) {
                showEmailPreviewDialog(this);
                e.preventDefault();
            });
        });
    </script>
{% endmacro %}

{#
    Render email address name, owner name or a link to owner view page can be rendered depends on given parameters
    Parameters:
        emailAddress - email address entity Oro\Bundle\EmailBundle\Entity\EmailAddress
        emailAddressName - a string contains an email address. It is used if the email address has no owner
        nameFormat - a format string used to render the owner full name
        noLink - determines whether the rendering of a link to the owner view page is forbidden or not. Default value is false
#}
{% macro email_address(emailAddress, emailAddressName, nameFormat, noLink) -%}
    {% macro email_address_text(emailAddress, nameFormat) -%}
        {{ emailAddress.owner.fullname(nameFormat)|default('N/A')|raw }}
    {%- endmacro -%}
    {% macro email_address_link(emailAddress, nameFormat) -%}
        {#- TODO: we need EntityConfig to get view url for an entity -#}
        <a href="{{ path(emailAddress.owner.class|split('\\')|first|lower ~ '_' ~ emailAddress.owner.class|split('\\')|last|lower ~ '_view', {id:emailAddress.owner.id}) }}">{{ _self.email_address_text(emailAddress, nameFormat) }}</a>
    {%- endmacro -%}
    {% if emailAddress.owner is null -%}
        {{ emailAddressName|raw }}
    {%- else -%}
        {% if noLink|default(false) -%}
            {{ _self.email_address_text(emailAddress, nameFormat)|raw }}
        {%- else -%}
            {{ _self.email_address_link(emailAddress, nameFormat)|raw }}
        {%- endif %}
    {%- endif %}
{%- endmacro %}

{#
    Render the given email recipients
    Parameters:
        recipients - an array of Oro\Bundle\EmailBundle\Entity\EmailRecipients
        nameFormat - a format string used to render the owner full name
        noLink - determines whether the rendering of a link to the owner view page is forbidden or not. Default value is false
#}
{% macro recipient_email_addresses(recipients, nameFormat, noLink) -%}
    {% set addreses = {} -%}
    {% for recipient in recipients -%}
        {{ _self.email_address(recipient.emailAddress, recipient.name, nameFormat, noLink) }}
        {%- if not loop.last %}; {% endif %}
    {%- endfor %}
{%- endmacro %}

{#
    Render the given email attachments
    Parameters:
        attachments - an array of Oro\Bundle\EmailBundle\Entity\EmailAttachment
#}
{% macro attachments(attachments) -%}
    {% macro attachment_row_data(values) -%}
        <ul class="inline">
            {%- for val in values -%}
            <li>
                <a class="no-hash" href="{{ path('oro_email_attachment', {id:val.id}) }}">
                    <span class="label label-info">{{ val.fileName }}</span>
                </a>
            </li>
            {%- endfor -%}
        </ul>
    {%- endmacro -%}
    {{ _self.attachment_row_data(attachments)|raw }}
{%- endmacro %}

{#
    Render email body
    Parameters:
        emailBody - email body entity Oro\Bundle\EmailBundle\Entity\EmailBody
        cssClass - used to specify an additional CSS class for email body container HTML element
#}
{% macro body(emailBody, cssClass) -%}
    {% if emailBody.bodyIsText -%}
        <pre class="email-body{% if cssClass is defined %} {{ cssClass }}{% endif %}">{{ emailBody.content }}</pre>
    {%- else -%}
        <iframe class="email-body{% if cssClass is defined %} {{ cssClass }}{% endif %}" src="{{ path('oro_email_body', {id:emailBody.id}) }}"></iframe>
    {%- endif %}
{%- endmacro %}
<commit_msg>BAP-1230: Email Templates   - fix<commit_after>{% macro renderAvailableVariablesWidget(entityName, dependentFieldId) %}
    <script type="text/javascript">
        $(function() {
            'use strict';

            var availableVariables = {{ render(path('oro_api_get_emailtemplate_available_variables', { 'entityName': entityName }))}};

            new Oro.Email.VariablesUpdater.View({
                el:         $('#oro-email-available-variables'),
                template:   $('#available-variables-lists-template'),
                target:     $('#{{ dependentFieldId }}'),
                model:      new Oro.Email.VariablesUpdater.Variable(availableVariables)
            });
        })
    </script>

    <script type="text/template" id="available-variables-lists-template">
        <% if (userVars.length > 0) { %>
        <div>
            <h4>{{ 'Logged in user:'|trans }}</h4>
            <ul class="nav nav-list">
                <% _.each(userVars, function(variable, i) { %>
                    <li><a href="javascript:void(0);">{% verbatim %}{{ user.<%= variable %> }}{% endverbatim %}</a></li>
                <% }); %>
            </ul>
        </div>
        <% } %>
        <% if (entityVars.length > 0) { %>
        <div>
            <h4>{{ 'Related entity:'|trans }}</h4>
            <ul class="nav nav-list">
                <% _.each(entityVars, function(variable, i) { %>
                    <li><a href="javascript:void(0);">{% verbatim %}{{ entity.<%= variable %> }}{% endverbatim %}</a></li>
                <% }); %>
            </ul>
        </div>
        <% } %>
    </script>

    <div class="well well-small span5" id="oro-email-available-variables"></div>
{% endmacro %}

{% macro renderPreviewDialog(formName, title) %}
    <script type="text/javascript">
        $(function () {
            var showEmailPreviewDialog = function (el) {
                var iframe = $('<iframe />',
                        {
                            name: "preview-frame",
                            id: "preview-frame",
                            'class': "scrollable-container",
                            frameborder: 0,
                            marginwidth: 0,
                            marginheight: 0,
                            allowfullscreen: true,
                            width: "100%"
                        });

                var form = $('#{{ formName }}');
                var formAction = form.attr('action');

                form.bindFirst('submit', function(e) {
                    // prevent hash navigation form processing
                    new Oro.widget.DialogView({
                        el: $('<div id="inject-content"></div>'),
                        //el: iframe,
                        url: false,
                        dialogOptions: {
                            allowMaximize: true,
                            allowMinimize: true,
                            dblclick: 'maximize',
                            maximizedHeightDecreaseBy: 'minimize-bar',
                            minWidth: 600,
                            minHeight: 400,
                            title: $(el).attr('title')
                        }
                    }).render();

                    $('#inject-content').append(iframe);
                    form.attr('target', 'preview-frame');
                    form.attr('action', $(el).attr('href'));
                    e.stopImmediatePropagation();
                });

                iframe.load(function() {
                    $(this).show();
                    form.attr('action', formAction);
                    form.removeAttr('target');
                });

                form.submit();
            };

            $('.dialog-form-renderer').click(function (e) {
                showEmailPreviewDialog(this);
                e.preventDefault();
            });
        });
    </script>
{% endmacro %}

{#
    Render email address name, owner name or a link to owner view page can be rendered depends on given parameters
    Parameters:
        emailAddress - email address entity Oro\Bundle\EmailBundle\Entity\EmailAddress
        emailAddressName - a string contains an email address. It is used if the email address has no owner
        nameFormat - a format string used to render the owner full name
        noLink - determines whether the rendering of a link to the owner view page is forbidden or not. Default value is false
#}
{% macro email_address(emailAddress, emailAddressName, nameFormat, noLink) -%}
    {% macro email_address_text(emailAddress, nameFormat) -%}
        {{ emailAddress.owner.fullname(nameFormat)|default('N/A')|raw }}
    {%- endmacro -%}
    {% macro email_address_link(emailAddress, nameFormat) -%}
        {#- TODO: we need EntityConfig to get view url for an entity -#}
        <a href="{{ path(emailAddress.owner.class|split('\\')|first|lower ~ '_' ~ emailAddress.owner.class|split('\\')|last|lower ~ '_view', {id:emailAddress.owner.id}) }}">{{ _self.email_address_text(emailAddress, nameFormat) }}</a>
    {%- endmacro -%}
    {% if emailAddress.owner is null -%}
        {{ emailAddressName|raw }}
    {%- else -%}
        {% if noLink|default(false) -%}
            {{ _self.email_address_text(emailAddress, nameFormat)|raw }}
        {%- else -%}
            {{ _self.email_address_link(emailAddress, nameFormat)|raw }}
        {%- endif %}
    {%- endif %}
{%- endmacro %}

{#
    Render the given email recipients
    Parameters:
        recipients - an array of Oro\Bundle\EmailBundle\Entity\EmailRecipients
        nameFormat - a format string used to render the owner full name
        noLink - determines whether the rendering of a link to the owner view page is forbidden or not. Default value is false
#}
{% macro recipient_email_addresses(recipients, nameFormat, noLink) -%}
    {% set addreses = {} -%}
    {% for recipient in recipients -%}
        {{ _self.email_address(recipient.emailAddress, recipient.name, nameFormat, noLink) }}
        {%- if not loop.last %}; {% endif %}
    {%- endfor %}
{%- endmacro %}

{#
    Render the given email attachments
    Parameters:
        attachments - an array of Oro\Bundle\EmailBundle\Entity\EmailAttachment
#}
{% macro attachments(attachments) -%}
    {% macro attachment_row_data(values) -%}
        <ul class="inline">
            {%- for val in values -%}
            <li>
                <a class="no-hash" href="{{ path('oro_email_attachment', {id:val.id}) }}">
                    <span class="label label-info">{{ val.fileName }}</span>
                </a>
            </li>
            {%- endfor -%}
        </ul>
    {%- endmacro -%}
    {{ _self.attachment_row_data(attachments)|raw }}
{%- endmacro %}

{#
    Render email body
    Parameters:
        emailBody - email body entity Oro\Bundle\EmailBundle\Entity\EmailBody
        cssClass - used to specify an additional CSS class for email body container HTML element
#}
{% macro body(emailBody, cssClass) -%}
    {% if emailBody.bodyIsText -%}
        <pre class="email-body{% if cssClass is defined %} {{ cssClass }}{% endif %}">{{ emailBody.content }}</pre>
    {%- else -%}
        <iframe class="email-body{% if cssClass is defined %} {{ cssClass }}{% endif %}" src="{{ path('oro_email_body', {id:emailBody.id}) }}"></iframe>
    {%- endif %}
{%- endmacro %}

{'fraction_non_alphanumeric': 0.14451103241623536, 'fraction_numerical': 0.0031326614001634433, 'mean_word_length': 1.763975155279503, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1789809', 'n_tokens_mistral': 4182, 'n_tokens_neox': 3853, 'n_words': 898}