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

{% block title %}
    {{ title }} | {% trans "Accounts" %} | {{ 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 'accounts-list' %}">{% trans "Accounts" %}</a>
            <span class="divider">/</span>
        </li>
        {% if account %}
            <li>
                <a href="{% url 'accounts-detail' account.id %}">{{ account }}</a>
                <span class="divider">/</span>
            </li>
            <li class="active">{% trans "Update" %}</li>
        {% else %}
            <li class="active">{% trans "Create" %}</li>
        {% endif %}
    </ul>
{% endblock %}

{% block headertext %}{{ title }}{% endblock %}

{% block dashboard_content %}

    {% if account %}
        {% include 'accounts/dashboard/partials/account_detail.html' %}
        <h2>{% trans "Edit this account" %}</h2>
    {% endif %}

    <form class="form-stacked" action="." method="post">
        {% csrf_token %}
        <span class="help-block">{{ form.non_field_errors }}</span>
        {% include 'partials/form_field.html' with field=form.name %}
        {% include 'partials/form_field.html' with field=form.description %}
        {% if form.account_type %}
            {% include 'partials/form_field.html' with field=form.account_type %}
        {% endif %}

        {% if form.initial_amount %}
            <legend>{% trans "Initial transaction" %}</legend>
            {% if form.source_account %}
                {% include 'partials/form_field.html' with field=form.source_account %}
            {% endif %}
            {% include 'partials/form_field.html' with field=form.initial_amount %}
        {% endif %}

        <legend>{% trans "Restrictions" %}</legend>
        <h4>{% trans "Restrict WHEN the account can be used" %}</h4>
            {% include 'partials/form_field.html' with field=form.start_date %}
            {% include 'partials/form_field.html' with field=form.end_date %}
        <h4>{% trans "Restrict WHO can use the account" %}</h4>
            {% include 'partials/form_field.html' with field=form.primary_user %}
            {% include 'partials/form_field.html' with field=form.secondary_users %}
        <h4>{% trans "Restrict WHAT can be bought" %}</h4>
            {% include 'partials/form_field.html' with field=form.product_range %}
            {% include 'partials/form_field.html' with field=form.can_be_used_for_non_products %}

        <div class="form-actions">
            <button class="btn btn-primary btn-large" type="submit">{% trans "Save" %}</button>
            {% trans "or" %}
            <a href="{% url 'accounts-list' %}">{% trans "cancel" %}</a>
        </div>
    </form>

{% endblock dashboard_content %}

{% block onbodyload %}
    {{ block.super }}
    $('a.form-toggle').click(function(){
        $($(this)[0].parentNode.nextElementSibling).toggle();
        // Bind datepicker
        oscar.dashboard.init();
        return false;
    });
{% endblock %}
