{% extends "newman/change_form.html" %}
{% load newman_modify cache %}

{% spaceless %}
{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href="{% url newman:index %}#/nm/">{% trans "Home" %}</a>
    &rsaquo; <a class="js-hashadr" href="../../../">{% trans app_label.title %}</a>
    &rsaquo; {% if has_change_permission %}<a class="js-hashadr" href="../../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %}
    &rsaquo; {% trans "Categories" %}
    {% if title %}&rsaquo; <strong id="doc-title">{{ title }}</strong>{% endif %}
</div>
{% endblock %}

{% block content_toolbar %}{% endblock %}
{% block content_services %}{% endblock %}

{% block fieldsets %}
    {% if adminforms %}
        {% for adminform in adminforms %}
            {% for fieldset in adminform %}

                    <fieldset class="module aligned {{ fieldset.classes }}" style="width: 30%; float: left; overflow: auto; margin: 5px;">
                        <legend style="font-size: 120%; font-weight: bold;">{{ adminform.form.instance.name }}</legend>
                        <input type="hidden" name="{{ adminform.form.prefix }}-name" value="{{ adminform.form.instance.name }}"/>
                        <input type="hidden" name="{{ adminform.form.prefix }}-category" value="{{ adminform.form.instance.category.pk }}"/>
                        <input type="hidden" name="{{ adminform.form.prefix }}-box_type" value="{{ adminform.form.instance.box_type }}"/>
                        <input type="hidden" name="{{ adminform.form.prefix }}-text" value="{{ adminform.form.instance.text }}"/>

                        <div style="font-weight: bold; padding: 3px 3px 3px 20px; margin: 3px 0; background: url({{ NEWMAN_MEDIA_URL }}ico/ct/16/{{ adminform.form.instance.target_ct.name|lower }}.png) 0 50% no-repeat;">
                        {% if adminform.form.instance.target %}
                            <span style="">
                                {{ adminform.form.instance.target }}
                            </span>
                        {% else %}
                            -- empty pos --
                        {% endif %}
                        </div>

                        <div class="form-row">
                            <div class="form-row-field field-box">
                                {{ adminform.form.target_ct.label_tag }}
                                {{ adminform.form.target_ct }}
                            </div>

                            <div class="form-row-field field-box">
                                {{ adminform.form.target_id.label_tag }}
                                {{ adminform.form.target_id }}
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-row-field field-box">
                                {{ adminform.form.active_from.label_tag }}
                                {{ adminform.form.active_from }}
                            </div>

                            <div class="form-row-field field-box">
                                {{ adminform.form.active_till.label_tag }}
                                {{ adminform.form.active_till }}
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-row-field">
                                {{ adminform.form.disabled }}
                                {{ adminform.form.disabled.label }}
                            </div>
                        </div>

                        {% comment %}
                        {% for line in fieldset %}
                            <div class="form-row{% if line.errors %} errors{% endif %} {% for field in line %}{{ field.field.name }} {% endfor %} ">
                                {{ line.errors }}
                                {% for field in line %}
                                <div class="form-row-field{% if not line.fields|length_is:"1" %} field-box{% endif %}{% if field.field.field.hint_text %} hint-enhanced{% endif %}{% if field.field.field.help_text %} help-enhanced{% endif %}">
                                    {% if field.is_checkbox %}{{ field.field }}{{ field.label_tag }}
                                    {% else                 %}{{ field.label_tag }}{{ field.field }}
                                    {% endif %}
                                    {% if field.field.field.hint_text %}<p class="hint">{{ field.field.field.hint_text|safe }}</p>{% endif %}
                                    {% if field.field.field.help_text %}<p class="help">{{ field.field.field.help_text|safe }}</p>{% endif %}
                                </div>
                                {% endfor %}
                            </div>
                        {% endfor %}
                        {% endcomment %}

                    </fieldset>

            {% endfor %}
        {% endfor %}
    {% else %}
        <p>{% trans "This category doesn't have any positions, or they aren't registered for multiple editation" %}</p>
    {% endif %}

    <div class="js-form-metadata">
        <input type="hidden" name="post_save" id="swim-2-levels-up" />
        <script type="text/javascript">
            $('#swim-2-levels-up').data('callback', function() {
                return { _save_: function() { adr('../../'); } };
            });
        </script>
    </div>

{% endblock %}

{% block content_js %}
    {% cache 300 'nm-cf-pos-js' adminforms %}
    {% if media %}
        <script type="text/javascript">
        {% for m in media %}
        request_media('{{ m }}');
        {% endfor %}
        </script>
    {% endif %}

    {% endcache %}
{% endblock %}
{% endspaceless %}
