{% extends "fladmin/public/base.html" %}
{% block title %}角色权限设置{% endblock %}

{% block content %}
<h2 class="sub-header">角色权限设置</h2>[ <a href="{{'CMS_BASEHOST'|sysconfig}}/fladmin/adminrole/index">角色列表</a> ]<br><br>

<form method="post" action="{{'CMS_BASEHOST'|sysconfig}}/fladmin/adminrole/dopermissions" role="form" enctype="multipart/form-data" class="table-responsive"><div class="table-responsive">
<input style="display:none;" name="role_id" type="text" id="role_id" value="{{role_id}}">
<ul class="list-group">
{% for row in menus %}

<li class="list-group-item {% if row.deep==0 %} list-group-item-info {% endif %}"><span style="padding-left: {{row.deep*30}}'px;"></span><input type='checkbox' {% if row.is_access and row.is_access == 1 %} checked='checked' {% endif %} name='menuid[]' value='{{row.id}}' level='{{row.deep}}' onclick='javascript:checknode(this);'>{% for i in range(row.deep) %} — {% endfor %} {{row.name}}</li>
{% endfor %}</ul>

<button type="submit" class="btn btn-success" value="Submit">保存(Submit)</button><br><br>
</div><!-- 表格结束 --></form><!-- 表单结束 -->

<script>
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 (le <level_top)
		{
			chk.eq(i).prop("checked", true);
			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).prop("checked"))
		{
			if (le > level_bottom)
			{
				chk.eq(j).prop("checked", true);
			}
			else if (le == level_bottom)
			{
				break;
			}
		}
		else
		{
			if (le >level_bottom)
			{
				chk.eq(j).prop("checked", false);
			}else if(le == level_bottom)
			{
				break;
			}
		}
	}
}
</script>
{% endblock %}