<%
/**
 * Created by The eXo Platform SARL
 * Author : Nguyen Anh Vu
 *          anhvurz90@gmail.com
 * Oct 16, 2009 5:3:43 PM
 */
%>

<% 
  import org.exoplatform.ecm.webui.utils.Utils;
  import org.exoplatform.services.jcr.impl.core.JCRPath;
  import org.exoplatform.services.jcr.impl.core.SessionImpl;
  import org.exoplatform.web.application.Parameter ;  
  import javax.jcr.Node;
  import javax.jcr.Session;
%>
<% 
  def favouriteNodesList = uicomponent.getAllFavouriteNodes(); 
  if(favouriteNodesList == null) return;
  def rcontext = _ctx.getRequestContext();
  rcontext.getJavascriptManager().importJavascript('eXo.ecm.UIJCRExplorer','/ecmexplorer/javascript/');
  java.text.DateFormat dateFormat = uicomponent.getSimpleDateFormat();
  int totalPages = uicomponent.getUIPageIterator().getAvailablePage();
%>

<div class="UIShowAllFavouriteResult" id="$uicomponent.id">
  <table class="UIGrid" style="width: 97%">
    <thead>
      <tr>
        <th style="width:80px;">
          <div class="StarOff">
            <span></span>
          </div>
        </th>
        <th width="45px">
          <%
            if (uicomponent.iconType.equals("BlueUpArrow")) {
          %>
            <div onclick="<%=uicomponent.event("SortASC", Utils.formatNodeName("type"))%>" title="<%=_ctx.appRes("UIShowAllFavouriteResult.title.typeASC")%>">
              <%=_ctx.appRes("UIShowAllFavouriteResult.header.type")%>
              <img src="/eXoResources/skin/sharedImages/Blank.gif" alt="<%=_ctx.appRes("UIShowAllFavouriteResult.title.typeASC")%>" class="BlueUpArrow16x16Icon">
            </div>
          <%
            } else if (uicomponent.iconType.equals("BlueDownArrow")) {
          %>
          <div onclick="<%=uicomponent.event("SortDESC", Utils.formatNodeName("type"))%>" title="<%=_ctx.appRes("UIShowAllFavouriteResult.title.typeDESC")%>">
            <%=_ctx.appRes("UIShowAllFavouriteResult.header.type")%>
            <img src="/eXoResources/skin/sharedImages/Blank.gif" alt="<%=_ctx.appRes("UIShowAllFavouriteResult.title.typeDESC")%>" class="BlueDownArrow16x16Icon">
          </div>
          <%
            } else {
          %>
            <div onclick="<%=uicomponent.event("SortASC", Utils.formatNodeName("type"))%>" title="<%=_ctx.appRes("UIShowAllFavouriteResult.title.typeASC")%>">
              <%=_ctx.appRes("UIShowAllFavouriteResult.header.type")%>                
            </div>
          <% } %>
        </th>
        <th>
          <%
            if (uicomponent.iconName.equals("BlueUpArrow")) {
          %>
            <a href="<%=uicomponent.event("SortASC", Utils.formatNodeName("name"))%>" title="<%=_ctx.appRes("UIShowAllFavouriteResult.title.nameASC")%>">
              <%=_ctx.appRes("UIShowAllFavouriteResult.header.name")%>
              <img src="/eXoResources/skin/sharedImages/Blank.gif" alt="<%=_ctx.appRes("UIShowAllFavouriteResult.title.nameASC")%>" class="BlueUpArrow16x16Icon"/>
            </a>
          <%
            } else if (uicomponent.iconName.equals("BlueDownArrow")) {
          %>
          <a href="<%=uicomponent.event("SortDESC", Utils.formatNodeName("name"))%>" title="<%=_ctx.appRes("UIShowAllFavouriteResult.title.nameDESC")%>">
            <%=_ctx.appRes("UIShowAllFavouriteResult.header.name")%>
            <img src="/eXoResources/skin/sharedImages/Blank.gif" alt="<%=_ctx.appRes("UIShowAllFavouriteResult.title.nameDESC")%>" class="BlueDownArrow16x16Icon"/>
          </a>
          <%
            } else {
          %>
            <a href="<%=uicomponent.event("SortASC", Utils.formatNodeName("name"))%>" title="<%=_ctx.appRes("UIShowAllFavouriteResult.title.nameASC")%>">
              <%=_ctx.appRes("UIShowAllFavouriteResult.header.name")%>         
            </a>
          <% } %>        
        </th>   
        <th style="width:80px;"><%=_ctx.appRes("UIShowAllFavouriteResult.header.action")%></th>
      </tr>
    </thead>

    
    
    <tbody>
    <%
      def rowClass = null ;
      boolean even = true ;
      int count = 0;
