<div id='entityEditContainer' class="managegoals" style="display:none;">
    <table class="dataTable entityTable">
        <thead>
        <tr>
            <th class="first">Id</th>
            <th>{{ 'Goals_GoalName'|translate }}</th>
            <th>{{ 'Goals_GoalIsTriggeredWhen'|translate }}</th>
            <th>{{ 'General_ColumnRevenue'|translate }}</th>
            <th>{{ 'General_Edit'|translate }}</th>
            <th>{{ 'General_Delete'|translate }}</th>
        </tr>
        </thead>
        {% if goals is empty %}
            <tr>
                <td colspan='7'>
                    <br/>
                    {{ 'Goals_ThereIsNoGoalToManage'|translate(siteName)|raw }}.
                    <br/><br/>
                </td>
            </tr>
        {% else %}
            {% for goal in goals %}
                <tr>
                    <td class="first">{{ goal.idgoal }}</td>
                    <td>{{ goal.name|raw }}</td>{# NOTE: goal names are escaped in the DB #}
                    <td><span class='matchAttribute'>{{ goal.match_attribute }}</span>
                        {% if goal.pattern_type is defined %}
                            <br/>
                            {{ 'Goals_Pattern'|translate }} {{ goal.pattern_type }}: {{ goal.pattern|raw }}
                        {% endif %}
                    </td>
                    <td>{% if goal.revenue==0 %}-{% else %}{{ goal.revenue|money(idSite)|raw }}{% endif %}</td>
                    <td>
                        <a href='#' name="linkEditGoal" id="{{ goal.idgoal }}" class="link_but withIcon">
                            <img src='plugins/Morpheus/images/ico_edit.png' border="0"/>
                            {{ 'General_Edit'|translate }}
                        </a>
                    </td>
                    <td>
                        <a href='#' name="linkDeleteGoal" id="{{ goal.idgoal }}" class="link_but withIcon">
                            <img src='plugins/Morpheus/images/ico_delete.png' border="0"/>
                            {{ 'General_Delete'|translate }}
                        </a>
                    </td>
                </tr>
            {% endfor %}
        {% endif %}
    </table>

    {% if onlyShowAddNewGoal is not defined %}
        <br/>
        <div name="linkAddNewGoal" class="addrow"><img src='plugins/Morpheus/images/add.png'/> {{ 'Goals_CreateNewGOal'|translate }}</div>
        <br/>
        <br/>

    {% endif %}
</div>

<div class="ui-confirm" id="confirm">
    <h2></h2>
    <input role="yes" type="button" value="{{ 'General_Yes'|translate }}"/>
    <input role="no" type="button" value="{{ 'General_No'|translate }}"/>
</div>

<script type="text/javascript">
    var goalTypeToTranslation = {
        "manually": "{{ 'Goals_ManuallyTriggeredUsingJavascriptFunction'|translate }}",
        "file": "{{ 'Goals_Download'|translate }}",
        "url": "{{ 'Goals_VisitUrl'|translate }}",
        "title": "{{ 'Goals_VisitPageTitle'|translate }}",
        "external_website": "{{ 'Goals_ClickOutlink'|translate }}",
        "event_action": "{{ 'Goals_SendEvent'|translate }} ({{ 'Events_EventAction'|translate }})",
        "event_category": "{{ 'Goals_SendEvent'|translate }} ({{ 'Events_EventCategory'|translate }})",
        "event_name": "{{ 'Goals_SendEvent'|translate }} ({{ 'Events_EventName'|translate }})"
    };

    $(document).ready(function () {
        // translation of the goal "match attribute" to human readable description
        $('.matchAttribute').each(function () {
            var matchAttribute = $(this).text();
            var translation = goalTypeToTranslation[matchAttribute];
            $(this).text(translation);
        });
    });
</script>
