<%
	import org.exoplatform.webui.core.UIComponent;
  import org.exoplatform.webui.form.UIForm;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import javax.jcr.Node;
  import javax.jcr.Session;
  import org.exoplatform.ecm.webui.utils.Utils;
  import org.exoplatform.services.ecm.publication.PublicationService;
  import org.exoplatform.services.wcm.publication.WCMPublicationService;
  import org.exoplatform.services.wcm.core.NodeLocation;
  import org.exoplatform.services.jcr.RepositoryService;

  String[] beanFields =  uicomponent.getBeanFields();  
  String[] beanActions =  uicomponent.getBeanActions();
  UIComponent uiParent = uicomponent.getParent() ;
  UIForm uiForm = uicomponent.getAncestorOfType(UIForm.class);
  DateFormat dateFormat = uicomponent.getDateFormat();
  RepositoryService rService = uicomponent.getApplicationComponent(RepositoryService.class);
  String repositoryName = rService.getCurrentRepository().getConfiguration().getName();  
%>
<div id="$uicomponent.id">
  <table class="UIGrid" cellspacing="0">
    <thead>
      <tr class="UIWCMSearchContent">
        <%
	        int count = 0;
        		for(field in beanFields) {
       	%>
              		<th class="$field"><%=_ctx.appRes("UIContentSearchResult.header." + field)%></th>
        <%		}
        		if(beanActions != null) { 
        %>
        			<th class="action"><%=_ctx.appRes("UIContentSearchResult.header.action")%></th>
        <%		
        		}
        		
        %>
      </tr>
    </thead>
    <tbody>
    <%	
    	if(uicomponent.getUIPageIterator().getAvailable() < 1) {
    %>
      <tr>
        <td style="font-style:italic; color: #FF5604; text-align: center;" colspan="<%=beanFields.length+1%>">
          <%=_ctx.appRes("UIGrid.msg.empty")%>
        </td>
      </tr>  
    <%	} else { 
        def rowClass = null ;
        boolean even = true ;
        for (bean in uicomponent.getBeans())  {
          if(even) rowClass = "EvenRow" ;  
          else rowClass =  "OddRow" ; 
          even = !even ;
    %>
          <tr>
    <%
            String titleNode = bean.getTitle();
            String expect = uicomponent.getExpect(bean.getExcerpt());
            String path = bean.getPath();
            float score = bean.getScore();
            Node node = bean.getNode();
            def nodeExpression = NodeLocation.getExpressionByNode(node);
            String nodePath = node.getPath();
            String workspaceName = uicomponent.getWorkspaceName(node);
            nodePath = repositoryName + ":" + workspaceName + ":" + nodePath;
            String date = dateFormat.format(uicomponent.getCreateDate(node));
            WCMPublicationService wcmPublicationService = uicomponent.getApplicationComponent(WCMPublicationService.class);
            String publicationState = wcmPublicationService.getContentState(node);
            if (publicationState == null) publicationState = "";
    %>        
          <td>
            <div class="default16x16Icon ItemIcon <%=Utils.getNodeTypeIcon(node, "16x16Icon")%>" style="width: auto; height: auto; background-position: left top; padding-left: 20px">
              <div class="Text">$titleNode</div>
              <div class="Text">$expect</div>
              <div class="Text">$path</div>
              <div class="Text">$date</div>
            </div>
          </td>
          
          <td>
            <div class="Number">$score</div>
          </td>
          
          <td>
            <div class="Text">$publicationState</div>
          </td>
    
          <td class="action">
            <div class="ActionContainer"> 
              <img onclick="eXo.ecm.ECS.addFile2ListContent(this);" nodeType="<%= node.getPrimaryNodeType().getName() %>" path="<%= nodePath %>" src="/eXoResources/skin/sharedImages/Blank.gif" class="SelectIcon" />
              <img onclick="<%= uicomponent.event("View", nodeExpression) %>" src="/eXoResources/skin/sharedImages/Blank.gif" class="ViewIcon" />
            </div>
          </td>
        </tr>
    <%
        }
      }
    %> 
    </tbody>
  </table> <!--End UIGrid-->
  <%
  if(uicomponent.getUIPageIterator().getAvailablePage() > 1) {
    _ctx.renderUIComponent(uicomponent.getUIPageIterator()) ;
  }
  %>
</div>