<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 cgroup_id=$("#cgroup_id").attr('cgroup_id');
            var data={"cgroup_id":cgroup_id,"auth_ids":List.dataid};
            
            
            $.ajax({
                type: 'POST',
                dataType: 'json', 
                data:JSON.stringify(data),
                url:'{{request.path}}',
                success:function(data){
                    //toastr.success("{{cgroup.name}} 菜单设置已保存",);
                    toastr.success(
                        "{{cgroup.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" cgroup_id="{{cgroup.id}}">
    功能组别: <span style='font-weight:bold;color:red;min-width:200px;display:inline-block;'>{{cgroup.name}}</span>
    <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:600px; 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>
