<%@
	page contentType="text/html; charset=UTF-8"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.moumi.Moumi" import="kr.co.kihyun.lang.MString"
	import="kr.co.kihyun.lang.MLong" import="kr.co.kihyun.beans.user.Dept"
	import="kr.co.kihyun.beans.user.PartList"
%>
<%
    String dtID = HttpSSOLogin.getDeptID(request);
	String rootId=request.getParameter("rootID");
	String keyWord=request.getParameter("keyWord");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="/totsys/common/js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="/totsys/common/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/totsys/common/js/jquery.hotkeys.js"></script>
<script type="text/javascript" src="/totsys/common/js/jquery.jstree.js"></script>
<style>
#newTree { text-align: justify; font-size:9pt; vertical-align:middle; }
</style>
</head>
<body>
<input type="button" class="button" value="Search" id="search" style="display:none" />
<input type="button" class="button" value="Search clear" id="searchClear" style="display:none" />
<input type="button" class="button" value="checked Id" id="checkbtn" style="display:none" />
<div id="newTree" class="newTree"></div>
<div id="searchWord" style="display:none"></div>
<script type="text/javascript" class="source">
$(function() {
	$("#newTree").jstree({
		"json_data" : {
			"data" : [
				{
					"data"  : "사용자그룹",
					"state" : "closed",
					"attr"  : { "id" : "ROOT","rel":'<%=dtID%>',"rootid":'<%=rootId%>' }
				}
			],
			"ajax" : {
				"url" : "/servlet/kr.co.kihyun.tree.Tree",
				"data" : function(n) {
					var data={};
					data.id=n.attr("id");
                     data.rel=n.attr("rel");
					data.rootId=n.attr("rootId");
					data.gubun="GROUP";
					data.userYN="N";
					return data;
				}
			},
			"progressive_render" : true
		},
		"types"    : {
			"valid_children" : ["ROOT","DEPT","USER"],
			"types" : {
				"ROOT" : {
					"icon" : { "image" : "/totsys/common/images/pc-user.gif" }
				},
				"USER" : {
					"icon" : { "image" : "/totsys/common/images/person.png" }
				}
			}
		},
		"core" : { 'initially_open' : ['ROOT'] },
		"plugins"  : ["themes","json_data","checkbox","search","types","ui","core"],
		"checkbox" : { state_type : "three-state" },
		"themes"   : {
			"theme":"classic",
			"dots":true,
			"icons":true,
		 	"url" : "/totsys/common/js/themes/classic/style.css"
		},
		"search"   : {
			"case_insensitive" : true,
			"ajax" : {
				"url" : "/servlet/kr.co.kihyun.tree.TreeSearch",
				"data": function(str) {
					var data={};
					data.keyWord=str;
					data.startId=encodeURIComponent('<%=rootId%>');
					data.gubun="GROUP";
					return data;
				},
				"async" : false,
				"success" : function(data) {
				}
			}
		}
	});
	$("#newTree").bind("check_node.jstree",function(e,data) {
		data.inst.open_node(data.rslt.obj,false,true);
	});
	$("#search").click(function () {
		$("#newTree").jstree("search",$('#searchWord').text());
	});
	$("#searchClear").click(function () {
		$("#newTree").jstree("clear_search");
    $("#searchResult").empty();
	});
	$("#checkbtn").click(function () {
		$("#newTree").jstree("get_checked",null,true).each(function() {
			if(this.id.length>10 || this.id=='ROOT') return;
			parent.putSelId(this.id);
		});
	});
});
</script>
</body>
</html>
