<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<link rel="stylesheet" href="<c:url value="/resources/3rd-party/sneat/libs/jstree/jstree.css"/>" /--%>
<div id="_url-tree" class="main-left d-flex flex-column flex-grow-1">
	<div class="d-flex justify-content-between" style="padding-top:.5em; padding-bottom:.5em; border-top:1px solid #dfdfdf; border-bottom:1px solid #dfdfdf;">
		<span>
			<button id="_urlToggler" onclick="_toggleURLs();" class="btn btn-primary"></button>
		</span>
	</div>
	<div id="_urlTree" style="padding-top:1em; height:37em; overflow:auto;">
	</div>
</div>
<script src="<c:url value="/resources/3rd-party/sneat/libs/jstree/jstree.js"/>"></script>
<script src="<c:url value="/resources/3rd-party/jstree/jstree-support.js"/>"></script>
<script type="text/javascript">
var _multiple = ${multiple},
	_urlSupport = treeSupport({
		selector:"#_urlTree",
		trace:wctx.trace,
		plugins: _multiple ? ["checkbox"] : [],
		core:{check_callback:true,
		      multiple:_multiple
//		      themes:{name:"proton"}
			 },
		checkbox:{
			whole_node:false,
			tie_selection:false
		}
	});

function getSelectedURL() {
	var selected = _multiple ? _urlSupport.checkedNodes() : _urlSupport.selectedNodes();
	if (selected.length < 1)
		return dialog.alert("URL을 선택하십시오.");
	
	if (_multiple)
		return selected;
	else
		return selected[0];
}

function _toggleURLs() {
	$("#_urlToggler").text(_urlSupport.toggleFolding() == "collapsed" ? "+ 펼치기" : "- 닫기");
}

var urls = ${urls};

_urlSupport.setData(treeHtml(urls, {
	id:function(e){return e.url;},
	text:function(e){
		return e.name == e.url ? e.name : e.name + " (" + e.url + ")";
	}
}));

$("#_urlToggler").text(_urlSupport._folding == "collapsed" ? "+ 펼치기" : "- 닫기");
</script>