<%
import java.util.List;
import org.exoplatform.wcm.webui.Utils;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.wcm.webui.clv.UICLVPortlet;
import org.exoplatform.wcm.webui.clv.CategoryBean;


	 /**
	 	* Created by The eXo Platform SAS
	 	* Author : eXoPlatform
	 	*          benjamin.paillereau@exoplatform.com
	 	* june, 19, 2011
	 	*/


public List<CategoryBean> getCategoriesFromUrl() throws Exception {
  String clvBy = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_SHOW_CLV_BY);
  String paramPath = Util.getPortalRequestContext().getRequestParameter(clvBy);
  if (paramPath==null)
    return uicomponent.getCategories(false);
  else {
%>
      <a class="CategoryLabel" href="<%=uicomponent.getBackLink(paramPath)%>" ><%=_ctx.appRes("UICLVContainer.msg.category-back");%></a>
<%
    return uicomponent.getCategories(paramPath, "exo:taxonomy", 1, false);
  }

}


public void renderCategories(def categories) {
    for (category in categories) {
      def categoryTitle = category.getTitle();
      def categoryURL = category.getUrl();
      def cssStyle = "CategoryLabel";
      def margin = 16 * category.getDepth() + "px";
      
      if (category.getDepth()>0) cssStyle = "SubCategory";
      if (category.isSelected()) cssStyle += " CategorySelected";
      %>
      <a class="$cssStyle" style="margin-left: $margin" href="$categoryURL" title="$categoryTitle">$categoryTitle</a>
      <%
      //if (category.hasChilds() && category.getDepth()==0) renderCategories(category.getChilds());
    }
}
def header = uicomponent.getHeader();
if (header ==null) header=_ctx.appRes("UICLVContainer.msg.non-contents");
%>

<style>
.CategorySelected {
  color: #3366CC !important;
}

.SimpleHorizontal {
  padding-bottom:10px;
}

</style>

<div id="$uicomponent.id" class="SimpleVerticalHierachy">
  <div class="CategoriesContainer">
    <div class="TitleBarL">
      <div class="TitleBarR">
        <div class="TitleBarM">
          <%= header %>
        </div>
      </div>
    </div>
    <div class="NewContent">
      <%
//      def categories = uicomponent.getCategoriesFromUrl();
      def categories = getCategoriesFromUrl();
      renderCategories(categories);
      %>
    </div>
  </div>
</div>