{% load i18n %}


<script type="text/javascript">
    $(document).ready(function(){
        
        $('#id_user').val('{{form.instance.user.id}}');
        $("#label_user").val('{{form.instance.user.username}}');
        $('#label_user').autocomplete({           
            source: function(request, response) {
                $.ajax({
                    url: '/obj/ajax/autocomplete/user/',
                    dataType: "json",
                    data: {
                        term:   $("#label_user").val() ,//搜索栏里的内容
                        company_id:  {{request.user.ancestor_id}} ,//额外参数
                    },
                    success: function(data) {
                        response(data);
                    }
                });
            },
            select: function (event, ui) {                
                $("#id_user").val(ui.item.value);
                $("#label_user").val(ui.item.label);                
                return false;
            }
        });   
		 
        {% if choose_last_name %}
			$("#id_name").val('{{form.instance.name}}');
			$("#label_name").val('{{form.instance.name}}');
			$('#label_name').autocomplete({           
				source: function(request, response) {
					$.ajax({
						url: '/obj/ajax/autocomplete/user_last_name/',
						dataType: "json",
						data: {
							term:   $("#label_name").val() ,//搜索栏里的内容
							company_id:  {{request.user.ancestor_id}} ,//额外参数
						},
						success: function(data) {
							response(data);
						}
					});
				},
				select: function (event, ui) {     
					$("#id_user").val(ui.item.value); 
					$("#label_name").val(ui.item.label);
					$("#id_name").val(ui.item.label);
					return false;
				}
			}); 
		{% endif %}


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


			


        $('.btn-confirm').removeAttr("style",""); 
        $('.btn-confirm').unbind('click').bind('click',function(){    
            $(this).hide();
            $('form').ajaxSubmit({
                type: 'post',
                url: '{{request.path}}',    
                success: function(html) {
                    $('form').html(html);         
                        
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');                        
                }                    
            });
            return; // 阻止表单自动提交事件  
        }).show();

        



        
        {% if is_saved %}   
            $('#confirm-url-modal').modal('hide');                 
            var url=$('#list-tt').attr('current');
            $.ajax({
                type:'GET',
                processData: false,
                contentType: 'application/json; charset=utf-8',
                url:url,
                success: function (html) { 
                    $('#div-list').html(html);                    
                    return;
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                    return;
                }
            });
            
        {% endif %}
       
    });
</script>
<style>
    .ui-autocomplete { z-index: 215000000 !important; }
</style>

   
<div class="row">    
    <form role="form" method='POST' class="form-horizontal">    
        {% if messages %}
            {% for message in messages %}
                <div class="alert {% if message.tags %} alert-{{ message.tags }}{% endif %}">{{ message|safe }}</div>
            {% endfor %}
        {% endif %}
        {% if form.errors %}
            <div class="alert alert-error">
                <h4>{% trans '数据输入有错误,请先改正以下错误:' %}</h4>
                <ul>
                    {% for field in form %}
                        {% if field.errors %}
                            {% for error in field.errors %}
                                <li class="error">{{ field.label}}: {{ error|escape }}</li>
                            {% endfor %}
                        {% endif %}
                    {% endfor %}
                </ul>
                {% if form.non_field_errors %}
                    {{ form.non_field_errors }}
                {% endif %}
            </div>
        {% endif %}
        {% for hidden_field in form.hidden_fields %}
            {{ hidden_field }}
        {% endfor %}      
		
		
        {% if choose_last_name %}
		<div class="form-group ">
            <label class="col-sm-2 control-label ">{% trans '员工姓名:' %} </label>
            <div class="col-sm-10"><input id='label_name' class='form-control' /><input type="text" name="name" maxlength="20" class="form-control" required="" id="id_name" style="display:none"></div>
        </div> 
		
		{% else %}
        <div class="form-group ">
            <label class="col-sm-2 control-label ">{% trans '员工姓名(帐号):' %} </label>
            <div class="col-sm-10">{{ form.name }}</div>
        </div> 
        <div class="form-group ">
            <label class="col-sm-2 control-label ">{% trans '登录账号:' %} </label>
            <div class="col-sm-10"><input id='label_user' class='form-control' /></div>
        </div> 
		
        {% endif %}

        
         <div class="form-group ">
            <label class="col-sm-2 control-label ">{% trans '所在部门:' %} </label>
            <div class="col-sm-10"><input id='label_department' class='form-control' /></div>
        </div>   
        <div class="form-group ">
            <label class="col-sm-2 control-label ">{% trans '岗位职务:' %} </label>
            <div class="col-sm-10">{{ form.position }}</div>
        </div>   
        <div class="form-group ">
            <label class="col-sm-2 control-label ">{% trans '部门负责人:' %} </label>
            <div class="col-sm-10">{{form.is_department_head}}</div>
        </div>           
        
        <div class="form-group ">
            <label class="col-sm-2 control-label ">{% trans '手机电话:' %} </label>
            <div class="col-sm-10">{{ form.cellphone }}</div>
        </div>   
        <div class="form-group ">
            <label class="col-sm-2 control-label ">{% trans '备注说明:' %} </label>
            <div class="col-sm-10">{{form.remark}}</div>
        </div>
        
        
   
    </form>
</div>

