<#macro chipTree filepath="">
    <@tools.fileList path=filepath>
        <#list list as a>
            <#local path=filepath+'/'+a.fileName>
            <li<#if a.directory> _src="cmsTemplate/ftlLookup.html?parent=${path}"</#if>>
                <#if a.directory>
                    <a href="javascript:;" onclick="return false;">${a.fileName}</a>
                <#else>
	                <@tools.metadata path=path>
	                    <a href="javascript:;" onclick="use('${path}','${(object.alias)?has_content?then('<#-- '+object.alias+' -->','')?js_string}');$.pdialog.closeCurrent();return false;">
	                        ${(object.alias)?has_content?then(object.alias+' '+a.fileName,a.fileName)}
	                    </a>
	                </@tools.metadata>
                </#if>
            </li>
        <#else>
            <li><a><@t.page 'empty_directory'/></a></li>
        </#list>
    </@tools.fileList>
</#macro>
<#if parent?has_content>
     <ul>
         <@chipTree parent/>
     </ul>
<#else>
<div class="pageFormContent" layoutH>
    <dl class="nowrap">
        <dt><@t.page 'use_way'/></dt>
        <dd>
            <label style="width:auto;">
                <input name="use" type="radio" value="include" checked="true"/>
                <@t.page 'include'/>
            </label>
            <label style="width:auto;">
                <input name="use" type="radio" value="import"/>
                <@t.page 'import'/>
            </label>
            <div class="hide"><label style="width:auto;"><@t.page 'name_space'/>:</label><input name="namespace" type="text" maxlength="10" size="10" value="t"/></div>
        </dd>
    </dl>
    <script>
    function use(path,description){
        if('include'==$('input[name=use]:checked',$.pdialog.getCurrent()).val()){
            JUI.instances[$('textarea.code',navTab.getCurrentPanel()).data('id')].replaceSelection('${r'<@include path="'?no_esc}'+path+'${r'"/>'?no_esc}'+description);
        } else {
            JUI.instances[$('textarea.code',navTab.getCurrentPanel()).data('id')].replaceSelection('${r'<@import path="'?no_esc}'+path+'" namespace="'+$('input[name=namespace]',$.pdialog.getCurrent()).val()+'"${r'/>'?no_esc}'+description);
        }
    }
    $('input[name=use]',$.pdialog.getCurrent()).on('change',function(){
        if('include'==$('input[name=use]:checked',$.pdialog.getCurrent()).val()){
            $('input[name=namespace]',$.pdialog.getCurrent()).parent().hide();
        } else {
            $('input[name=namespace]',$.pdialog.getCurrent()).parent().show();
        }
    });
    </script>
    <ul class="tree treeFolder">
        <@chipTree ''/>
    </ul>
</div>
<div class="formBar">
    <ul>
        <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
    </ul>
</div>
</#if>