<%
	/**
	 * Created by The eXo Platform SAS
	 * Author : eXoPlatform
	 *          chuong.phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
	 * Jun 27, 2009  
	 */
	 
	/**
	 * Render sub categories
	 */
	public void renderChild(def categoryUri, def categories, int level) {
  	def categoryPath = categories.get(level);
  	def subcategories = uicomponent.getSubcategories(categoryPath);
  	for (subcategory in subcategories) {
      def subcategoryName = subcategory.getName();
      
      def subcategoryTitle = uicomponent.getTitle(subcategory);
      def margin = 16 * (level - 1) + "px";
      def selectedClass = "";
      if (categoryUri.equals("/" + categoryPath + "/" + subcategoryName)) selectedClass = "SubCategorySelected";
      def categoryLink = uicomponent.renderCategoryLink(subcategory);
      %><a style="margin-left: $margin" class="SubCategory $selectedClass" href="$categoryLink" rel="tooltip" data-placement="bottom" title="$subcategoryTitle">$subcategoryTitle</a><%      
      if (subcategory.hasNodes() && (categoryUri+"/").startsWith("/" + categoryPath + "/" + subcategoryName + "/"))       
        renderChild(categoryUri, categories, level + 1);
    }
	}

%>

<div id="$uicomponent.id" class="SimpleVerticalHierachy">
	<div class="CategoriesContainer">
		<div class="TitleBarL">
			<div class="TitleBarR">
				<div class="TitleBarM">
					<%= uicomponent.getTreeTitle() %>
				</div>
			</div>
		</div>
		<div class="NewContent">
			<%
			if(uicomponent.getSelected() != null) {
				def categoryUri = uicomponent.resolveCategoryPathByUri(_ctx.getRequestContext());
				def categories = uicomponent.getCategoriesByUri(categoryUri);
				def rootCategory = categories.get(0);
				if(!uicomponent.isMovedTreeToTrash(rootCategory)) {
			    	def subcategories = uicomponent.getSubcategories(rootCategory);
				  	for (subcategory in subcategories) {
				    	def subcategoryName = subcategory.getName();
				    	def subcategoryTitle = uicomponent.getTitle(subcategory);
				    	def categoryLink = uicomponent.renderCategoryLink(subcategory);
				    	%><a class="CategoryLabel" href="$categoryLink" rel="tooltip" data-placement="bottom" title="$subcategoryTitle">$subcategoryTitle</a><%
				    	if ((categoryUri+"/").startsWith("/" + subcategoryName + "/")) {
				    		renderChild(categoryUri, categories, 1);
				    	}	
				    }
				} else {
					%><div style="font-size: 13px; text-align: center; padding: 10px;"><%= _ctx.appRes("UICategoryNavigationTreeBase.msg.not-existed-category");%></div><%
				}
			  } else {
				%><div style="font-size: 13px; text-align: center; padding: 10px;"><%= _ctx.appRes("UICategoryNavigationTreeBase.msg.not-existed-category");%></div><%
			  }
			%>
		</div>
	</div>
</div>