<?php include $this->admin_tpl('meta');?>
<title>权限管理 - YzmCMS内容管理系统</title>
<style>
	.parentid{cursor:pointer;user-select:none}
	input[type="checkbox"]{margin-top:-1px}
</style>
</head>
<body>
<nav class="breadcrumb"><i class="yzm-iconfont yzm-iconai-home"></i> 首页 <span class="c-gray en">&gt;</span> 角色管理 <span class="c-gray en">&gt;</span> 权限管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="yzm-iconfont yzm-iconshuaxin"></i></a></nav>
<div class="page-container footer_padding">
	<div class="cl tb-top"> 
		<span class="l"> 
		<a href="javascript:;" onclick="yzm_tree_toggle(this)" isshow="1" class="btn btn-secondary radius tree_toggle"><i class="yzm-iconfont">&#xe653;</i> 收起子项</a>
		</span> 
	</div>
	<form action="" method="post">
	<table class="table table-border table-bg table-hover permission">
		<thead>
			<tr class="text-c">
				<th class="text-l"><input type="checkbox" onclick="change_menu(this)"> 权限名称</th>
			</tr>
		</thead>
		<tbody>
			 <?php echo $menus;?>
		</tbody>
	</table>
	<input type="hidden" name="roleid" value="<?php echo $roleid?>"></input>
	<div class="footer_btn footer_border"> 
		<input class="btn btn-primary radius" name="dosubmit" value="确 定" type="submit">
		<input type="button" class="btn btn-default radius" value="返 回" onclick="javascript:history.go(-1)">
	</div>
	</form>
</div>
<?php include $this->admin_tpl('footer');?>
<script type="text/javascript">
	function checknode(obj){
		var chk = $("input[type='checkbox']");
		var count = chk.length;
		var num = chk.index(obj);
		var level_top = level_bottom =  chk.eq(num).attr('level')
		for (var i=num; i>=0; i--){
		  var le = chk.eq(i).attr('level');
		  if(eval(le) < eval(level_top)) {
			  chk.eq(i).attr("checked",'checked');
			  var level_top = level_top-1;
		  }
		}
		for (var j=num+1; j<count; j++){
		  var le = chk.eq(j).attr('level');
		  if(chk.eq(num).attr("checked")=='checked') {
			  if(eval(le) > eval(level_bottom)) chk.eq(j).attr("checked",'checked');
			  else if(eval(le) == eval(level_bottom)) break;
		  }else {
			  if(eval(le) > eval(level_bottom)) chk.eq(j).attr("checked",false);
			  else if(eval(le) == eval(level_bottom)) break;
		  }
		}
	}

	function change_menu(obj){
		$(".table :checkbox").prop("checked", $(obj).prop("checked"));
	}

  	function yzm_tree_toggle(obj) {
  		var isshow = $(obj).attr("isshow");
  		if(isshow == "0"){
  			$(obj).attr("isshow", "1");
  			$(obj).html('<i class="yzm-iconfont">&#xe653;</i> 收起子项');
  			$(".top .parentid").attr('action', 2).html('&#xe653;');
  			$(".child").show();
  		}else{
  			$(obj).attr("isshow", "0");
  			$(obj).html('<i class="yzm-iconfont">&#xe652;</i> 展开子项');
  			$(".top .parentid").attr('action', 1).html('&#xe652;');
  			$(".child").hide();
  		}
    }

    $(".parentid").click(function () {
        var action = parseInt($(this).attr("action"));
        var tr = $(this).parents('tr').eq(0);
        switch (action) {
            case 1://展示
                $(tr).nextUntil('.top').show();
                $(this).attr('action', 2).html('&#xe653;');
                break;
            case 2://收缩
                $(tr).nextUntil('.top').hide();
                $(this).attr('action', 1).html('&#xe652;');
                break;
        }
    })

    $(".tree_toggle").trigger('click');
</script>
</body>
</html>