<%

  import org.exoplatform.webui.core.UIComponent ;
  import org.exoplatform.webui.form.UIForm;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import org.exoplatform.commons.utils.HTMLEntityEncoder;

  String[] beanFields =  uicomponent.getBeanFields() ;  
  String[] beanActions =  uicomponent.getBeanActions() ;  
  def uiParent = uicomponent.getParent();

  String name = uicomponent.getLabel() ;
  UIForm uiForm = uicomponent.getAncestorOfType(UIForm.class); 
  
  DateFormat dateFormat = null;
%>
<div id="$uicomponent.id">
    <table class="uiGrid table table-hover table-striped" cellspacing="0" summary="Page list">
        <thead>
            <tr>
                <%if(name != null) {%>
                    <%for(field in beanFields) { %>
                            <th id="<%=field%>" scope="col"><%=_ctx.appRes(name+".header."+field)%></th>
                    <%}%>
                    <%if(beanActions != null) { %>
                            <th id="actions" scope="col"><%=_ctx.appRes(name+".header.action")%></th>
                    <%}%>
                <%}%>
                <%if(name == null) {%>
                    <%for(field in beanFields) { %>
                            <th id="<%=field%>" scope="col"><%=_ctx.appRes(uiParent.getName()+".header."+field)%></th>
                    <%}%>
                    <%if(beanActions != null && beanActions.length > 0) { %>
                            <th class="center" id="actions" scope="col"><%=_ctx.appRes(uiParent.getName()+".header.action")%></th>
                    <%}%>
                <%}%>
            </tr>
        </thead>
        <tbody class="FeedBox">
			<% 			
			for (bean in uicomponent.getBeans())  { 				
			%>   
	        <tr >
			      <%
		        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(java.util.Date.class.isAssignableFrom(fieldClass)) {
		              if(dateFormat == null) dateFormat = new SimpleDateFormat("HH:mm:ss yyyy-MM-dd");
		              cssClass = "dateTime" ;
		              fieldValue = dateFormat.format(fieldValue);
		            } 
		            else {
		                cssClass = "text" ;
		                fieldValue = HTMLEntityEncoder.getInstance().encode(fieldValue.toString());
		            }
		          } else {
		            fieldValue = "";
		          }
		          String value = fieldValue.toString();
		          println "<td headers=\"$field\"><span class=\""+cssClass+"\" title='$fieldValue'>"+fieldValue+"</span></td>";
		        }  
			      if(beanActions != null && beanActions.length > 0) { 
			      %>
	           <td class="center actionContainer" headers="actions"> 
	                  <%
	                    def beanIdField = uicomponent.getBeanIdField() ;           
	                    for(action in beanActions) { 
	                      def beanId = uicomponent.getFieldValue(bean, beanIdField)  ;
	                        if(action == null) continue;
	                      String title = _ctx.appRes(uiParent.getParent().getName() + ".action.title." + action);
	                      String actionLink = uiParent.event(action, beanId);
	                    %>             

	                        <a href="javascript:void(0);" onclick="$actionLink" data-toggle="tooltip" data-placement="bottom"  data-original-title="$title" class="actionIcon" ><i class="uiIcon${action} uiIconLightGray"></i></a>
	                  <%}%>          
	            </td>
	      <%
	            }
	      %>  
            </tr>
        <%
            }
        %>
        </tbody>
    </table>
</div>