{include file='public/meta'}
<link rel="stylesheet" href="__LIB__/layui/css/layui.css" media="all">
<body>
<article class="page-container">
	<form class="form form-horizontal layui-form" >
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>名称</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text"  placeholder="" id="name" name="name" value="<?php echo $row['name'];?>" >
		</div>
	</div>

	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">用户组权限</label>
		<div class="formControls col-xs-8 col-sm-9">
			<ul id="privileges">
       		</ul> 
		</div>
	</div>

	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" lay-submit lay-filter="btnSub" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>



	</form>
</article>

{include file='public/footer'}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/layui/layui.js"></script> 
<script type="text/javascript">
var id = "<?php echo $row['id'];?>";

layui.use(['form','tree'], function () {
    var form = layui.form,
        tree = layui.tree,
        layer = layui.layer;
    var privilege_tree = tree.render({
        elem: '#privileges',
        data: getMenus(),
        id: 'demoId',
        showCheckbox: true,     //是否显示复选框
    });

    //提交
    form.on('submit(btnSub)', function (data) {
        var name = $('#name').val();
        if(name.length==0){
          layer.msg('请输入用户组名称');
          return false;
        }
        var rules = privilege_tree.getChecked('demoId');
        if(!rules){
          layer.msg('请选择权限');
          return false;
        }
        $.post(
          "<?php echo url('admin/usergroup/publish');?>", 
          {"rules":rules,"id":id,"name":name}, 
          function (result) {
          	layer.msg(result.msg,{icon:1,time:1000});
            if(0==result.error){
                setTimeout(function(){
                  	var index = parent.layer.getFrameIndex(window.name);
					parent.location.reload();
					parent.layer.close(index);
                },1000)
            }
          },'json');
        return false;
    });
})



function getMenus(){ 
    var data = [];
    $.ajax({
        url: "<?php echo url('admin/usergroup/getallrules');?>",   
        data: {"user_group_id":id}, 
        type: "post",
        async:false,
        success: function(result){
           data = JSON.parse(result);
        }
    });
    return data;
}

</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>