{% extends "admin/change_form.html" %}
{% load i18n admin_modify adminmedia %}

{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}

{% block extrahead %}{{ block.super }}
{% if FEINCMS_ADMIN_MEDIA_HOTLINKING %}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
{% else %}
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}ui/jqueryui-custom-1.7.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="{{ FEINCMS_ADMIN_MEDIA }}ui/jqueryui-custom-1.7.2.css" />
{% endif %}

<link rel="stylesheet" type="text/css" href="{{ FEINCMS_ADMIN_MEDIA }}style.css" />
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery.alerts.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}item_editor.js"></script>

<script type="text/javascript">
    {% include "admin/feincms/_messages.html" %}
    IMG_DELETELINK_PATH = "{{ FEINCMS_ADMIN_MEDIA }}img/icon_deletelink.gif";
    REGION_MAP = [{% for region in object.template.regions %}'{{ region.key }}'{% if not forloop.last %}, {% endif %}{% endfor %}];
    ACTIVE_REGION = 0;
    CONTENT_NAMES = {
        {% for name, value in content_types %}'{{ value }}': '{{ name|capfirst }}'{% if not forloop.last %},{% endif %}
        {% endfor %}};
    var contentblock_init_handlers = [];

    var template_regions = {
            {% for template in available_templates.values %}'{{ template.key }}': [{% for region in template.regions %}'{{ region.key }}'{% if not forloop.last %}, {% endif %}{% endfor %}]{% if not forloop.last %},{% endif %}
            {% endfor %}};
</script>

{% for inc in object.feincms_item_editor_includes.head %}{% include inc %}{% endfor %}

<script type="text/javascript">
    $(document).ready(function(){
        {% block extra-init-js %}{# /* do not use this block, use feincms_item_editor_includes instead */ #}{% endblock %}
    });
</script>
{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
     <a href="../../../">{% trans "Home" %}</a> &rsaquo;
     <a href="../../">{{ opts.app_label|capfirst|escape }}</a> &rsaquo;
     <a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
     {{ object.title|truncatewords:"18" }}
</div>
{% endblock %}

{% block content %}

<div id="content-main">

{% block object-tools %}
<ul class="object-tools">
    {% if object.get_preview_url %}
        <li><a target="_blank" href="{{ object.get_preview_url }}" class="viewsitelink">{% trans "Preview" %}</a></li>
    {% endif %}
    {% if object.get_absolute_url %}
        <li><a target="_blank" href="{{ object.get_absolute_url }}" class="viewsitelink">{% trans "View on site" %}</a></li>
    {% endif %}
</ul>
{% endblock %}

<form name="main_form" enctype="multipart/form-data" action="." method="post" id="{{ opts.module_name }}_form">
<div>

<div class="submit-row" >
<input type="submit" value="{% trans "Save" %}" class="default" name="_save" />
<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>

<input type="submit" value="{% trans "Save and add another" %}" name="_addanother"  />
<input type="submit" value="{% trans "Save and continue editing" %}" name="_continue" />
</div>

{% if errors %}
    <p class="errornote">
    {% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
    </p>
    <ul class="errorlist">{% for error in object_form.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
{% endif %}

<fieldset class="module aligned">
    {% for field in top_fields %}
    <div class="form-row{% if field.errors %} errors{% endif %}">
        {% ifequal field.name "language" %}
            {# Maybe this should be moved somewhere else, since this is specific for translated objects... #}
            {% with object.available_translations as translations %}
            {% if translations %}
                <div style="float:right;padding:5px 0 0 0">
                {% trans "available translations" %}:
                {% for translation in translations %}
                    <a href="../{{ translation.id }}/" title="{{ translation }}">{{ translation.language|upper }}</a>{% if not forloop.last %},{% endif %}
                {% endfor %}
                </div>
            {% endif %}
            {% endwith %}
        {% endifequal %}

        {{ field.errors }}
        <label for="{{ field.auto_id }}"{% if field.field.required %} class="required"{% endif %}>{{ field.label }}</label>{{ field }}
        {% if field.field.help_text %}<p class="help">{{ field.field.help_text|safe }}</p>{% endif %}
    </div>
    {% endfor %}
</fieldset>

<div id="main_wrapper">
    {% for region in object.template.regions %}
        <div class="navi_tab" id="{{ region.key }}_tab">{{ region.title }}</div>
    {% endfor %}
    <div class="navi_tab" id="settings_tab">{% trans "Properties" %}</div>
    <div id="main">
        <fieldset class="module aligned" id="settings_body">
            {% for field in settings_fields %}
            <div class="form-row{% if field.errors %} errors{% endif %}">
                {{ field.errors }}
                <label for="{{ field.auto_id }}"{% if field.field.required %} class="required"{% endif %}>{{ field.label }}</label>{{ field }}
                {% if field.field.help_text %}<p class="help">{{ field.field.help_text|safe }}</p>{% endif %}
            </div>
            {% endfor %}
        </fieldset>

        {% for region in object.template.regions %}
        <div id="{{ region.key }}_body" class="panel">
            <div class="empty-machine-msg">
                {% trans "Region empty" %}
            </div>
            <div class="empty-machine-msg" style="margin-left:20px; margin-top:20px;">
                {% if region.inherited %}
                    {% trans "Content from the parent site is automatically inherited. To override this behaviour, add some content." %}
                {% endif %}
            </div>

            <div class="order-machine"></div>

            <div class="machine-control">
                <div class="control-unit">
                    <span>{% trans "Add new item" %}:</span> <br/>
                    <select name="order-machine-add-select">
                    {% for v,n in region.content_types %}<option value="{{ v }}">{{ n|capfirst }}</option> {% endfor %}
                    </select>
                    <input type="button" class="order-machine-add-button button" value="OK" />
                </div>
                {% ifnotequal object.template.regions|length 1 %}
                <div class="control-unit">
                    <span>{% trans "Move selected item to" %}:</span>  <br/>
                    <select name="order-machine-move-select">
                    {% for r in object.template.regions %}{% ifnotequal region r %}<option value="{{ r.key }}">{{ r.title|capfirst }}</option> {% endifnotequal %}{% endfor %}
                    </select>
                    <input type="button" class="order-machine-move-button button" value="{% trans "OK" %}" />
                </div>
                {% endifnotequal %}
            </div>
         </div>
        {% endfor %}
    </div>
</div>

<div class="submit-row" >
<input type="submit" value="{% trans "Save" %}" class="default" name="_save" />
<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>

<input type="submit" value="{% trans "Save and add another" %}" name="_addanother"  />
<input type="submit" value="{% trans "Save and continue editing" %}" name="_continue" />
</div>

<div id="inlines">
{% for formset in inline_formsets %}
    <div id="{{ formset.rel_name }}">
        <div class="header">
            {{ formset.management_form }}
        </div>
        {% for form in formset.forms %}
            <div id="{{ formset.rel_name }}_item_{{ forloop.counter0 }}">
                {% for field in form %}
                    {% if field.is_hidden %}
                        {{ field }}
                    {% else %}
                        <div class="form-row{% if field.errors %} errors{% endif %}">
                            {{ field.errors }}
                            <label for="{{ field.auto_id }}"{% if field.field.required %} class="required"{% endif %}>{{ field.label }}</label>{{ field }}
                            {% if field.field.help_text %}<p class="help">{{ field.field.help_text|safe }}</p>{% endif %}
                        </div>
                    {% endif %}
                {% endfor %}
            </div>
        {% endfor %}
    </div>
{% endfor %}
</div>

</div>
</form>

</div>
{% endblock %}

