<%
    import javax.jcr.Node;
    import org.exoplatform.wcm.webui.paginator.UICustomizeablePaginator;
    import org.exoplatform.wcm.webui.clv.UICLVPortlet;
    import org.exoplatform.wcm.webui.Utils;
    import org.exoplatform.services.wcm.core.NodeLocation;


    def header = uicomponent.getHeader();
    def rssLink = uicomponent.getRssLink();
    def isShowRssLink = uicomponent.isShowRssLink();
    def isShowHeader = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_HEADER) && header != null && header.trim().length() != 0;
%>
<div class="AnnouncementTemplate">    
        <%if (isShowHeader || isShowRssLink) {%>
		<div class="TopBoxHeader ClearFix">
            <%if (isShowRssLink) {%>
				<a class="RssIcon" href="$rssLink" target="_newrss" title="<%= _ctx.appRes("UICLVPresentation.label.rssFeed") %>">&nbsp;</a><%
            }
            if(isShowHeader) {%>
              $header
            <%}%> 
		 </div>		  
        <%}%>       
  <%if (uicomponent.getUIPageIterator().getAvailable() == 0) {
    if (!uicomponent.isViewMode()) {%>
    <div class="emptyContent">
      <span><%= _ctx.appRes(uicomponent.getParent().getMessageKey()) %></span>
    </div>
    <%}
  } else {%>

    <div id="$uicomponent.id" class="UICLVPresentation">
        <%
          def currentPageData = uicomponent.getCurrentPageData();
          def i=currentPageData.size()-1;
          def viewNode = currentPageData.get(i);

          def isShowTitle = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_TITLE);
          def isShowDate = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_DATE_CREATED);
          def isShowLink = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_LINK);
          def isShowReadmore = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_READMORE);

          def itemLink = uicomponent.getURL(viewNode);
          def itemDateCreated = uicomponent.getCreatedDate(viewNode);
          def itemOwner = uicomponent.getAuthor(viewNode);

          def imgSrc = uicomponent.getIllustrativeImage(viewNode);
          def isShowImage = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_ILLUSTRATION) && imgSrc != null;

          def itemName = viewNode.getName();
          def itemTitle = uicomponent.getTitle(viewNode);

          if (itemTitle != null && itemTitle.trim().length() != 0)
            itemName = itemTitle;
          def _trustedItemName = org.exoplatform.commons.utils.HTMLSanitizer.sanitize(itemName);

          def itemSummary = uicomponent.getSummary(viewNode);
          def itemSummaryField = uicomponent.getSummaryField(viewNode);
          def isShowSummary = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_SUMMARY) && itemSummary != null;

          //def isShowSummary = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_SUMMARY) && itemSummary != null;
          //def  html = viewNode.getNode("default.html/jcr:content").getProperty("jcr:data").getString();
        %>

        <%=uicomponent.addQuickEditDiv("Column1", viewNode)%>

              <%if(isShowImage) {%>
        <a class="Image" title="$_trustedItemName"><img alt="$_trustedItemName" src="$imgSrc" /></a><%
              }%>
                <%if (isShowTitle) {
          if (isShowLink) {%>
            <div class="Title"><a href="$itemLink">$itemName</a></div><%
                    } else {%>
            <div class="Title">$itemName</div><%
                    }
                }
                if (isShowDate) {%>
          <div class="DateAndMail">$itemDateCreated by $itemOwner</div>
        <%}
                if (isShowSummary) {%>
          <div class="Summary content-display">
            <%if (itemSummaryField!=null) {
              print uicomponent.getInlineEditingField(viewNode, itemSummaryField, itemSummary, "TEXTAREA", "Text_"+String.valueOf(i), "CLV1ColumnPresent", true);
            }%>
          </div>
        <%}%>
      </div>
  <%}%>

  <div class="CaptionFunc ClearFix">
      <% String labelRefreshAction = _ctx.appRes("UICLVPresentation.action.refresh");
        def isShowRefresh = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_REFRESH_BUTTON);
        if (isShowRefresh) {
          String link = uicomponent.event("Refresh");
          %>
            <div class="CaptionRefresh">
              <a href="$link">$labelRefreshAction</a>
            </div>
        <%}
      if (uicomponent.showPaginator()) {
        uicomponent.renderChild(UICustomizeablePaginator.class);
            }
    %>
    </div>
</div>
