{% extends 'obj_form.html' %}
{% load i18n %}
{% load tj_filters %}


    {% block js %}
        {{ block.super }}
        $('.btn-save').click(function(){
            $.SubmitForm('#obj_form form','{{request.path}}');
        });


        $('#keeper_label').autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: '/obj/ajax/autocomplete/user/',
                    dataType: "json",
                    data: {
                        term:   $("#keeper_label").val() ,//搜索栏里的内容
                        company_id:  $('#co').val() ,//额外参数
                    },
                    success: function(data) {
                        response(data);
                    }
                });
            },
            select: function (event, ui) {
                $("#id_keeper").val(ui.item.value);
                $("#keeper_label").val(ui.item.label);  
                return false;
            }
        });

        {% if form.instance.id %}
            $("#id_keeper").val('{{form.instance.keeper.id}}');
            $("#keeper_label").val('{{form.instance.keeper.username}}');            
        {% endif %}


    {% endblock %}


    {% block subtitle-1 %}
        {% trans "公司管理" %}
    {% endblock %}
    {% block subtitle-2 %}
        {% trans "仓库" %}
    {% endblock %}

    <span style="margin-left:10px; color:green; ">
        {% block subtitle-3 %}
            {% if form.instance.id %}
                {% trans "修改" %}
            {% else %}
                {% trans "新建" %}
            {% endif %}
        {% endblock %}
{#        {% if form.instance.id %}#}
{#            {% block subtitle-3 %}#}
{#                {% trans "修改" %}#}
{#            {% endblock %}#}
{#        {% else %}#}
{#            {% block subtitle-3 %}#}
{#                {% trans "新建" %}#}
{#            {% endblock %}#}
{#        {% endif %}#}
    </span>



{% block form_content %}
    {{ block.super }}
    {% if form.instance.company.has_external_code %}
        <div class="form-group ">
            <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'external_code' %}</label>
            <div class="col-sm-10">{{ form.external_code }}</div>
        </div>
    {% endif %}
    <div class="form-group ">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'name' %} </label>
        <div class="col-sm-10">{{ form.name }}</div>
    </div>

    <div class="form-group ">
        <label class="col-sm-2 control-label ">库房管理员</label>
        <div class="col-sm-10"><input type="text" class="form-control"  id="keeper_label" ></div>
    </div>
    <div class="form-group ">
        <label class="col-sm-2 control-label ">仓库地址</label>
        <div class="col-sm-10">{{ form.address }}</div>
    </div>
    <div class="form-group ">
        <label class="col-sm-2 control-label ">联系人</label>
        <div class="col-sm-10">{{ form.contact }}</div>
    </div>
    <div class="form-group ">
        <label class="col-sm-2 control-label ">联系电话</label>
        <div class="col-sm-10">{{ form.cellphone }}</div>
    </div>
    

    
    <div class="form-group ">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'inv_type' %} </label>
        <div class="col-sm-10">{{ form.inv_type }}</div>
    </div>
    <div>
        <a class="btn btn-primary btn-save" type="button" style="float:right;">{% trans '保存' %}</a>
    </div>
{% endblock %}
