{% extends 'django_admin_rq/job_base.html' %}

{% load i18n admin_urls %}

{% block content_title %}
    {% if title %}
        <h1>
            {{ title }} &rsaquo;&rsaquo;
            {% if preview %}
                {% trans 'Preview' %}
            {% else %}
                {% trans 'Run' %}
            {% endif %}
        </h1>
    {% endif %}
{% endblock %}


{% block content %}
    {{ block.super }}

    {% block form_data %}
        {% if form_data_list %}
        <div class="module aligned">
            <h2>{% trans 'Form data' %}</h2>
            {% for field_data in form_data_list %}
                <div class="form-row">
                    <label>
                        {% if field_data.label %}{{ field_data.label }}{% else %}{{ field_data.name|capfirst }}{% endif %}:
                    </label>
                    <p>
                        {% if field_data.display_value %}
                            {{ field_data.display_value }}
                        {% else %}
                            {{ field_data.value }}
                        {% endif %}
                    </p>
                </div>
            {% endfor %}
        </div>
        {% endif %}
    {% endblock %}

    {% if job_status and not job_status.is_finished %}
        <div id="progress-container">
            <p id="progress-label">
                {% if job_status.is_failed %}
                    {{ title }} {% trans 'failed' %}
                    <br />
                    {{ job_status.failure_reason }}
                {% else %}
                    {% if preview %}
                        {% blocktrans %}Preview is being generated for {{ title }}{% endblocktrans %}
                    {% else %}
                        {% blocktrans %}{{ title }} is running{% endblocktrans %}
                    {% endif %}
                {% endif %}
            </p>
            {% if job_status.is_queued or job_status.is_started %}
                <progress id="progress-bar" max="100"></progress>
            {% endif %}
        </div>
    {% endif %}

    {% block job_content %}{% endblock %}

    {% block action_row %}
        {% if preview or job_status.is_finished %}
            <div class="submit-row">
                {% if preview %}
                    <a class="button inline" href="{% url opts|admin_urlname:'job_run' job_name=job_name view_name=main_run_view object_id=original.pk %}">
                        {% trans 'Run' %}
                    </a>
                {% else %}
                    {% if complete_view_url %}
                        <a class="button inline" href="{{ complete_view_url }}">{% trans 'Continue' %}</a>
                    {% elif original_change_url %}
                        <a class="button inline" href="{{ original_change_url }}">{% trans 'Done' %}</a>
                    {% else %}
                        <a class="button inline" href="{{ original_changelist_url }}">{% trans 'Done' %}</a>
                    {% endif %}
                {% endif %}
            </div>
        {% endif %}
    {% endblock %}

{% endblock %}
