{% extends 'dashboard/layout.html' %}
{% load i18n %}
{% load currency_filters %}

{% block body_class %}catalogue{% endblock %}

{% block title %}
{% trans "Update product" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
        <a href="{% url dashboard:index %}">{% trans "Dashboard" %}</a>
        <span class="divider">/</span>
    </li>
    <li>
        <a href="{% url dashboard:catalogue-product-list %}">{% trans "Catalogue" %}</a>
        <span class="divider">/</span>
    </li>
    <li class="active"><a href=".">{{ title }}</a></li>
</ul>
{% endblock %}

{% block header %}
<div class="page-header">
<h1>{{ title }}</h1>
</div>
{% endblock header %}

{% block dashboard_content %}
<form action="." method="post" class="product-new form-horizontal wysiwyg" enctype="multipart/form-data">
{% csrf_token %}
    <div class="well well-blank product-details">
        <div class="sub-header">
            <h3>{% trans "Product Details" %}</h3>
        </div>
        <span class="help-block">{{ form.non_field_errors }}</span>
        {% for field in form %}
            {% if field.is_hidden %}
                {{ field }}
            {% endif %}
        {% if 'attr' not in field.id_for_label %}
        <div class="control-group {% for error in field.errors %}error{% endfor %}">
            {% if field.is_hidden %}
                {{ field }}
            {% else %}
            <label for="{{ field.auto_id }}" class="control-label {% if field.field.required %}required{% endif %}">{{ field.label }}{% if field.field.required %} <span>*</span>{% endif %}</label>
            <div class="controls">
                {{ field }}
                {% for error in field.errors %}
                <span class="help-block">
                    {{ error }}
                </span>
                {% endfor %}
                {% if field.help_text %}
                <span class='help-block'>
                    {{ field.help_text }}
                </span>
                {% endif %}
            </div>
            {% endif %}
        </div>
        {% endif %}
        {% endfor %}
    </div>
    <div class="well well-blank">
        <div class="sub-header">
            <h3>{% trans "Product Attributes" %}</h3>
        </div>
        <div class="control-group">
            <label class="control-label">{% trans "Product class" %}</label>
            <div class="controls">
                <select id="select01">
                    <option>{{ product.product_class }}</option>
                </select>
            </div>
        </div>
        {% for field in form %}
            {% if 'attr' in field.id_for_label %}
            <div class="control-group {% for error in field.errors %}error{% endfor %}">
                {% if field.is_hidden %}
                {{ field }}
                {% else %}
                <label for="{{ field.auto_id }}" class="control-label {% if field.field.required %}required{% endif %}">{{ field.label }}{% if field.field.required %} <span>*</span>{% endif %}</label>
                <div class="controls">
                    {{ field }}
                    {% for error in field.errors %}
                    <span class="help-block">
                        {{ error }}
                    </span>
                    {% endfor %}
                    {% if field.help_text %}
                    <span class='help-block'>
                        {{ field.help_text }}
                    </span>
                    {% endif %}
                </div>
                {% endif %}
            </div>
            {% endif %}
        {% endfor %}
    </div>

    <div class="well well-blank form-inline">
        <div class="sub-header">
            <h3>{% trans "Category" %}</h3>
        </div>
        {{ category_formset.management_form }}
		{{ category_formset.non_form_errors }}
        {% for category_form in category_formset %}
            {% include "partials/form_fields_inline.html" with form=category_form %}
        {% endfor %}
    </div>
</div>

<div class="well well-blank">
    <div class="sub-header">
        <h3>{% trans "Upload, change or remove images" %}</h3>
    </div>
    {{ image_formset.management_form }}
    {{ image_formset.non_form_errors }}
    <ol class='upload-image'>
        {% for image_form in image_formset %}
            {% include "dashboard/partials/product_images.html" with form=image_form %}
        {% endfor %}
    </ol>
</div>
<div class="well well-blank fields-full stock-pricing">
    <div class="sub-header">
        <h3>{% trans "Stock and price information" %}</h3>
    </div>
    {{ stockrecord_form.non_field_errors }}
    <div class="row-fluid">
        <div class="span3">
            <h4>{% trans "Partner" %}</h4>
            {% for field in stockrecord_form %}
                {% if "partner" in field.id_for_label %}
                    {% include "dashboard/partials/stock_info.html" %}
                {% endif %}
            {% endfor %}
        </div>
        <div class="span3">
            <h4>{% trans "Price" %}</h4>
            {% for field in stockrecord_form %}
                {% if "price" in field.id_for_label %}
                    {% include "dashboard/partials/stock_info.html" %}
                {% endif %}
            {% endfor %}
        </div>
        <div class="span3">
            <h4>{% trans "Stock levels" %}</h4>
            {% for field in stockrecord_form %}
                {% if "stock" in field.id_for_label %}
                    {% include "dashboard/partials/stock_info.html" %}
                {% endif %}
            {% endfor %}
        </div>
    </div>
</div>
<hr/>
<div class="control-group">
    <div class="pull-right">
        <a href="{% url dashboard:catalogue-product-list %}">{% trans "Cancel" %}</a> {% trans "or" %} <button class="btn btn-primary btn-large" type="submit">{% trans "Save Product" %}</button>
    </div>
    {% if product %}
        <a class="btn btn-success btn-large" href="{{ product.get_absolute_url }}">{% trans "View on site" %}</a>
    {% endif %}
</div>
</form>
{% endblock dashboard_content %}
