{% load i18n %}
{% get_available_languages as languages %}

    <div class="modal" id="tasks-form-modal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" tabindex="-1">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h2 class="modal-title">
                        <span ng-hide="service.values.id">{% trans 'Create task' %}</span>
                        <span ng-show="service.values.copy">{% trans 'Copy task' %}</span>
                        <span ng-show="service.values.id && !service.values.copy">{% trans 'Update task' %}</span>
                    </h2>
                </div>

                <div class="modal-body">
                    <div class="copy-block" ng-show="service.values.copy">
                        <p>
                            {% trans 'Please enter the values for the copy of the task below and change at least the <strong>key</strong>.' %}
                        </p>
                        <p>
                            {% trans 'Other properties can be changed once the new task is created.' %}
                        </p>
                    </div>
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group" ng-class="{'has-error': service.errors.uri_prefix }">
                                <label class="control-label" for="uri_prefix">
                                    {{ meta.Task.uri_prefix.verbose_name }}
                                </label>

                                <div class="input-group">
                                    <input class="form-control"
                                           id="task_uri_prefix"
                                           type="text"
                                           ng-model="service.values.uri_prefix" />

                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default"
                                            title="{% trans 'Insert default URI Prefix' %}"
                                            ng-click="service.values.uri_prefix = service.settings.default_uri_prefix">

                                            <span class="fa fa-magic"></span>
                                        </button>
                                    </span>
                                </div>

                                <p class="help-block">
                                    {{ meta.Task.uri_prefix.help_text }}
                                </p>

                                <ul class="help-block list-unstyled" ng-show="service.errors.uri_prefix">
                                    <li ng-repeat="error in service.errors.uri_prefix">
                                        {$ error $}
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <formgroup
                                data-id="task_key"
                                data-type="text"
                                data-label="{{ meta.Task.key.verbose_name }}"
                                data-help="{{ meta.Task.key.help_text }}"
                                data-model="service.values.key"
                                data-errors="service.errors.key">
                            </formgroup>
                        </div>
                    </div>

                    <div ng-hide="service.values.copy">
                        <formgroup
                            data-id="task_comment"
                            data-type="textarea"
                            data-label="{{ meta.Task.comment.verbose_name }}"
                            data-help="{{ meta.Task.comment.help_text }}"
                            data-model="service.values.comment"
                            data-errors="service.errors.comment">
                        </formgroup>
                        <formgroup
                            data-id="task_locked"
                            data-type="checkbox"
                            data-label="{{ meta.Task.locked.verbose_name }}"
                            data-help="{{ meta.Task.locked.help_text }}"
                            data-model="service.values.locked"
                            data-errors="service.errors.locked">
                        </formgroup>
                        <div>
                            <ul class="nav nav-tabs" role="tablist">
                                <li role="presentation" class="active">
                                    <a class="control-label" href="#tasks-general"
                                        role="tab" data-toggle="tab" aria-controls="tasks-general">

                                        {% trans 'General' %}
                                    </a>
                                </li>
                                {% for lang_code, lang in languages %}
                                <li role="presentation" ng-class="{
                                    'has-error':
                                        service.errors.title_{{ lang_code }} ||
                                        service.errors.text_{{ lang_code }},
                                    'has-warning':
                                        service.values.id &&
                                        (!service.values.title_{{ lang_code }} ||
                                         !service.values.text_{{ lang_code }})
                                }">
                                    <a role="tab" class="control-label" data-toggle="tab"
                                        href="#tasks-{{ lang_code }}" aria-controls="tasks-{{ lang_code }}">

                                        {{ lang }}
                                        <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
                                    </a>
                                </li>
                                {% endfor %}
                                <li role="presentation" ng-class="{
                                    'has-error': service.errors.catalogs,
                                }">
                                    <a class="control-label" href="#tasks-catalogs"
                                        role="tab" data-toggle="tab" aria-controls="tasks-catalogs">

                                        {% trans 'Catalogs' %}
                                        <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
                                    </a>
                                </li>
                                <li role="presentation" ng-class="{
                                    'has-error': service.errors.groups,
                                }">
                                    <a class="control-label" href="#tasks-groups"
                                        role="tab" data-toggle="tab" aria-controls="tasks-groups">

                                        {% trans 'Groups' %}
                                        <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
                                    </a>
                                </li>
                                {% if settings.MULTISITE %}
                                <li role="presentation" ng-class="{
                                    'has-error': service.errors.sites,
                                }">
                                    <a class="control-label" href="#tasks-sites"
                                        role="tab" data-toggle="tab" aria-controls="tasks-sites">

                                        {% trans 'Sites' %}
                                        <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
                                    </a>
                                </li>
                                {% endif %}
                            </ul>
                            <div class="tab-content">
                                <div role="tabpanel" class="tab-pane active" id="tasks-general">
                                    <formgroup
                                        data-id="task_available"
                                        data-type="checkbox"
                                        data-label="{{ meta.Task.available.verbose_name }}"
                                        data-help="{{ meta.Task.available.help_text }}"
                                        data-model="service.values.available"
                                        data-errors="service.errors.available">
                                    </formgroup>
                                </div>
                                {% for lang_code, lang in languages %}
                                <div role="tabpanel" class="tab-pane" id="tasks-{{ lang_code }}">
                                    <formgroup
                                        data-id="task_title_{{ lang_code }}"
                                        data-type="text"
                                        data-label="{% trans 'Title' %} ({{ lang }})"
                                        data-help="{% trans 'The title for this task.' %}"
                                        data-model="service.values.title_{{ lang_code }}"
                                        data-errors="service.errors.title_{{ lang_code }}"
                                        data-warning="service.values.id && !service.values.title_{{ lang_code }}">
                                    </formgroup>
                                    <formgroup
                                        data-id="task_text_{{ lang_code }}"
                                        data-type="textarea"
                                        data-label="{% trans 'Text' %} ({{ lang }})"
                                        data-help="{% trans 'The text for this task.' %}"
                                        data-model="service.values.text_{{ lang_code }}"
                                        data-errors="service.errors.text_{{ lang_code }}"
                                        data-warning="service.values.id && !service.values.text_{{ lang_code }}">
                                    </formgroup>
                                </div>
                                {% endfor %}
                                <div role="tabpanel" class="tab-pane" id="tasks-catalogs">
                                    <formgroup
                                        data-id="task_catalogs"
                                        data-type="selectmultiple"
                                        data-label="{% trans 'Catalogs' %}"
                                        data-model="service.values.catalogs"
                                        data-errors="service.errors.catalogs"
                                        data-options="service.catalogs"
                                        data-options-label="title"
                                        data-help="{% trans 'Hold down Control, or Command on a Mac, to select more than one.' %} {% trans 'An empty list implies that the task can be used with every catalog.' %}">
                                    </formgroup>
                                </div>
                                <div role="tabpanel" class="tab-pane" id="tasks-groups">
                                    <formgroup
                                        data-id="task_groups"
                                        data-type="selectmultiple"
                                        data-label="{% trans 'Groups' %}"
                                        data-model="service.values.groups"
                                        data-errors="service.errors.groups"
                                        data-options="service.groups"
                                        data-options-label="uri"
                                        data-help="{% trans 'Hold down Control, or Command on a Mac, to select more than one.' %}">
                                    </formgroup>
                                </div>
                                {% if settings.MULTISITE %}
                                <div role="tabpanel" class="tab-pane" id="tasks-sites">
                                    <formgroup
                                        data-id="task_sites"
                                        data-type="selectmultiple"
                                        data-label="{% trans 'Sites' %}"
                                        data-model="service.values.sites"
                                        data-errors="service.errors.sites"
                                        data-options="service.sites"
                                        data-options-label="uri"
                                        data-help="{% trans 'Hold down Control, or Command on a Mac, to select more than one.' %}">
                                    </formgroup>
                                </div>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        {% trans 'Close' %}
                    </button>
                    <button type="button" class="btn btn-primary"
                            ng-click="service.submitFormModal('tasks')">
                        {% trans 'Save' %}
                    </button>
                </div>
            </div>
        </div>
    </div>
