{% extends "helpdesk/public_base.html" %}{% load i18n humanize %}
{% load static %}
{% block helpdesk_title %}{% trans "View a Ticket" %}{% endblock %}

{% block helpdesk_body %}

<table class="table table-hover table-bordered table-striped">
<caption>{{ ticket.ticket }} . {{ ticket.title }} [{{ ticket.get_status }}]</caption>
<thead>
<tr><th colspan='2'>{% blocktrans with ticket.queue as queue_name %}Queue: {{ queue_name }}{% endblocktrans %}</th></tr>
</thead>
<tbody>
<tr>
    <th>{% trans "Submitted On" %}</th>
    <td>{{ ticket.created|date:"DATETIME_FORMAT" }} ({{ ticket.created|naturaltime }})</td>
</tr>

{% if ticket.due_date %}
    <tr>
        <th>{% trans "Due On" %}</th>
        <td>{{ ticket.due_date|date:"DATETIME_FORMAT" }} ({{ ticket.due_date|naturaltime }})</td>
    </tr>
{% endif %}

<tr>
    <th>{% trans "Submitter E-Mail" %}</th>
    <td>{{ ticket.submitter_email }}</td>
</tr>

<tr>
    <th>{% trans "Priority" %}</th>
    <td>{{ ticket.get_priority_display }}</td>
</tr>

{% for customfield in ticket.ticketcustomfieldvalue_set.all %}
    <tr>
        <th>{{ customfield.field.label }}</th>
        <td>{{ customfield.value|default:"" }}</td>
    </tr>
{% endfor %}

{% if tags_enabled %}
<tr>
    <th>{% trans "Tags" %}</th>
    <td>{{ ticket.tags }}</td>
</tr>
{% endif %}

<tr>
    <th colspan='2'>{% trans "Description" %}</th>
</tr>
<tr>
    <td colspan='2'>{{ ticket.description|force_escape|urlizetrunc:50|linebreaksbr }}</td>
</tr>

{% if ticket.resolution %}<tr>
    <th colspan='2'>{% trans "Resolution" %}{% if ticket.get_status_display == "Resolved" %} <a href='{{ ticket.ticket_url }}&close'><button type="button" class="btn btn-primary btn-xs">{% trans "Accept and Close" %}</button></a>{% endif %}</th>
</tr>
<tr>
    <td colspan='2'>{{ ticket.resolution|urlizetrunc:50|linebreaksbr }}</td>
</tr>{% endif %}
</tbody>
</table>

{% if ticket.followup_set.public_followups %}
<h3>{% trans "Follow-Ups" %}</h3>
{% load ticket_to_link %}
{% for followup in ticket.followup_set.public_followups %}
<div class='followup well'>
<div class='title'>{{ followup.title }} <span class='byline text-info'>{% if followup.user %}by {{ followup.user }}{% endif %} <span title='{{ followup.date|date:"DATETIME_FORMAT" }}'>{{ followup.date|naturaltime }}</span></span></div>
{{ followup.comment|force_escape|urlizetrunc:50|num_to_link|linebreaksbr }}
{% if followup.ticketchange_set.all %}<div class='changes'><ul>
{% for change in followup.ticketchange_set.all %}
<li>{% blocktrans with change.field as field and change.old_value as old_value and change.new_value as new_value %}Changed {{ field }} from {{ old_value }} to {{ new_value }}.{% endblocktrans %}</li>
{% endfor %}
</ul></div>{% endif %}
{% for attachment in followup.followupattachment_set.all %}{% if forloop.first %}<div class='attachments'><ul>{% endif %}
<li><a href='{{ attachment.file.url }}'>{{ attachment.filename }}</a> ({{ attachment.mime_type }}, {{ attachment.size|filesizeformat }})</li>
{% if forloop.last %}</ul></div>{% endif %}
{% endfor %}
</div>
{% endfor %}
{% endif %}

<form method='post' action="{% url 'helpdesk:update' ticket.id %}" enctype='multipart/form-data'>
    <input type="hidden" name="key" value="{{ key }}" />
    <input type="hidden" name="mail" value="{{ mail }}" />

