{% load i18n %}


<script type="text/javascript">
    $(document).ready(function(){
        
        $('#subdivision').val('{{form.instance.sub_division.id}}');
        $("#label_parent").val('{{form.instance.parent.name}}');  
        
        

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

        $('#id_division').change(function(){
            var me=$('#subdivision');
            var d=$(this).val();
            $(me).empty();
            if (d!=''){
                $.ajax({
                    url: "/company/json/subdivision/"+d+"/",
                    success: function(data) {
                        data=data.details;
                        $.each(data,function(i,d){$(me).append("<option value='"+d[0]+"'>"+d[1]+"</option>")});
                        $(me).append("<option value='' selected='selected'>---------</option>");
                    }
                });
            }
        });

        $('#subdivision').change(function(){
            $('#id_sub_division').val($(this).val());
        });

        $('.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');         
            $.RefreshContent("/company/orginazition/vieworginazition/");
        {% endif %}
       
    });
</script>
<style>
    .ui-autocomplete { z-index: 215000000 !important; }
</style>


<ol class="breadcrumb">
    <li>{% trans "系统菜单" %}</li>
    <li>{% trans "新建组别" %}</li>

   
</ol>


<div class="clearfix"></div>


<div class='x_panel' >


<div class='container'>

    

        <div class="form-group ">
            <label class="col-sm-1 control-label ">{% trans '功能组别:' %} </label>
            <div class="col-sm-11"><input class='form-control' id='name' /></div>
        </div>      
        <div class="form-group ">
            <label class="col-sm-1 control-label ">{% trans '备注说明:' %} </label>
            <div class="col-sm-11"><input class='form-control' id='remark' /></div>
        </div>   
        <div class="form-group ">
            <label class="col-sm-1 control-label ">{% trans '适用企业:' %} </label>
            <div class='col-sm-11'>
                <div class="input-group">
                    <select id='company_id' class='form-control'>
                    {% for c in companys %}
                        <option value="{{c.0}}">{{c.1}}</option>
                    {% endfor %}
                    </select><span class="input-group-btn"><button type="button" class="btn btn-success add-company">
                    <span class='glyphicon glyphicon-arrow-down'></span></button></span>
                </div>
            </div>
        </div>
        <div class="form-group" >
            <div class='col-sm-11 col-md-offset-1'>
                <select class="select2_multiple form-control" id="sel-company" multiple="multiple">                                                
                </select>        
            </div>
        </div>      



         <div>       
            <button class="btn btn-primary btn-save"  style="float:right;">{% trans '保存' %}</button>
        </div>
    
</div>









  
   
   


