{% extends "menu.html" %}
{% load is_in_filter %}

{% block head %}
    <script src="/media/js/common.js" type="text/javascript"></script>
    <script src="/media/js/comment_reply.js" type="text/javascript"></script>
{% endblock %}

{% block title %}{{ section.title }}{% endblock %}

{% block content %}
<h1>Details for ticket #{{ticket.id}}</h1>

{% if editable %}
<div class="toolbar"><a href="/ts/edit/{{ticket.id}}">Edit</a></div>
{% endif %}
<div class="detail">
  <div class="row single">
    <div>
      <h3>Short description:</h3>{{ticket.s_desc}}
    </div>
  </div>
  <div class="clear">
    <div class="row one"><h3>Responsible:</h3>{{ticket.resp}}</div>
    <div class="row two"><h3>Queue:</h3>{{ticket.queue}}</div>
  </div>
  <div>
    <div class="row one"><h3>Urgency:</h3>{{ticket.get_urgency}}</div>
    <div class="row two"><h3>Status:</h3>{{ticket.get_status}}</div>
  </div>
  <div>
    <div class="row one"><h3>Creator:</h3>{{ticket.creator}}</div>
    <div class="row two"><h3>Created:</h3>{{ticket.s_date|date:"d.m.Y H:i"}}</div>
  </div>
  {% if ticket.done %}
  <div>
    <div class="row one"><h3>Deadline:</h3>{{ticket.e_date|date:"d.m.Y"}}</div>
    <div class="row two"><h3 style="color: green">Done</h3>{{ticket.d_date|date:"d.m.Y H:i"}}</div>
  </div>
  {% else %}
  <div class="row clear">
    <h3>Deadline:</h3>{% if ticket.e_date %}{{ticket.e_date|date:"d.m.Y"}}{% else %}{{ticket.e_date}}{% endif %}
  </div>
  {% endif %}
  <div class="row clear">
    <h3>Description:</h3>
    <div>{{ticket.l_desc|urlize|linebreaks}}</div>
  </div>
  <div class="row last clear">
    <div>
      <h3>Subscribers:</h3>
      <div>
        <ul>
        {% for i in subscr %}
          <li>{{i}}</li>
        {%endfor%}
        </ul>
      </div>
    </div>
  </div>
</div>
<br/>
<div class="detail">
  {% if user|is_in:ticket.subscr %}<a href="/ts/unsubscribe/{{ticket.id}}"><b>Unsubscribe</b></a>{% else %}<a href="/ts/subscribe/{{ticket.id}}"><b>Subscribe</b></a>{% endif %} | 
  {% ifequal user ticket.resp %}<a href="/ts/untake/{{ticket.id}}"><b>Drop ticket</b></a>{% else %}<a href="/ts/take/{{ticket.id}}"><b>Take ticket</b></a>{% endifequal %}
  {% if not ticket.done %} | <a href="/ts/status/{{ticket.id}}/resolved"><b>Mark done</b></a> {%endif%}
</div>

<br />
<div class="comments">
<h3>Comments:</h3>
{% if comments %}<ul class="nomargin">
{% for comment in comments %}
  {% ifequal comment '>>>' %}
    <ul>
  {% else %}{% ifequal comment '<<<' %}
    </ul>
  {% else %}
    <li>
      <div class="title">
        {{ comment.owner }}
        <div class="date">{{ comment.date|date:"d.m.Y H:i" }}</div>
        <div class="reply"><input type="button" value="Reply" onclick="openCommentReply(event, {{ticket.id}}, {{comment.id}})" /></div>
      </div>
      {{ comment.text|urlize|linebreaks }}
      <noscript>
        <div class="reply">
          <h3>Reply:</h3>
          <form action="/ts/detail/{{ticket.id}}/" method="post">
            <textarea name="comment" cols="80" rows="5"></textarea>
            <input type="hidden" name="repto" value="{{comment.id}}" />
            <input type="submit" value="Submit" />
          </form>
        </div>
      </noscript>
    </li>
  {% endifequal %}{% endifequal %}
{% endfor %}
</ul>{% endif %}
<div class="reply">
  <h3>Comment:</h3>
  <form method="POST" action="/ts/detail/{{ticket.id}}/">
    <textarea rows="5" cols="80" name="comment"></textarea>
    <input type="submit" value="Submit"/>
    {% if message %}<div class="error">{{ message }}</div>{% endif %}
  </form>
</div>
</div>

{% endblock %}
