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



{% block js %}
    {{ block.super }}


    $('#data-content div.product_photo br').remove();
    $('#photo-clear_id,#id_photo').removeClass('form-control');


    
    var html='<tr><th>{% trans "属性名" %}</th>'+
        '<th>{% trans "属性值" %}</th>'+
        '<th>{% trans "单位" %}</th>'+
        '<th>{% trans "备注" %}</th></tr>';
    var s='',sel='', sSel='';
    {% for p in props %}
        s='';
        sel='<select class="form-control prd_props" name="pro_id_{{forloop.counter}}">';
        {% for o in p.ops %}
            sSel='';
            {% ifequal p.pro_id o.0 %}
                sSel='selected="selected"';
            {% endifequal %}
             s = s + '<option value="{{o.0}}" '+sSel+'>{{o.1}}</option>';
        {% endfor %};
        sSel='';
        {% ifequal p.pro_id '' %}
            sSel=' selected="selected"';
        {% endifequal %}
        s=s+'<option value=""  '+sSel+'>-------------</option>';
        sel=sel+s+'</select>';
        html = html + '<tr><input type="hidden" name="rec_id_{{forloop.counter}}" value="{{p.rec_id}}">'+
                '<td>{{ p.label }}</td>'+
                '<td>'+sel+'</td>'+
                '<td>{{ p.unit }}</td>'+
                '<td><input class="form-control" value="{{ p.remark|default_if_none:''}}" name="remark_{{forloop.counter}}" > </td>'+
            '</tr>';
    {% endfor %}
    $('#tb_props tbody').html(html);
    $('#tb_props').append('<input type="hidden" name="rec_cnt" value="{{ props|length }}">');

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


    $('#obj_form .product_photo a').click(function(event){      
        event.preventDefault();
        var src=$(this).attr('href');
        var i="<div style='text-align:center;'><img src='"+src+"' style='height:400px;'></img></div>";
        $.OpenCfmDlg($('#id_name').val(),i);                   
    });
{% endblock %}

{% block subtitle-1 %}
        {% trans "产品管理" %}
{% endblock %}
{% block subtitle-2 %}
        {% trans "产品名称" %}
{% endblock %}


{% 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 %}

    {% if has_series %}
        <div class="form-group ">
            <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'series' %} </label>
            <div class="col-sm-10">{{ form.series }}</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 ">{% get_verbose_field_name form.instance 'price' %} </label>
            <div class="col-sm-10">{{ form.price }}</div>
    </div>
    
   

    <div class="form-group ">
        <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'remark' %} </label>
        <div class="col-sm-10">{{ form.remark|default_if_none:'' }}</div>
    </div>

     <div class="form-group product_photo">
            <label class="col-sm-2 control-label ">{% get_verbose_field_name form.instance 'photo' %} </label>
            <div class="col-sm-10">{{ form.photo }}</div>
    </div>
    
    <div>
        <table id='tb_props' class="table table-condensed table-responsive table-bordered table-hover"><tbody></tbody></table>
    </div>
    <div>
        <a class="btn btn-primary btn-save" type="submit" style="float:right;">{% trans '保存' %}</a>
    </div>
{% endblock %}
