{{template "inc"}}
<!-- Main Header -->
{{template "header"}}
<!-- Left side column. 权限菜单 -->
{{template "memu"}}

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <section class="content-header">
        <ol class="breadcrumb">
            <li><a href="/admin/role"><i class="fa fa-dashboard"></i> 角色管理</a></li>
            <li><a href="/admin/rolemenu"><i class="fa fa-dashboard"></i> 角色菜单管理</a></li>
            <li><a href="/admin/rolesecondmenu"><i class="fa fa-dashboard"></i> 角色二级菜单管理</a></li>
        </ol>
    </section>
    <br>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        <table id="dataTable" class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>名字</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
</div>


<!-- footer -->
{{template "footer"}}

<script>
    menuActive("role")
    $(function () {
        ttable=$('#dataTable').DataTable({
            "paging"      : true,
            "lengthChange": false,
            "searching"   : true,
            "ordering"    : true,
            "info"        : true,
            "autoWidth"   : false,
            "ajax": {
                "url": "/admin/role/secondmenu/data",
                "type": "post",
                "data":{"role":{{.role}},"_id":{{._id}}}
            },
            "language": {
                "url": "/res/dist/js/dataTables.chinese.lang"
            },
            "columns": [
                { "data": "name",render:function(val,a,row){
                        return row.name}},
                {"data":"_id",render:function(val,a,row){
                        return "<a href='#' onclick='del(\""+val+"\")'><i class='fa fa-fw fa-trash text-red'></i></a>"
                    }}
            ]
        });
        //ttable.on('init.dt', function () {});
    })

    function save(){
        na=$("#name").val()
        href=$("#href").val()
        pic=$("#pic").val()
        if(na==""||pic==""){
            alert("表单填写不完整！")
            return false;
        }
        _id=$("#_id").val()
        if (_id){
            map={"name":na,"href":href,"pic":pic,"_id":_id}
        }else{
            map={"name":na,"href":href,"pic":pic}
        }
        $.ajax({
            url:"/admin/menu/save",
            type:"post",
            data:map,
            success:function(r){
                if(r.rep){
                    $("#userform")[0].reset();
                    $("#modal-info").modal("hide");
                    ttable.ajax.reload();
                }else{
                    alert("保存失败");
                }
            }
        })
    }
    function del(_id){
        showConfirm("确定删除？", function() {
            $.ajax({
                url:"/admin/role/secondmenu/del",
                type:"post",
                data:{"_id":_id,"role":{{.role}}},
                success:function(r){
                    if(r.rep){
                        ttable.ajax.reload();
                    }else{
                        showTip("删除失败", 1000, function() {});
                    }
                }
            })
        });
    }
    function formReset(){
        $("#email").attr("disabled",false);
        $("#name").attr("disabled",false);
        $("#userform")[0].reset();
        $("#_id").removeAttr("value")
    }
</script>
