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

    <div class="modal" id="views-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">
                        {% trans 'View' %}
                    </h2>
                </div>

                <div class="modal-body">
                    <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.View.uri_prefix.verbose_name }}
                                </label>

                                <div class="input-group">
                                    <input class="form-control"
                                           id="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.View.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="key"
                                data-type="text"
                                data-label="{{ meta.View.key.verbose_name }}"
                                data-help="{{ meta.View.key.help_text }}"
                                data-model="service.values.key"
                                data-errors="service.errors.key">
                            </formgroup>
                        </div>
                    </div>
                    <formgroup
                        data-id="comment"
                        data-type="textarea"
                        data-label="{{ meta.View.comment.verbose_name }}"
                        data-help="{{ meta.View.comment.help_text }}"
                        data-model="service.values.comment"
                        data-errors="service.errors.comment">
                    </formgroup>

                    <div>
                        <ul class="nav nav-tabs" role="tablist">
                            {% for lang_code, lang in languages %}
                            <li role="presentation" class="{{ forloop.first|yesno:'active,' }}" ng-class="{
                                'has-error':
                                    service.errors.title_{{ lang_code }} ||
                                    service.errors.help_{{ lang_code }},
                                'has-warning':
                                    service.values.id && !service.values.title_{{ lang_code }}
                            }">
                                <a role="tab" class="control-label" data-toggle="tab"
                                    href="#views-{{ lang_code }}" aria-controls="views-{{ lang_code }}">

                                    {{ lang }}
                                    <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
                                </a>
                            </li>
                            {% endfor %}
                        </ul>
                        <div class="tab-content">
                            {% for lang_code, lang in languages %}
                            <div role="tabpanel" id="views-{{ lang_code }}"
                                class="tab-pane {{ forloop.first|yesno:'active,' }}">

                                <formgroup
                                    data-id="title_{{ lang_code }}"
                                    data-type="text"
                                    data-label="{% trans 'Title' %} ({{ lang }})"
                                    data-help="{% trans 'The title for this view.' %}"
                                    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="help_{{ lang_code }}"
                                    data-type="textarea"
                                    data-label="{% trans 'Help' %} ({{ lang }})"
                                    data-help="{% trans 'The help text for this view.' %}"
                                    data-model="service.values.help_{{ lang_code }}"
                                    data-errors="service.errors.help_{{ lang_code }}">
                                </formgroup>
                            </div>
                            {% endfor %}
                        </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('views')">
                        {% trans 'Save' %}
                    </button>
                </div>
            </div>
        </div>
    </div>
