<%
  import org.exoplatform.portal.config.model.PageNode;
  import java.util.List;

%>
<%// Begin render page nodes method
  void renderPageNodes(List<PageNode> pageNodes) {
    if(pageNodes == null || pageNodes.isEmpty()) {
      return;
    }

    for(PageNode pageNode : pageNodes) {
      if(!uicomponent.hasPermissionOnPageNode(pageNode)) {
        continue;
      }
      String href = uicomponent.getHREF(pageNode);
      String label = uicomponent.getEncodedResolvedLabel(pageNode);
      boolean hasChild = uicomponent.hasChild(pageNode);
      String icon = pageNode.getIcon();
      if(icon == null) icon = "DefaultPageIcon";
      def clazz = "";
      if(hasChild){
        clazz = "ArrowIcon";
      }
      %><li class="MenuItem $clazz"><%
      if(href != null) {%>
        <a class="ItemIcon $icon" href="$href">$label</a>
    <%} else {%>
        <a class="ItemIcon $icon" href="#">$label</a>
    <%}
      if(hasChild) {%>
        <ul class="MenuItemContainer" style="position: absolute; display:none">
        <%
          List<PageNode> childPageNodes = uicomponent.getChildren(pageNode);
          renderPageNodes(childPageNodes);
        %>
        </ul>
    <%}%>
        </li>
  <%}%>
<%} // End render method 

List<PageNode> pagesNodes = uicomponent.getPageNodes();
if(pagesNodes!=null && !pagesNodes.isEmpty()) {
  def rcontext = _ctx.getRequestContext();
  def jsManager = rcontext.getJavascriptManager();
  jsManager.importJavascript('eXo.portal.UIPortalNavigation');
  jsManager.importJavascript('eXo.portal.UIAdminToolbar');
  jsManager.addCustomizedOnLoadScript('eXo.portal.UIAdminToolbar.onLoad("' + uicomponent.id + '");');
%>
  <ul class="UISetupPlatformToolBarPortlet UIHorizontalTabs" id="$uicomponent.id">
    <li class="UITab NormalToolbarTab">
      <a href="#" class="SetupMenuItem TBIcon"><img src="/eXoPlatformResources/skin/platformSkin/icons/setup.png"/></a>
      <ul style="display: none" class="MenuItemContainer">
        <%  renderPageNodes(pagesNodes); %>
      </ul>
    </li>
  </ul>
<%} %>
