<%
  import java.util.Locale;
  import java.text.DateFormat;
  import org.exoplatform.portal.webui.util.Util;
  import java.net.URLEncoder;
  import org.exoplatform.wiki.commons.Utils;
  import org.apache.commons.lang.StringEscapeUtils;
  
  Locale currentLocale = Util.getPortalRequestContext().getLocale();
%>
<div class="uiAttachmentUploadListForm clearfix">
  <% uiform.begin(); %>
    <h6 class="attachmentTit"><%= _ctx.appRes("UIAttachmentUploadListForm.label.AttachmentTitle"); %></h6>
    <table class="uiGrid table table-hover table-striped">
      <thead>
        <tr>
          <th><%= _ctx.appRes("UIAttachmentUploadListForm.label.File"); %></th>
          <th><%= _ctx.appRes("UIAttachmentUploadListForm.label.Creator"); %></th>
          <th><%= _ctx.appRes("UIAttachmentUploadListForm.label.LastUpdate"); %></th>
          <th class="center"><%= _ctx.appRes("UIAttachmentUploadListForm.label.Action"); %></th>
        </tr>
      </thead>
      <tbody>
    <%
      def attachments = uicomponent.getAttachments();
      int index = 0;
      DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, currentLocale);
      String creator;
      String downloadLink;
      
      for(attachment in attachments){
        index++;        
        creator = StringEscapeUtils.escapeHtml(Utils.getFullName(attachment.getCreator()));
        downloadLink = attachment.getDownloadURL();
        String extension = Utils.getExtension(attachment.getName()) ;
        if (extension != null && !extension.equals("")) {
          extension = new StringBuilder(extension.substring(0, 1)).toString().toUpperCase() + extension.substring(1);
        }
    %>
        <tr>
          <td>
            <i class="uiIcon16x16FileDefault uiIcon16x16File$extension"></i>&nbsp;
          	<a rel="tooltip" data-placement="bottom" title="<%= _ctx.appRes("UIAttachmentUploadListForm.label.DownloadAttachment"); %>" href="$downloadLink" target="_blank"><%= attachment.getFullTitle() %></a>
          </td>
          <td><%= creator %></td>
          <td><%= df.format(attachment.getUpdatedDate().getTime())%></td>
          <td class="center"><% uicomponent.renderActions(attachment); %> </td>
        </tr>
    <%}%>
    
      </tbody>
    </table>
  <% uiform.end();%>
</div>