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

{% block title %}
    {% if task.id %}
        {% trans 'Edit' %}
    {% else %}
        {% trans 'Create' %}
    {% endif %}
{% 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">{% if task.id %}{% trans 'Edit' %}{% else %}{% trans 'Create' %}{% endif %}</li>
    </ol>
{% endblock %}


{% block main %}
    <div class="row">
        <div class="{% if task %}col-sm-6{% else %}col-sm-12{% endif %}">
            <div class="panel panel-default">
                <div class="panel-heading">
                {% if task.id %}
                    <h3 class="panel-title">{% trans 'Edit task' %}</h3>
                {% else %}
                    <h3 class="panel-title">{% trans 'Add new task' %}</h3>
                {% endif %}
                </div>
                <div class="panel-body">

                    {% if task.id %}
                        <form role="form" action="{% url 'taskapp:edit' task.id %}" method="post" enctype="multipart/form-data">
                    {% else %}
                        <form role="form" action="{% url 'taskapp:add' %}" method="post" enctype="multipart/form-data">
                    {% endif %}
                    {% csrf_token %}<input type="hidden" name="MAX_FILE_SIZE" value="{% global_var 'FILE_UPLOAD_MAX_MEMORY_SIZE' %}"/>

                    {% bootstrap_icon 'tag' as ic %}
                    {% bootstrap_field form.descr addon_before=ic %}

                    {% bootstrap_icon 'task' as ic %}
                    {% bootstrap_field form.recipients addon_before=ic %}

                    {% bootstrap_icon 'pawn' as ic %}
                    {% bootstrap_field form.mode addon_before=ic %}

                    {% bootstrap_icon 'sort-by-order' as ic %}
                    {% bootstrap_field form.priority addon_before=ic %}

                    {% bootstrap_icon 'retweet' as ic %}
                    {% bootstrap_field form.state addon_before=ic %}

                    <div class="form-group">
                        <label for="id_abon">{% trans 'Subscriber' %}</label>

                        <div class="input-group selectajax" data-dst="/abons/api/abon_filter">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                            <input type="hidden" name="abon" class="selectajax-hid"{% if selected_abon %} value="{{ selected_abon.pk }}"{% endif %}>
                        {% if selected_abon %}
                            <button class="selectajax-btn form-control btn btn-default">{{ selected_abon.fio }}</button>
                            <input type="text" class="form-control dropdown-toggle selectajax-inp hidden" data-toggle="dropdown" id="id_abon" placeholder="{% trans 'Find the subscriber' %}">
                        {% else %}
                            <button class="selectajax-btn form-control btn btn-default hidden"></button>
                            <input type="text" class="form-control dropdown-toggle selectajax-inp" data-toggle="dropdown" id="id_abon" placeholder="{% trans 'Find the subscriber' %}">
                        {% endif %}
                            <ul class="dropdown-menu selectajax-ul"></ul>{{ form.abon.errors }}
                        </div>
                    </div>

                    {% bootstrap_icon 'calendar' as ic %}
                    {% bootstrap_field form.out_date addon_before=ic %}

                    {% bootstrap_icon 'picture' as ic %}
                    {% bootstrap_field form.attachment addon_before=ic %}

                    <div class="btn-group btn-group-sm">
                        {% bootstrap_button _('Save') button_type='submit' button_class='btn-primary' icon='save' %}

                        {% if task.id %}
                            {% url 'taskapp:delete' task.id as delurl%}
                            {% bootstrap_button _('Delete') button_class='btn-danger' href=delurl icon='remove' %}

                            {% url 'taskapp:finish' task.id as cmpurl %}
                            {% bootstrap_button _('Complete') button_class='btn-success' href=cmpurl icon='ok' %}
                        {% endif %}
                    </div>
                    </form>
                </div>
            </div>
        </div>
        {% if task %}
            <div class="col-sm-6">
                {% include 'taskapp/details.html' with task=task time_diff=time_diff %}
            </div>
            {% if perms.taskapp.view_extracomment %}
                <div class="col-sm-6">
                    {% include "taskapp/comments/task_comments.html" with comments=comments task_uid=task.pk comment_form=comment_form %}
                </div>
            {% endif %}
        {% endif %}
    </div>

{% endblock %}
