<%
  import org.exoplatform.webui.core.UIComponent ;
  import org.exoplatform.webui.form.UIForm;

  String[] beanFields =  uicomponent.getBeanFields() ;  
  String[] beanActions =  uicomponent.getBeanActions() ;
  UIComponent uiParent = uicomponent.getParent() ;
  String name = uicomponent.getLabel() ;
  UIForm uiForm = uicomponent.getAncestorOfType(UIForm.class); 
%>
<div id="$uicomponent.id">
	<table class="UIGrid" cellspacing="0" borderspacing="0">
	  <thead>
	  	<tr>
	      <%if(name != null) {%>
		      <%for(field in beanFields) { %>
		          <th><%=_ctx.appRes(name+".header."+field)%></th>
		      <%}%>
		      <%if(beanActions != null) { %>
		          <th><%=_ctx.appRes(name+".header.action")%></th>
		      <%}%>
	      <%}%>
	      <%if(name == null) {%>
	      	<%for(field in beanFields) { %>
		          <th><%=_ctx.appRes(uiParent.getName()+".header."+field)%></th>
		      <%}%>
		      <%if(beanActions != null && beanActions.length > 0) { %>
		          <th><%=_ctx.appRes(uiParent.getName()+".header.action")%></th>
		      <%}%>
		    <%}%>
	    </tr>
	  </thead>
	  <tbody>
	  <%if(uicomponent.getUIPageIterator().getAvailable() < 1) {%>
	    <tr>
	      <td style="color: #EF5604; font-style: italic;text-align: center;" colspan="<%=beanFields.length%>">
	        <%=_ctx.appRes(uicomponent.getId() + ".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 class="$rowClass">
	  <%
			    for(field in beanFields) { 
			       def fieldValue = uicomponent.getFieldValue(bean, field) ;
			      def cssClass = "" ;
			      if(fieldValue != null) {
			        def fieldClass = fieldValue.getClass() ;
			        if(fieldClass == Integer.class)  cssClass = "number" ;
			        else if(fieldClass == java.util.Date.class)  cssClass = "Datetime" ;
			        else cssClass = "Text" ;
			      } else {
			      	fieldValue = "";
			      }
			      println "<td class=\""+cssClass+"\">"+fieldValue+"</td>";
		    
		      }  
	        if(beanActions != null && beanActions.length > 0) { 
	  %>
				  <td>         
		        <div class="ActionContainer">
		          <%	          
		            def beanIdField = uicomponent.getBeanIdField() ;           
		            for(action in beanActions) { 
		              def beanId = uicomponent.getFieldValue(bean, beanIdField)  ;
			            if(action == null) continue;           
		              String title = _ctx.appRes(uicomponent.getParent().getName() + ".action.title." + action);
		              String actionLink = "";
		              if(uiForm != null){
		                actionLink = uiForm.event(action, uicomponent.getParent().getId(), beanId);
		              } else {
		                actionLink = uiParent.event(action, beanId);
		              }
			        %>	           
			            <img onclick="$actionLink" title="$title" src="/eXoResources/skin/sharedImages/Blank.gif" class="${action}Icon" alt="" />
		          <%}%>                 
		        </div>
		      </td>
	  <%
	        }
	  %>  
			    </tr>
		<%
		    }
		  }
		%> 
	  </tbody>
	</table> <!--End UIGrid-->
</div>
<%if(uicomponent.getUIPageIterator().getAvailablePage() > 1) {%>
<%_ctx.renderUIComponent(uicomponent.getUIPageIterator())%>
<% } %>