<head>
    
    <link rel="stylesheet" href="/static/js/hummingbird-treeview-master/hummingbird-treeview.min.css" />
    <script src="/static/js/hummingbird-treeview-master/hummingbird-treeview.min.js" type="text/javascript"></script>
   
    <style>
        #treeview li label{
            font-size:14px;
        }
    </style>

</head>

<script type="text/javascript">
    $(document).ready(function(){     

       

        $.fn.hummingbird.defaults.checkDoubles= false;

        $("#treeview").hummingbird();
        $('.btn-expandAll').click(function(){
            $("#treeview").hummingbird("expandAll");
        });
        $('.btn-collapseAll').click(function(){           
            $("#treeview").hummingbird("collapseAll");
        });
        $('.btn-checkAll').click(function(){
            $("#treeview").hummingbird("checkAll");
        });
        $('.btn-uncheckAll').click(function(){           
            $("#treeview").hummingbird("uncheckAll");
        });
        
        $('.btn-save').click(function(){
            var List = {"id" : [], "dataid" : [], "text" : []};
            $("#treeview").hummingbird("getChecked",{list:List,onlyEndNodes:false,onlyParents:false,fromThis:false});            
            var data={'company_id':{{company.id}},"menu_ids":List.dataid};            
            $.ajax({
                type: 'POST',
                dataType: 'json', 
                data:JSON.stringify(data),
                url:'{{request.path}}',
                success:function(data){                    
                    toastr.success(
                        "{{company.name}} 菜单已生成",
                        {imeOut: "800",showDuration:"800", positionClass: "toast-center-center"}
                    );

                    /*

                    $.ajax({
                        type:'GET',
                        processData: false,
                        contentType: 'application/json; charset=utf-8',
                        url:'/company/orginazition/cgroup_menu/?cgroup_id='+cgroup_id,
                        success: function (html) { 
                            $('#div-edit').html(html);  
                            return;
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            alert('连接服务器失败');
                            return;
                        }
                    });
                    */
                }
            });

        });
    });
</script>					


<div style='margin-bottom:10px;' id="cgroup_id" >
    企业名称: <span style='font-weight:bold;color:red;min-width:200px;display:inline-block;'>{{company.name}}</span>
    <id='company_id' type='hidden' value='{{company.id}}' />
    <button class='btn btn-success btn-xs btn-expandAll'><span class='glyphicon glyphicon-plus' style='padding-right:5px;'/>全部展开</button>
    <button class='btn btn-success btn-xs btn-collapseAll'><span class='glyphicon glyphicon-minus' style='padding-right:5px;'/>全部收起</button>
    <button class='btn btn-warning btn-xs btn-checkAll' style="margin-left:200px;"><span class='glyphicon glyphicon-check' style='padding-right:5px;'></span>全部勾选</button>
    <button class='btn btn-warning btn-xs btn-uncheckAll'> <span class='glyphicon glyphicon-unchecked' style='padding-right:5px;'></span>全部取消</button>

    <button class='btn btn-primary btn-xs btn-save pull-right' style="margin-left:40px;">生成企业菜单</button>
</div>


<div id="treeview_container" class="hummingbird-treeview" style="height:700px; overflow-y: scroll;">
    <ul id="treeview" class="hummingbird-base">
    {% for i in menuitems %}
        <li>{% if i.children %}<i class="fa fa-plus"></i>{% endif %}  
            <label><input type="checkbox" {% if i.show %} checked="checked" {% endif %} data-id='{{i.id}}'/>
            <i class='{{i.icon}}'></i>{{i.title}}</label>	
            {% for c in i.children %}<ul>            
                <li>{% if c.children %}<i class="fa fa-plus"></i>{% endif %}  
                    <label><input type="checkbox" {% if c.show %} checked="checked" {% endif %} data-id='{{c.id}}' />
			        <i class='{{c.icon}}'></i>{{c.title}}</label>	  
                    {% for cc in c.children %}<ul>                  
                        <li>{% if cc.children %}<i class="fa fa-plus"></i>{% endif %}
                            <label><input {% if cc.show %} checked="checked" {% endif %} type="checkbox" data-id='{{cc.id}}'/>
                            <i class='{{cc.icon}}'></i>{{cc.title}}</label> 
                            {% for ccc in cc.children %}<ul>
                                <li>
                                    <label><input type="checkbox" {% if ccc.show %} checked="checked" {% endif %} data-id='{{ccc.id}}'/>
			                        <i class='{{ccc.icon}}'></i>{{ccc.title}}</label>	  
                                </li>
                            </ul>{% endfor %}
                        </li>
                    </ul>{% endfor %}                   
                </li>           
            </ul>{% endfor %}
        </li>
    {% endfor %}
    </ul>
</div>