<fieldset>
    <dl>
        {% if preset_replies %}
        <dt><label for='id_preset'>{% trans "Use a Pre-set Reply" %}</label> <span class='form_optional'>{% trans "(Optional)" %}</span></dt>
        <dd><select name='preset' id='id_preset'><option value=''>------</option>{% for preset in preset_replies %}<option value='{{ preset.id }}'>{{ preset.name }}</option>{% endfor %}</select></dd>
        <dd class='form_help_text'>{% trans "Selecting a pre-set reply will over-write your comment below. You can then modify the pre-set reply to your liking before saving this update." %}</dd>
        {% endif %}

        <dt><label for='commentBox'>{% trans "Comment / Resolution" %}</label></dt>
        <dd><textarea rows='8' cols='70' name='comment' id='commentBox'></textarea></dd>
        <dd class='form_help_text'>{% trans "You can insert ticket and queue details in your message. For more information, see the <a href='../../help/context/'>context help page</a>." %}</dd>

        {% if not ticket.can_be_resolved %}<dd>{% trans "This ticket cannot be resolved or closed until the tickets it depends on are resolved." %}</dd>{% endif %}
        {% ifequal ticket.status 1 %}
        <input type="hidden" name="new_status" value="{{ ticket.status }}" />
        {% endifequal %}
        {% ifequal ticket.status 2 %}
        <dd><div class="form-group">
            <label for='st_reopened' class='active radio-inline'><input type='radio' name='new_status' value='2' id='st_reopened' checked='checked'>{% trans "Reopened" %} &raquo;</label>
            <label class="radio-inline" for='st_resolved'><input type='radio' name='new_status' value='3' id='st_resolved'{% if not ticket.can_be_resolved %} disabled='disabled'{% endif %}>{% trans "Resolved" %} &raquo;</label>
            <label class="radio-inline" for='st_closed'><input type='radio' name='new_status' value='4' id='st_closed'{% if not ticket.can_be_resolved %} disabled='disabled'{% endif %}>{% trans "Closed" %} &raquo;</label>
            <label class="radio-inline" for='st_duplicate'><input type='radio' name='new_status' value='5' id='st_duplicate'>{% trans "Duplicate" %}</label>
        </div></dd>
        {% endifequal %}
        {% ifequal ticket.status 3 %}
        <dd><div class="form-group">
            <label for='st_reopened' class="radio-inline"><input type='radio' name='new_status' value='2' id='st_reopened'>{% trans "Reopened" %} &laquo;</label>
            <label for='st_resolved' class='active radio-inline'><input type='radio' name='new_status' value='3' id='st_resolved' checked='checked'>{% trans "Resolved" %} &raquo;</label>
            <label class="radio-inline" for='st_closed'><input type='radio' name='new_status' value='4' id='st_closed'>{% trans "Closed" %}</label>
        </div></dd>
        {% endifequal %}
        {% ifequal ticket.status 4 %}
        <dd><div class="form-group"><label for='st_reopened' class="radio-inline"><input type='radio' name='new_status' value='2' id='st_reopened'>{% trans "Reopened" %} &laquo;</label>
        <label class="radio-inline" for='st_closed'><input type='radio' name='new_status' value='4' id='st_closed' checked='checked'>{% trans "Closed" %}</label></div></dd>
        {% endifequal %}
        {% ifequal ticket.status 5 %}
        <dd><div class="form-group">
            <label class="radio-inline" for='st_reopened'><input type='radio' name='new_status' value='2' id='st_reopened'>{% trans "Reopened" %} &laquo;</label>
            <label class="radio-inline" for='st_duplicate'><input type='radio' name='new_status' value='5' id='st_duplicate' checked='checked'>{% trans "Duplicate" %}</label>
        </div></dd>
        {% endifequal %}

        <input type='hidden' name='public' value='1'>

    </dl>

<p id='ShowFileUploadPara'><button class="btn btn-warning btn-sm"
    id='ShowFileUpload' onclick="$('#FileUpload')[0].style.display='block';return false;" >{% trans "Attach File(s) &raquo;" %}</button></p>

<div id='FileUpload' style='display: none;'>

    <dl>
        <dt><label for='id_file'>{% trans "Attach a File" %}</label></dt>
        <dd>
            <div class="add_file_fields_wrap">
                <div><label class='btn btn-primary btn-sm btn-file'>
                        Browse... <input type="file" name='attachment' id='file0' style='display: none;'/>
                </label><span>&nbsp;</span><span id='selectedfilename0'>{% trans 'No files selected.' %}</span></div>
            </div>
        </dd>
    </dl>

</div>

</fieldset>

<button class="btn btn-primary btn-lg" type='submit'>{% trans "Update This Ticket" %}</button>

{% csrf_token %}</form>


{% endblock %}
