#{param name=keyword/}
#{param name=projects/}
#{param name=currentProjectId/}
#{param name=identity/}

<%
	import org.exoplatform.task.util.StringUtil;
	import org.exoplatform.commons.utils.HTMLEntityEncoder;	

def displayProject(project, level) {
  		  def encoder = HTMLEntityEncoder.getInstance();
        //. If current project is match, we do not shot its tree
        if (currentProjectId == project.getId()) {
            return;
        }
        String name = project.getName();
        boolean isMatched = false;
        if (keyword == "") {
            name = encoder.encode(name);
            isMatched = true;
        } else if (name.toLowerCase().contains(keyword.toLowerCase())) {
            isMatched = true;
            name = StringUtil.highlight(name, keyword, "<strong>", "</strong>");
        }
        def padding = level * 20 + 20;
        
        def canView = project.canView(identity);
    %>
    <li>
        <a class="" style="padding-left: ${padding}px" href="javascript:void(0)" data-canview="${canView}" data-matched="${isMatched}" data-projectid="${project.id}">
        ${name}
        </a>
        <% if (project.children != null && project.children.size() > 0) {%>
            <ul>
                <% for (def p in project.children) { displayProject(p, level + 1) }%>
            </ul>
        <% }%>
    </li>
<%}%>

<% if (projects.size() > 0) { %>
    <ul>
        <li>
            <a href="javascript:void(0)" data-canview="true" data-matched="${keyword == "" ? "true" : "false"}" data-projectid="0">&{label.projects}</a>
            <ul>
                <% for (def p in projects) { displayProject(p, 1) }%>
            </ul>
        </li>
    </ul>
<% } else { %>
    <div class="empty center">&{message.noProjectFound}</div>
<% }%>
