{% extends 'core/page.html' %}
{% load static %}
{% load compress %}
{% load i18n %}
{% load core_tags %}

{% block head %}
    {% vendor 'angular' %}
    {% vendor 'codemirror' %}
    {% vendor 'select2' %}
    {% vendor 'select2-bootstrap-theme' %}

    {% compress css %}
    <link rel="stylesheet" type="text/x-scss" href="{% static 'tasks/css/tasks.scss' %}" />
    {% endcompress %}

    {% compress js %}
    <script type="text/javascript" src="{% static 'core/js/core.js' %}" ></script>
    <script type="text/javascript" src="{% static 'tasks/js/tasks.js' %}" ></script>
    {% endcompress %}
{% endblock %}

{% block bodyattr %} ng-app="tasks" ng-controller="TasksController" {% endblock %}

{% block sidebar %}

    <h2>{% trans 'Filter tasks' %}</h2>

    <div class="form-group">
        <div class="input-group">
            <input type="text" class="form-control" ng-model="service.filter"
                   placeholder="{% trans 'Search' %}"></input>
            <span class="input-group-btn" ng-click="service.filter = ''">
                <button class="btn btn-default">
                    <span class="fa fa-times"></span>
                </button>
            </span>
        </div>
    </div>

    <div class="form-group">
        <select class="form-control" ng-model="service.uri_prefix">
            <option value="">{% trans 'All URI prefixes' %}</option>
            <option ng-repeat="uri_prefix in service.uri_prefixes" value="{$ uri_prefix $}">
                {$ uri_prefix $}
            </option>
        </select>
    </div>

    <h2>{% trans 'Options' %}</h2>

    <ul class="list-unstyled">
        <li>
            <a href="" ng-click="service.openFormModal('tasks', null, true)">
                {% trans 'Create new task' %}
            </a>
        </li>
    </ul>

    <h2>{% trans 'Export' %}</h2>

    <ul class="list-unstyled">
        {% for format, text in export_formats %}
        <li >
            <a href="{% url 'tasks_export' format %}" target="_blank">
                {{ text }}
            </a>
        </li>
        {% endfor %}
    </ul>

    <ul class="list-unstyled">
        <li >
            <a href="{% url 'tasks_export' 'xml' %}" target="_blank">
                {% trans 'XML' %}
            </a>
        </li>
    </ul>

    <h2>{% trans 'Import' %}</h2>
    <ul class="list-unstyled">
        <li>
            {% url 'upload' as upload_url %}
            {% include 'core/upload_form.html' with upload_url=upload_url %}
        </li>
    </ul>

{% endblock %}

{% block page %}

    <h1>{% trans 'Tasks' %}</h1>

    <div ng-repeat="task in service.tasks | orderBy: 'title'" ng-cloak>

        <div class="panel panel-default" ng-hide="service.hideTask(task)">

            <div class="panel-heading">
                <div class="pull-right">
                    <span class="fa fa-warning text-warning"
                        title="{% trans 'Some languages are not configured' %}"
                        ng-show="task.warning"></span>

                    <i class="fa fa-lock text-danger" ng-show="task.locked"></i>

                    <a href="" class="fa fa-pencil"
                        title="{% trans 'Update task' %}"
                        ng-click="service.openFormModal('tasks', task)">
                    </a>
                    <a href="" class="fa fa-copy"
                        title="{% trans 'Copy task' %}"
                        ng-click="service.openFormModal('tasks', task, false, true)">
                    </a>
                    <a href="" class="fa fa-question-circle"
                        title="{% trans 'Update conditions' %}"
                        ng-click="service.openFormModal('conditions', task)">
                    </a>
                    <a href="" class="fa fa-clock-o"
                        title="{% trans 'Update time frame' %}"
                        ng-click="service.openFormModal('timeframes', task)">
                    </a>
                    <a href="{$ task.xml_url $}" class="fa fa-download"
                        title="{% trans 'Export task as XML' %}"
                        target="blank">
                    </a>
                    <a href="" class="fa fa-trash"
                        title="{% trans 'Delete task' %}"
                        ng-click="service.openDeleteModal('tasks', task)">
                    </a>
                </div>
                <strong>{% trans 'Task' %}</strong>
                <code class="code-tasks">{$ task.uri $}</code>
            </div>

            <ul class="list-group">
                <li class="list-group-item">
                    <p><strong>{$ task.title $}</strong></p>
                    <p ng-bind-html="task.text_html"></p>
                </li>
            </ul>

            {% if settings.MULTISITE %}
            <div class="panel-footer">
                <strong>{% trans 'Sites'%}</strong>
                <span ng-show="task.sites.length" ng-repeat="site in task.sites">
                    {$ site.name $}{$ $last ? '' : ', ' $}
                </span>
                <span ng-hide="task.sites.length">
                    {% trans 'all' %}
                </span>
            </div>
            {% endif %}
        </div>
    </div>

    {% include 'tasks/tasks_modal_form_tasks.html' %}
    {% include 'tasks/tasks_modal_form_timeframes.html' %}
    {% include 'tasks/tasks_modal_form_conditions.html' %}

    {% include 'tasks/tasks_modal_delete_tasks.html' %}

{% endblock %}
