{% extends "projector/project/task/base.html" %}

{% load markup %}
{% load native %}

{% block extra-head %}
    {{ block.super }}
    <script type="text/javascript" src="{{ RICHTEMPLATES_MEDIA_URL }}js/action_form.js"></script>
{% endblock %}

{% load i18n %}

{% comment %}
{% block col-left %}{{ block.super }}
<div class="richtemplates-panel">
    <h5>{% trans "Task changes" %}</h5>
    <div class="richtemplates-panel-content">
        {% if task.revisions|length > 1 %}
        <ul class="nav-vertical">
            {% for revision in task.revisions %}
            {% if not forloop.first %}
            <li><a href="{{ revision.task.get_absolute_url }}#revision:{{ revision.revision }}">#{{ revision.revision }} {% trans "by" %} {{ revision.author }} {% trans "at" %} {{ revision.created_at|date:"Y-m-d" }}</a></li>
            {% endif %}
            {% endfor %}
        </ul>
        {% else %}
        <ul class="messages">
            <li class="message message-warning">{% trans "No revisions yet" %}</li>
        </ul>
        {% endif %}
    </div>
</div>
{% endblock %}
{% endcomment %}

{% block col-single-extra %}
<div class="richtemplates-panel">    
    <h5>{% trans "Task detail" %}</h5>
    <div class="richtemplates-panel-content">

        <h1>{% trans "Task" %} {{ task.id }}: {{ task.summary }}</h1>
        <h2>{{ task.status }} {% if not task.status.is_resolved %}({% trans "opened for" %} {{ task.created_at|timesince }}){% endif %}</h2>
        <ul class="nav-inline">
            <li class="richbuttonset">
                <a class="button-link" href="{{ task.project.get_task_list_url }}">{% trans "Return to task list" %}</a>
                <a class="button-link" href="{{ task.get_edit_url }}">{% trans "Edit" %}</a>
            </li>
            {% if user.is_authenticated %}
            
            <li class="richbuttonset" style="float: right">
                
                <form id="watch_form" method="post" action="{% spaceless %}
                    {% if not is_watched %}
                        {{ task.get_watch_url }}
                    {% else %}
                        {{ task.get_unwatch_url }}
                    {% endif %}{% endspaceless %}">

                    {% csrf_token %}
                    <input id="watch_form_submit" class="richbutton" type="submit" value="{% spaceless %}
                        {% if not is_watched %}
                        {% trans "Watch" %}
                        {% else %}
                        {% trans "Unwatch" %}
                        {% endif %}{% endspaceless %}"
                    />
                </form>

            </li>
            {% endif %}
        </ul>

        <div class="task-block">
            <table class="task-block-properties">
                <tbody>
                    <tr>
                        <th>{% trans "Task" %} Id</th>
                        <td>{{ task.id }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Revision" %}</th>
                        <td>{{ task.revision }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Project" %}</th>
                        <td><a href="{{ task.project.get_absolute_url }}">{{ task.project }}</a></td>
                    </tr>
                    <tr>
                        <th>{% trans "Component" %}</th>
                        <td>{{ task.component }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Type" %}</th>
                        <td>{{ task.type }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Milestone" %}</th>
                        {% if task.milestone %}
                        <td class="show-tipsy" title="{{ task.milestone.description }}">
                            <a href="{{ task.milestone.get_absolute_url }}">{{ task.milestone }}</a>
                        </td>
                        {% else %}
                        <td>-</td>
                        {% endif %}
                    </tr>
                    <tr>
                        <th>{% trans "Summary" %}</th>
                        <td>{{ task.summary }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Reported by" %}</th>
                        <td>{{ task.author }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Reported date" %}</th>
                        <td>{{ task.created_at|date:"Y-m-d H:i:s" }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Last modified at" %}</th>
                        <td>{{ task.edited_at|date:"Y-m-d H:i:s" }}
                    <tr>
                        <th>{% trans "Deadline" %}</th>
                        <td>
                            {% if task.deadline %}
                                {{ task.deadline|date:"Y-m-d" }}
                                {% if now > task.deadline %}
                                    <img src="{% richicon_src "icon-no.gif" %}" />
                                {% endif %}
                            {% else %}
                                {% trans "Not set" %}
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th>{% trans "Assigned to" %}</th>
                        <td>{{ task.owner }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Priority" %}</th>
                        <td>{{ task.priority }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Status" %}</th>
                        <td>
                            <span
                            {% if task.status.is_resolved %}
                            class="task-closed"
                            {% else %}
                            class="task-open"
                            {% endif %}
                            >
                            {{ task.status }}</span>
                        </td>
                    </tr>
                </tbody>
            </table>
            <h2>{% trans "Description" %}:</h2>
            <div class="task-block-description">
                {{ task.description|safe|restructuredtext }}
            </div>

        </div>

        <div class="task-changeset">
            
            <h2>{% trans "History" %}</h2>
                {% for revision in task.revisions %}
                {% if not forloop.first %}
                <div id="revision:{{ revision.revision }}" class="task-block">
                    <h3>{{ revision.created_at|date:"Y-m-d H:i:s" }} {% trans "by" %} {{ revision.author }}</h3>
                    <div class="task-revision-changes">
                        {% if revision.changes %}
                        <ul>
                            {% for field, values in revision.changes.items %}
                            <li><strong>{{ field }}</strong>
                                {% if not values.1 %}
                                    {% trans "set to" %}
                                {% else %}
                                {% trans "changed" %}: {{ values.1|slice:":20" }} &rarr;
                                {% endif %}
                                <strong>{{ values.0|slice:":20" }}</strong></li>
                            {% endfor %}
                        </ul>
                        {% endif %}
                    </div>
                    {{ revision.comment|default_if_none:""|restructuredtext }}
                </div>
                {% endif %}
                {% endfor %}
        

        {% comment %}{# Old dynamic form #}
            {# Form begin #}
            {% if user.is_authenticated %}
            <form action="." method="post" class="action-form">
            {% csrf_token %}

            <fieldset id="task-comment">
                <legend>{% trans "Quick action" %}</legend>
                {{ comment_formset.management_form }}
                {% for form in comment_formset.forms %}
                    <table class="form-table">
                        {% include "richtemplates/forms/form.html" %}
                    </table>
                {% endfor %}

                {% with action_form as form %}
                    {{ form.as_p_rows }}
                {% endwith %}
                
                <p>
                    <input type="submit" value="{% trans "Submit" %}" />
                </p>
            </fieldset>
            </form>
            {% else %}
            <p>
            {% trans "If you want to contribute, please" %}
                <a href="{% url auth_login %}">{% trans "login" %}</a>.
            </p>
            {% endif %}
        {% endcomment %}

        </div>
    </div>
</div>
{% endblock %}
