{% extends 'main_header.html' %}
{% block body %}
<table class="one-column-emphasis context-menu">
    <thead>
    <tr class="one-column-emphasis-first">
        <th scope="col"><input type="checkbox" name="select_all" onclick="toggle_all_checkboxes(this)"/> </th>
        <th scope="col">Trigger On/Alive</th>
        <th scope="col">Process Name</th>
        <th scope="col">Entry Name</th>
        <th scope="col">Trigger Frequency</th>
        <th scope="col"></th>  <!-- Trigger Now -->
        <th scope="col">Next Run In</th>
        <th scope="col">Arguments</th>
        <th scope="col"></th>  <!-- View Log -->
        <th scope="col"></th>  <!-- View Uow -->
        <th scope="col"></th>  <!-- Cancel Uow -->
        <th scope="col"></th>  <!-- Edit -->
    </tr>
    </thead>
    <tbody>

    {%- for row in details.freerun_entries %}
    {%- if row.is_on != row.is_alive -%}
    <tr class="state_inconsistent">
    {%- elif not row.is_alive -%}
    <tr class="state_inactive">
    {%- else -%}
    <tr>
    {%- endif -%}
        <td>
            {% set value = "{ process_name: '" + row.process_name + "', entry_name: '" + row.entry_name + "', is_freerun: 'True' }" %}
            <input type="checkbox" name="batch_processing" value="{{ value }}"/>
        </td>
        <td>{{ row.is_on }} / {{ row.is_alive }}</td>
        <td>{{ row.process_name }}</td>
        <td>{{ row.entry_name }}</td>
        <td>
            <form method="GET" action="/action/change_interval/">
                <input type="hidden" name="process_name" value="{{ row.process_name }}" />
                <input type="hidden" name="entry_name" value="{{ row.entry_name }}" />
                <input type="hidden" name="is_freerun" value="True" />
                <input type="text" size="8" maxlength="32" name="interval" value="{{ row.trigger_frequency }}" />
                <input type="submit" class="fa-input" title="Apply" value="&#xf00c;"/>
            </form>
        </td>
        <td>
            <form method="GET" action="/action/trigger_now/">
                <input type="hidden" name="process_name" value="{{ row.process_name }}" />
                <input type="hidden" name="entry_name" value="{{ row.entry_name }}" />
                <input type="hidden" name="is_freerun" value="True" />
                <input type="submit" class="action_button fa-input" title="Trigger" value="&#xf1d9;&nbsp;Trigger"/>
            </form>
        </td>

        <td>{{ row.next_run_in }}</td>
        <td>{{ row.arguments|jsonify }}</td>
        <td>
            {% set url = 'action=action/get_log' + '&process_name=' + row.process_name + '&entry_name=' + row.entry_name + '&is_freerun=True' %}
            <form method="GET" onsubmit="window.open('/object_viewer/?{{ url }}','View Log',
                 'toolbar=no,scrollbars=yes,resizable=yes,top=250,left=250,width=720,height=480'); return false;">
                <input type="submit" class="action_button fa-input" title="View Log" value="&#xf00b;&nbsp;Log"/>
            </form>
        </td>
        <td>
            {% set url = 'action=action/get_uow' + '&process_name=' + row.process_name + '&entry_name=' + row.entry_name + '&is_freerun=True' %}
            <form method="GET" onsubmit="window.open('/object_viewer/?{{ url }}','Get Uow',
                 'toolbar=no,scrollbars=yes,resizable=yes,top=250,left=250,width=400,height=350'); return false;">
                <input type="submit" class="action_button fa-input" title="View Uow" value="&#xf1c9;&nbsp;Uow"/>
            </form>
        </td>
        <td>
            <form method="GET" action="/action/cancel_uow/">
                <input type="hidden" name="process_name" value="{{ row.process_name }}" />
                <input type="hidden" name="entry_name" value="{{ row.entry_name }}" />
                <input type="hidden" name="is_freerun" value="True" />
                <input type="submit" class="action_button fa-input" title="Cancel Uow" value="&#xf00d;&nbsp;Cancel"/>
            </form>
        </td>
        <td>
            {% set form_url = url_for('open_schedulable_form') %}
            {% set url = form_url + '?process_name=' + row.process_name + '&entry_name=' + row.entry_name + '&is_freerun=True' + '&is_new_entry=False'%}
            <form method="GET"
                 onsubmit="window.open('{{ url }}','Edit Freerun Trigger',
                 'toolbar=no,scrollbars=yes,resizable=yes,top=250,left=250,width=750,height=550'); return false;">
                <input type="submit" class="action_button fa-input" title="Edit" value="&#xf044;&nbsp;Edit"/>
            </form>
        </td>
    </tr>
    {%- endfor %}

    <tr>
        <td colspan="13">
            {% set form_url = url_for('open_schedulable_form') %}
            {% set url = form_url + '?is_new_entry=True'%}
            <a href="#" onClick="MyWindow=window.open('{{ url }}','New Freerun Trigger',
                'toolbar=no,scrollbars=yes,resizable=yes,top=250,left=250,width=750,height=550'); return false;">
                <i class="fa fa-plus"></i>&nbsp;Add New Freerun Trigger
            </a>
        </td>
    </tr>

    </tbody>
</table>

{% import 'block_context_menu.html' as context_menu %}
{{ context_menu.trigger_menu(true) }}

{% endblock %}
