{% extends request.is_ajax|yesno:'bajax.html,base.html' %}
{% load i18n tasktags %}

{% block title %}{% trans 'All tasks' %}{% endblock %}

{% block breadcrumb %}
    <ol class="breadcrumb">
        <li><span class="glyphicon glyphicon-home"></span></li>
        <li><a href="{% url 'taskapp:home' %}">{% trans 'Tasks' %}</a></li>
        <li class="active">{% trans 'All tasks' %}</li>
    </ol>
{% endblock %}


{% block page-header %}
    {% trans 'Records of all the tasks in the system' %}
{% endblock %}


{% block main %}

    <div class="table-responsive">
        <table class="table table-striped table-bordered">
            <thead>
            <tr>
                <th class="col-sm-2">{% trans 'Name and comment count' %}</th>
                <th class="col-sm-2">{% trans 'Address' %}</th>
                <th class="col-sm-1">{% trans 'The nature of the damage' %}</th>
                <th class="col-sm-3">{% trans 'Description' %}</th>
                <th class="col-sm-1">{% trans 'Task author' %}</th>
                <th class="col-sm-1">{% trans 'Condition' %}</th>
                <th class="col-sm-1 hidden-xs">{% trans 'Date of create' %}</th>
                <th class="col-sm-1">{% trans 'Actions' %}</th>
            </tr>
            </thead>
            <tbody>
            {% for task in tasks %}

                {% if task.is_relevant %}
                    <tr class="text-muted">
                {% else %}
                    <tr>
                {% endif %}

                {% if task.abon and task.abon.group %}
                    <td>

                        {# Task state #}
                        {% if not task.is_relevant %}
                            {% if task.priority == 'E' %}
                                <span class="glyphicon glyphicon-ok-circle text-success"></span>
                            {% elif task.priority == 'A' %}
                                <span class="glyphicon glyphicon-exclamation-sign text-danger"></span>
                            {% endif %}
                        {% endif %}

                        <a href="{% url 'abonapp:abon_home' task.abon.group.pk task.abon.username %}">
                            {{ task.abon.get_full_name }}
                        </a>
                        {% if task.comment_count > 0 %}({{ task.comment_count }}){% endif %}

                    </td>
                    <td>{{ task.abon.group.title }}, {{ task.abon.street|default:_('Not assigned') }} {{ task.abon.house|default:_('Not assigned') }}</td>
                {% else %}
                    <td>{% trans 'User does not exist' %}</td>
                    <td>---</td>
                {% endif %}

                <td>{{ task.get_mode_display }}</td>
                <td>{{ task.descr|default:_('None') }}</td>
                <td>{% if task.author %}
                    <a href="{% url 'acc_app:other_profile' task.author.pk %}" title="{{ task.author.get_full_name }}" data-toggle="tooltip">
                        {{ task.author.username }}
                    </a>
                    {% else %}
                        {% trans 'Not assigned' %}
                    {% endif %}
                </td>
                <td>{{ task.get_state_display }}</td>

                <td class="hidden-xs">
                    {% is_today task.time_of_create as is_timecreate_is_today %}
                    {% is_yesterday task.time_of_create as is_timecreate_is_yesterday %}
                    {% if is_timecreate_is_today %}
                        {% trans 'Today' %} {{ task.time_of_create|date:'H:i' }}
                    {% elif is_timecreate_is_yesterday %}
                        {% trans 'Yesterday' %} {{ task.time_of_create|date:'H:i' }}
                    {% else %}
                        {{ task.time_of_create|date:'d E H:i' }}
                    {% endif %}
                </td>

                <td class="btn-group btn-group-sm btn-group-justified">
                    {% if perms.taskapp.change_task %}
                        <a href="{% url 'taskapp:edit' task.pk %}" class="btn btn-default" title="{% trans 'Edit' %}" data-toggle="tooltip">
                            <span class="glyphicon glyphicon-edit"></span>
                        </a>
                    {% endif %}
                    {% if perms.taskapp.can_remind %}
                        <a href="{% url 'taskapp:remind' task.pk %}" class="btn btn-default" title="{% trans 'Remind' %}" data-toggle="tooltip">
                            <span class="glyphicon glyphicon-bell"></span>
                        </a>
                    {% endif %}
                </td>
                </tr>
            {% empty %}
                <tr>
                    <td colspan="8">{% trans 'The list is empty' %}</td>
                </tr>
            {% endfor %}
            </tbody>
            <tfoot>
            <tr>
                <td colspan="8">
                    {% if perms.taskapp.add_task %}
                    <a href="{% url 'taskapp:add' %}" class="btn btn-sm btn-success" title="{% trans 'Add new task' %}" data-toggle="tooltip">
                        <span class="glyphicon glyphicon-plus"></span> {% trans 'Add new task' %}
                    </a>
                    {% endif %}
                </td>
            </tr>
            </tfoot>
        </table>
    </div>

{% endblock %}
