<%
   /**
    * Created by The eXo Platform SAS
    * Author : eXoPlatform
    *          chuong.phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
    * Aug 20, 2009
    */

    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;
    import org.exoplatform.services.jcr.core.ManageableRepository;
    import org.exoplatform.webui.application.WebuiRequestContext;


    def propertyName = "exo:title";
    def repo = "";
    def workspace = "";
    def uuid = "";

    def siteName = org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getPortalOwner();
    Locale locale = WebuiRequestContext.getCurrentInstance().getLocale();
    def language = locale.getLanguage();

    def draftMsg = _ctx.appRes("PublicationStates.draft");
    def publishedMsg = _ctx.appRes("PublicationStates.published");
    %>

    <div id="$uicomponent.id" class="threeColumnsCLVTemplate">
    <section class="well-8 cnt5">
        <div class="container">
          <h3 class="block-title center">WHAT THEY SAY</h3>
    <%
    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;
    %>

    <%

    if (uicomponent.getUIPageIterator().getAvailable() == 0) {
      %>
      <div  >
      <span><%= _ctx.appRes(uicomponent.getParent().getMessageKey()) %></span>
      </div>
      <%
    } else {
      %>
      <div >
       <div >
      <%
      def currentPageData = uicomponent.getCurrentPageData();
      for (def i = 0; i < currentPageData.size(); i++) {
      if(i%2 == 0){%><div class="row"><%}
%>
<div class="grid_6">
              <div class="box-4">
<%
        def viewNode = currentPageData.get(i);
        if(!Utils.isViewable(viewNode)) continue;
        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 itemSummary = uicomponent.getSummary(viewNode);
        def itemSummaryField = uicomponent.getSummaryField(viewNode);
        def isShowSummary = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_SUMMARY) && itemSummary != null;

        repo = ((ManageableRepository)viewNode.getSession().getRepository()).getConfiguration().getName();
        workspace = viewNode.getSession().getWorkspace().getName();
        uuid = viewNode.getUUID();

        %>

        <%=uicomponent.addQuickEditDiv("Column3", viewNode)%>
        
        <%
        if(isShowImage) {
          %><div class="box-4_aside"><img alt="$itemName" rel="tooltip" title="$itemName" src="$imgSrc"/></div><%
        }
        %>
        
        <%
        if (uicomponent.isViewMode()){
          if (isShowTitle) {
            if (isShowLink) {
              %><div class="heading"><a href="$itemLink" rel="tooltip" data-placement="bottom" title="$itemName">$itemName</a></div><%
            } else {
              %>
              <div class="heading">
              <% print uicomponent.getInlineEditingField(viewNode, "exo:title", itemName, "TEXT", "CLVTitle_"+String.valueOf(i), "GroovyCLVTitle", true, "button_direction=left-to-right","fast_publish=" + uicomponent.getFastPublicLink(viewNode));%>
              </div>
              <%
            }
          }
        }
        else {
          if (isShowTitle) {
            if (isShowLink) {
              %><div class="heading WCMInlineEditable" contenteditable="true" propertyName="<%=propertyName%>" repo="<%=repo%>" workspace="<%=workspace%>" uuid="<%=uuid%>" siteName="<%=siteName%>" language="<%=language%>" publishedmsg="<%=publishedMsg%>" draftmsg="<%=draftMsg%>" fastpublishlink="<%=uicomponent.getFastPublicLink(viewNode)%>"><a href="$itemLink" rel="tooltip" data-placement="bottom" title="$itemName">$itemName</a></div><%
            } else {
              %>
              <div class="heading WCMInlineEditable" contenteditable="true" propertyName="<%=propertyName%>" repo="<%=repo%>" workspace="<%=workspace%>" uuid="<%=uuid%>" siteName="<%=siteName%>" language="<%=language%>" publishedmsg="<%=publishedMsg%>" draftmsg="<%=draftMsg%>" fastpublishlink="<%=uicomponent.getFastPublicLink(viewNode)%>">
              <% print uicomponent.getInlineEditingField(viewNode, "exo:title", itemName, "TEXT", "CLVTitle_"+String.valueOf(i), "GroovyCLVTitle", true, "button_direction=left-to-right","fast_publish=" + uicomponent.getFastPublicLink(viewNode)); %>
              </div>
              <%
            }
          }
        }

        if (isShowDate) {
          
        }
        if (isShowSummary) {
          
          if (itemSummaryField!=null) {
            print uicomponent.getInlineEditingField(viewNode, itemSummaryField, itemSummary, "TEXTAREA", "Text_"+String.valueOf(i), "CLV2ColSummary", true, "height=80px","fast_publish=" + uicomponent.getFastPublicLink(viewNode));
          }
          
        }
        %>
        <%
        if (isShowReadmore) {
          %><div class="readLink"><a href="$itemLink" rel="tooltip" data-placement="bottom" title="<%= _ctx.appRes("UICLVPresentation.label.readmore") %>"><%= _ctx.appRes("UICLVPresentation.label.readmore") %></a></div><%
        }
        %>
        </div>
        </div>
        </div>
        <%if(i%2 == 1){%></div><%}%>
        
        
        <%
      }
      %>
      </div>
      <%
      String labelRefreshAction = _ctx.appRes("UICLVPresentation.action.refresh");
      def isShowRefresh = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_REFRESH_BUTTON);
      %>


      <%
      if (isShowRefresh) { %>
        <div class="captionFunc clearfix">
        <%

        String link = uicomponent.event("Refresh");
        %>
        <div class="captionRefresh right">
        <a href="$link" class="btn" rel="tooltip" data-placement="bottom" title="$labelRefreshAction">$labelRefreshAction</a>
        </div>

        </div>
        <%
      }
      if (uicomponent.showPaginator()) { %>
        <div class="paginatorDefault" >
        <%    uicomponent.renderChild(UICustomizeablePaginator.class) %>
        </div>
        <%
      }
      %>

      </div> <%
    }
    %>
    </div>
    </section>
    </div>