{%extends "admin/change_form.html"%}
{%load i18n admin_modify adminmedia%}
{%block extrastyle%}
    {{ block.super }}
    <link rel="stylesheet" href="{{MEDIA_URL}}scaffold/styles/scaffold-admin.css" type="text/css" media="screen"/>
    <link rel="stylesheet" href="{{MEDIA_URL}}scaffold/styles/jquery.ui.start/jquery.ui.css" type="text/css">   
{%endblock%}
{%block breadcrumbs%}{%if not is_popup%}
<div class="breadcrumbs">
    <a href="{%url admin:index%}">{% trans "Home" %}</a> &rsaquo; 
    <a href="{{app_index_url}}">{{app_label|capfirst|escape}}</a> &rsaquo;      
    <a href="{{changelist_url}}">{{model_label_plural|capfirst}}</a> &rsaquo;
    {%trans "Add"%} {{model_label}}
</div>
{%endif%}{%endblock%}
{%block content%}
<div id="content-main">
{%if parent%}
<p>{%trans "Belonging to the"%} {{model_label}} <em>{{parent.title}}</em></p>
{%endif%}
<form enctype="multipart/form-data" action="" method="post" id="{{ opts.module_name }}_form">
    {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
    {% csrf_token %}
    {% if errors %}
        <p class="errornote">
        {% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
        </p>
        {{ adminform.form.non_field_errors }}
    {% endif %}
    {% for fieldset in adminform %}
      {% include "admin/includes/fieldset.html" %}
    {% endfor %}

    {% block after_field_sets %}{% endblock %}

    {% for inline_admin_formset in inline_admin_formsets %}
        {% include inline_admin_formset.opts.template %}
    {% endfor %}

    {% block after_related_objects %}{% endblock %}
    {%if parent.has_children%}
    {%with parent.get_children as children%}
    <fieldset class="position-node ui-state-highlight ui-corner-all">
    <legend>Position New {{model_label|capfirst}}</legend>
    <p class="notice">The {{model_label}} that you're adding this new {{model_label}} to already has 
        {{children|pluralize:"a,some"}} sub-{{model_label}}{{children|pluralize}} 
    ({%for child in children%}<em>{{child.title}}</em>{%if not forloop.last%}, {%endif%}{%endfor%} ).
     How do you want to position this new section in relation to {{children|pluralize:"it,them"}}?</p>
    <label>Add this subsection 
        <select name="position">
            <option value="after">after</option>
            <option value="before">before</option>
        </select>
        the 
        <select name="child">
        {%for child in children%}
            <option value="{{child.pk}}"{%if forloop.last%} selected="true"{%endif%}>{{child.title}}</option>
        {%endfor%}
        </select> subsection.
    </label>
    </fieldset>
    {%endwith%}
    {%endif%}
    <div class="submit-row">
    <input type="submit" name="_continue" value="Save and continue editing">
    <input type="submit" name="_save" class="default" value="Save">
    </div>

    {% if adminform and add %}
       <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>
    {% endif %}    
</form>
</div>
{# JavaScript for prepopulated fields #}
{% prepopulated_fields_js %}
{%endblock%}
