<commit_before>{% macro renderTransitionButton(workflow, transition, enabled, url, redirectToWorkflow) %}
    <a href="{{ url }}"
        data-enabled="{{ enabled }}"
        data-redirect-to-workflow="{{ redirectToWorkflow }}"
        class="btn icons-holder-text no-hash {% if not enabled %}disabled {% endif %}{% if transition.options.frontend is defined and transition.options.frontend.class is defined %}{{ transition.options.frontend.class }}{% endif %}"
        id="transition-{{ workflow.name }}-{{ transition.name }}">
        {% if transition.options.frontend is defined and transition.options.frontend.icon is defined %}
            <i class="{{ transition.options.frontend.icon }} hide-text">{{ transition.label }}</i>
        {% endif %}
        {{ transition.label }}
    </a>
{% endmacro %}

{% macro renderTransitionsJs(workflowData, blockId) %}
    <script type="text/javascript">
        $(function() {
            var container = $('#{{ blockId }}');
            {% for data in workflowData %}
                {% for transition in data.transitions %}
                container.on('click', '#transition-{{ data.workflow.name }}-{{ transition.name }}', function(e) {
                    var element = this;
                    var enabled = $(element).data('enabled');
                    if (enabled) {
                        e.preventDefault();
                        $.getJSON(this.href)
                        .done(function(response) {
                            var workflowItemId = null;
                            if (response.workflowItem && response.workflowItem.id) {
                                workflowItemId = response.workflowItem.id;
                            }
                            var needRedirect = $(element).data('redirect-to-workflow');
                            if (needRedirect && workflowItemId) {
                                var redirectUrl = Routing.generate(
                                    'oro_workflow_step_edit',
                                    { id: workflowItemId }
                                );

                                if (Oro.hashNavigationEnabled()) {
                                    Oro.hashNavigationInstance.setLocation(redirectUrl);
                                } else {
                                    window.location.href = redirectUrl;
                                }
                            } else {
                                if (Oro.hashNavigationEnabled()) {
                                    Oro.hashNavigationInstance.loadPage();
                                } else {
                                    window.location.reload();
                                }
                            }
                        })
                        .fail(function(jqxhr, textStatus, error) {
                            Oro.NotificationFlashMessage('error', _.__('Could not perform transition'));
                        });
                    }
                    return false;
                });
                {% endfor %}
            {% endfor %}
        });
    </script>
{% endmacro %}<commit_msg>CRM-424: Update widget to process redirect URL on workflow transitions<commit_after>{% macro renderTransitionButton(workflow, transition, enabled, url, redirectToWorkflow) %}
    <button type="button"
        {% if not enabled %}disabled="disabled"{% endif %}
        data-href="{{ url }}"
        data-redirect-to-workflow="{{ redirectToWorkflow }}"
        class="btn icons-holder-text no-hash {% if transition.options.frontend is defined and transition.options.frontend.class is defined %}{{ transition.options.frontend.class }}{% endif %}"
        id="transition-{{ workflow.name }}-{{ transition.name }}">
        {% if transition.options.frontend is defined and transition.options.frontend.icon is defined %}
            <i class="{{ transition.options.frontend.icon }} hide-text">{{ transition.label|trans }}</i>
        {% endif %}
        {{ transition.label|trans }}
    </button>
{% endmacro %}

{% macro renderTransitionsJs(workflowData, blockId) %}
    <script type="text/javascript">
        $(function() {
            var container = $('#{{ blockId }}');
            {% for data in workflowData %}
                {% for transition in data.transitions %}
                container.on('click', '#transition-{{ data.workflow.name }}-{{ transition.name }}', function(e) {
                    var element = $(this);
                    e.preventDefault();
                    $.getJSON($(this).data('href'))
                        .done(function(response) {
                            var doRedirect = function(redirectUrl) {
                                if (Oro.hashNavigationEnabled()) {
                                    Oro.hashNavigationInstance.setLocation(redirectUrl);
                                } else {
                                    window.location.href = redirectUrl;
                                }
                            };
                            var doReload = function() {
                                if (Oro.hashNavigationEnabled()) {
                                    Oro.hashNavigationInstance.loadPage();
                                } else {
                                    window.location.reload();
                                }
                            };

                            /** Handle redirectUrl result parameter for RedirectPostAction */
                            element.one('transitions_success', function(e, response) {
                                if (response.workflowItem
                                        && response.workflowItem.result
                                        && response.workflowItem.result.redirectUrl
                                ) {
                                    e.stopImmediatePropagation();
                                    doRedirect(response.workflowItem.result.redirectUrl);
                                }
                            });
                            /** Handle redirect-to-workflow element data parameter */
                            element.one('transitions_success', function(e, response) {
                                var workflowItemId = null;
                                if (response.workflowItem && response.workflowItem.id) {
                                    workflowItemId = response.workflowItem.id;
                                }
                                var needRedirect = element.data('redirect-to-workflow');
                                if (needRedirect && workflowItemId) {
                                    e.stopImmediatePropagation();
                                    var redirectUrl = Routing.generate(
                                        'oro_workflow_step_edit',
                                        {id: workflowItemId}
                                    );
                                    doRedirect(redirectUrl);
                                }
                            });
                            /** By default reload page */
                            element.one('transitions_success', doReload);
                            element.trigger('transitions_success', [response]);
                        })
                        .fail(function(jqxhr, textStatus, error) {
                            element.one('transitions_failure', function() {
                                Oro.NotificationFlashMessage('error', _.__('Could not perform transition'));
                            });
                            element.trigger('transitions_failure', [jqxhr, textStatus, error]);
                        });
                    return false;
                });
                {% endfor %}
            {% endfor %}
        });
    </script>
{% endmacro %}
{'fraction_non_alphanumeric': 0.10591979630808403, 'fraction_numerical': 0.00038192234245703374, 'mean_word_length': 1.1175202156334232, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6344916', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1610, 'n_words': 311}