<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="{base}application/views/" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<link rel="stylesheet" href="css/zTreeStyle.css" type="text/css">
	
</head>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
	<script type="text/javascript" src="js/jquery.ztree.core-3.5.js"></script>
	<script type="text/javascript" src="js/jquery.ztree.excheck-3.5.js"></script>
	<script type="text/javascript">

		var setting = {
			view: {
				selectedMulti: false
			},
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onCheck: onCheck
			}
		};

		var zNodes ={tree_data};
		/*
		var zNodes =[
			{ id:1, pId:0, name:"随意勾选 1", open:true},
			{ id:11, pId:1, name:"随意勾选 1-1"},
			{ id:12, pId:1, name:"随意勾选  1-2", open:true},
			{ id:121, pId:12, name:"随意勾选 1-2-1", checked:true},
			{ id:122, pId:12, name:"随意勾选 1-2-2"},
			{ id:123, pId:12, name:"随意勾选 1-2-3"},
			{ id:13, pId:1, name:"随意勾选 1-3"},
			{ id:2, pId:0, name:"随意勾选 2", open:true},
			{ id:21, pId:2, name:"随意勾选 2-1"},
			{ id:22, pId:2, name:"随意勾选 2-2", open:true},
			{ id:221, pId:22, name:"随意勾选 2-2-1", checked:true},
			{ id:222, pId:22, name:"随意勾选 2-2-2"},
			{ id:223, pId:22, name:"随意勾选 2-2-3"},
			{ id:23, pId:2, name:"随意勾选 2-3", checked:true}
		];
		*/
		var clearFlag = false;
		function onCheck(e, treeId, treeNode) {
			count();
			if (clearFlag) {
				clearCheckedOldNodes();
			}
		}
		function clearCheckedOldNodes() {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getChangeCheckedNodes();
			for (var i=0, l=nodes.length; i<l; i++) {
				nodes[i].checkedOld = nodes[i].checked;
			}
		}
		function count() {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			checkCount = zTree.getCheckedNodes(true).length,
			nocheckCount = zTree.getCheckedNodes(false).length,
			changeCount = zTree.getChangeCheckedNodes().length;
			$("#checkCount").text(checkCount);
			$("#nocheckCount").text(nocheckCount);
			$("#changeCount").text(changeCount);

		}
		function save(){
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			var array_node = zTree.getCheckedNodes(true);
			var ids = array_node[0]['id'];
			for (var i=1;i<array_node.length;i++)
			{
				ids += ","+array_node[i]['id'];
			}
			$("#ids").val(ids);
			$("#submit").click();
		}
		function createTree() {
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			count();
			clearFlag = $("#last").attr("checked");
		}

		$(document).ready(function(){
			createTree();			
			$("#init").bind("change", createTree);
			$("#last").bind("change", createTree);
		});
	</script>
<BODY>
<h1>当前角色：{role_name}</h1>
<input type="button" onClick="save()" value="　保　存　" />

<div style=" display:none" >
<form id="form" action="{site}admin/role_menu_update" method="post">
	<input type="text" id="role_id" name="role_id" value="{role_id}" />
	<input type="text" id="ids" name="ids" value="" />
	<input type="submit" id="submit" value=""/>
</form>
</div>
<div class="content_wrap">
	<div class="zTreeDemoBackground left">
		<ul id="treeDemo" class="ztree"></ul>
	</div>
</div>
</BODY>
</HTML>