{% extends "admin/openhelpdesk/change_form_ohp.html" %}

{% load helpdesk_tags i18n staticfiles %}

{% block extrahead %}
    {{ block.super }}
    <script src="{% static "openhelpdesk/js/lib/require.js" %}" data-main="{% static "openhelpdesk/js/ticket" %}"></script>
    <link rel="stylesheet" href="{% static "openhelpdesk/css/admin/ticket/change_form.css" %}">
{% endblock %}

{% block after_field_sets %}
    {% if object_id %}
        <div id="ticket_infos">
            <ul>
                <li><a href="#tab_ticket_data">{% awesome_icon "database" larger="lg" %}&nbsp;&nbsp;{% trans "Ticket Data" %}</a></li>
                <li><a href="#tab_messages">{% awesome_icon "comments" larger="lg" %}&nbsp;&nbsp;{% trans "Messaging" %}</a></li>
                <li><a href="#tab_changestatuslog">{% awesome_icon "exchange" larger="lg" %}&nbsp;&nbsp;{% trans "Status Changelogs" %}</a></li>
            </ul>
            <div id="tab_ticket_data">
                <fieldset class="module aligned">
                    <div class="form-row">
                    <table class="table_ticket_data">
                        <tbody>
                        <tr><th>{% trans "Created" %}:</th><td>{{ original.created }}</td></tr>
                        <tr>
                            <th>{% trans "Tipologies" %}:</th>
                            <td>{{ original.tipologies.all|join:", " }}</td>
                        </tr>
                        <tr><th>{% trans "Priority" %}:</th><td>{{ original.get_priority_display }}</td></tr>
                        <tr><th>{% trans "Source" %}:</th><td>{% if original.source %}{% awesome_icon original.source.icon %}&nbsp;&nbsp;{{ original.source }}{% endif %}</td></tr>
                        <tr><th>{% trans "Status" %}:</th><td class="ticket_status">{{ original.status|helpdesk_status }}</td></tr>
                        <tr><th>{% trans "Content" %}:</th><td><div id="ticket_content">{{ original.content|safe }}</div></td></tr>
                        {% if helpdesk_user.pk != original.requester.pk %}
                            <tr><th>{% trans "Requester" %}:</th><td>{{ original.requester }}</td></tr>
                        {% endif %}
                        {% if not helpdesk_user.is_requester %}
                            <tr><th>{% trans "Insert by" %}:</th><td>{{ original.insert_by }}</td></tr>
                        {% endif %}
                        <tr><th>{% trans "Assignee" %}:</th><td>{{ original.assignee|default_if_none:_("Not assigned") }}</td></tr>
                        <tr>
                            <th>{% trans "Related tickets" %}:</th>
                            <td>
                                {% for related_ticket in original.related_tickets.all %}
                                <a class="related_ticket" href="{% url 'admin:openhelpdesk_ticket_change' related_ticket.pk %}">{% trans opts.verbose_name %}{{ related_ticket.id }}</a>&nbsp;
                                {% empty %}
                                    {% trans "No related tickets" %}
                                {% endfor %}
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    </div>
                </fieldset>
            </div>
            <div id="tab_messages">
                <fieldset class="module aligned">
                    {% for ticket_message in ticket_messages %}
                        {% format_ticket_message ticket_message %}
                    {% empty %}
                        <div class="form-row" style="text-align: center"><h2>{% blocktrans %}There are no messages until now.{% endblocktrans %}</h2></div>
                    {% endfor %}
                </fieldset>
            </div>
            <div id="tab_changestatuslog">
                {% if ticket_changelogs %}
                    <fieldset class="module aligned">
                        {% for changelog in ticket_changelogs %}
                            <div id="ticket_statuschangelog_{{ changelog.pk }}"
                                 class="form-row">
                                <span class="before">{% if changelog.before %}{{ changelog.before|helpdesk_status }}{% else %}&nbsp;{% endif %}</span>
                                <span class="arrow">{% awesome_icon 'long-arrow-right' %}</span>
                                <span class="after">{{ changelog.after|helpdesk_status }}</span>{{ changelog.created }}
                            </div>
                        {% endfor %}
                    </fieldset>
                {% endif %}
            </div>
        </div>

    {% endif %}
{% endblock %}

{% block content %}
    {{ block.super }}
    <script type="text/javascript">
        {% if original.is_closed %}
            $(document).ready(function () {
                var submit_row = $('div.submit-row');
                if (submit_row.length == 0) {
                    alert("ERRORE CONTATTARE L'AMMINISTRATORE DI SISTEMA")
                }
                submit_row.remove();
            });
        {% endif %}
    </script>
{% endblock %}