//      map.clear();
      if (favouriteNodesList != null && favouriteNodesList.size() > 0) {
        for (node in favouriteNodesList) {
          if (even) rowClass = "EvenRow";  
          else rowClass =  "OddRow"; 
          even = !even;
          String nodePath = node.getPath();
          if (node.getPrimaryNodeType().getName().equals("nt:resource")) {
            node = node.getParent();
            nodePath = node.getPath();
          }
         
          //String excerpt = row.getValue("rep:excerpt(.)")== null ? "" : row.getValue("rep:excerpt(.)").getString();
          String excerpt = "";
          String s = "";
          
      %>
          <tr class="$rowClass">
            <td>
              <div class="ActionContainer">
                <%
                  //UIStar uiStarObj = uicomponent.getUIStars().get(count++);
                  //uiStarObj.setFavourite(node.isNodeType(Utils.EXO_FAVOURITE));
                  //uiStarObj.setNode(node);
                  def mapIndexNode = uicomponent.getMapIndexNode();
                  mapIndexNode.put(count, node);
                  if (uicomponent.getFavouriteService().isFavouriter(node.getSession().getUserID(), node)) { 
                %>
                  <div class="StarLight UICursorPointer" onclick="<%=uicomponent.event("StarClick", count+"")%>">
                    <span>
                    </span>
                  </div
                <%} else {
                %>
                   <div class="StarOff UICursorPointer" onclick="<%=uicomponent.event("StarClick", count+"")%>">
                      <span>
                      </span>    
                    </div>
                  <% 
                    }

                  %>
              </div>
            </td>
                      
            <td>
              <div class="default16x16Icon ItemIcon <%=Utils.getNodeTypeIcon(node, "16x16Icon")%>" style="margin:auto"><span></span></div>
            </td>
            <td>
              <div class="Text" title="<%=dateFormat.format(uicomponent.getDateCreated(node))%>">
                <%=node.getName()%>
              </div>
              <div>$excerpt</div>
              <div><%=_ctx.appRes("UIShowAllFavouriteResult.header.path")%>: <%=nodePath%></div>
              <div><%=_ctx.appRes("UIShowAllFavouriteResult.header.dateCreated")%>: <%=dateFormat.format(uicomponent.getDateCreated(node))%></div>
            </td>
            <td>
              <div class="ActionContainer">
                <img onclick="<%=uicomponent.event("View", Utils.formatNodeName(node.getPath()))%>" alt="<%=_ctx.appRes("UIShowAllFavouriteResult.tooltip.View")%>" title="<%=_ctx.appRes("UIShowAllFavouriteResult.tooltip.View")%>" src="/eXoResources/skin/sharedImages/Blank.gif" class="View16x16Icon"/>
                <img src="/eXoResources/skin/sharedImages/Blank.gif" onclick="<%=uicomponent.event("OpenFolder", Utils.formatNodeName(node.getPath()))%>" title="<%=_ctx.appRes("UIShowAllFavouriteResult.tooltip.OpenFolder")%>" alt="<%=_ctx.appRes("UIShowAllFavouriteResult.tooltip.OpenFolder")%>" class="OpenFolder16x16Icon"/>
              </div>
            </td>                   
          </tr>
    <%
		    count++;    
        }
      } else {
    %>
      <tr class="EvenRow">
        <td colspan="4" style="text-align:center;font-style:italic; color: #EF5604;"><%=_ctx.appRes("UIShowAllFavouriteResult.msg.empty")%></td>
      </tr>
    <%}%>
    </tbody>
  </table>
  <% if(totalPages>1){ %>
  <div style="margin:1px 0px 20px 0px;">
    <%_ctx.renderUIComponent(uicomponent.getUIPageIterator())%>
  </div>
  <% } %>
</div>





