<%
	 /**
	 	* Created by The eXo Platform SAS
	 	* Author : eXoPlatform
	 	*          benjamin.paillereau@exoplatform.com
	 	* Aug 27, 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;
	 	import org.exoplatform.services.wcm.utils.WCMCoreUtils;
	 	import org.exoplatform.services.cms.comments.CommentsService;

	 	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");
	 	def commentService = WCMCoreUtils.getService(CommentsService.class);
	 	%>

	 	<div class="documentsCLVTemplate" id="$uicomponent.id">

	 	<div class="clv uiBox blogListBox">
	 	<%
	 	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 (isShowHeader || isShowRssLink) {
	 		%>
	 		<h5 class="title">
	 		<%if (isShowRssLink) {
	 			%><a class="rssIcon pull-right" onclick="javascript:window.open('$rssLink');" style="cursor:pointer" rel="tooltip" data-placement="bottom" title="<%= _ctx.appRes("UICLVPresentation.label.rssFeed") %>"><i class="uiIconRss uiIconLightGray">&nbsp;</i></a><%
	 		}
	 		if(isShowHeader) {%> <span>$header</span><%}%>
	 			</h5>
	 		<%
	 	}
	 	%>
	 	<%
	 	if (uicomponent.getUIPageIterator().getAvailable() == 0) {
	 		%>
	 		<div class="emptyContent">
	 		<span><%= _ctx.appRes(uicomponent.getParent().getMessageKey()) %></span>
	 		</div>
	 		<%
	 	} else {
	 		def currentPageData = uicomponent.getCurrentPageData();
	 		def i=0;
	 		%>
	 		<div class="uiContentBox">
	 		<%
	 		for (viewNode in currentPageData) {
	 			if(!Utils.isViewable(viewNode)) continue;
	 			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 itemWebdavLink = uicomponent.getWebdavURL(viewNode);
	 			uicomponent.setDateTimeFormat("dd/MMM/yyyy");
	 			def itemDateCreated = uicomponent.getCreatedDate(viewNode);
	 			int slashIndex1 = itemDateCreated.indexOf('/');
	 			int slashIndex2 = itemDateCreated.lastIndexOf('/');
	 			def itemCreatedDay = itemDateCreated.substring(0, slashIndex1);
	 			def itemCreatedMonth = itemDateCreated.substring(slashIndex1 + 1, slashIndex2);
	 			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;

	 			def itemIcon = uicomponent.getContentIcon(viewNode);

	 			repo = ((ManageableRepository)viewNode.getSession().getRepository()).getConfiguration().getName();
	 			workspace = viewNode.getSession().getWorkspace().getName();
	 			uuid = viewNode.getUUID();
	 			def commentCount = commentService.getComments(viewNode, null).size();

	 			%>
	 			<%=uicomponent.addQuickEditDiv("Column1 media " + ((i%2==1)?"odd":"even"),, viewNode)%>
	 			<div class="clearfix">
	 				<div class="badge"><p><time datetime="2013-01-01">$itemCreatedDay</time></p><p class="numb">$itemCreatedMonth</p></div>
	 				<div class="extra-wrap">
	 					<%

				 			if (uicomponent.isViewMode()){
				 				if (isShowTitle) {
				 					%><%
				 					if (isShowLink) {
				 						%><h3 class=""><a href="$itemLink" rel="tooltip" data-placement="bottom" title="$itemName">$itemName</a></h3><%
				 					} else {
				 						%>
				 						<h3 class="">
				 						<% print uicomponent.getInlineEditingField(viewNode, "exo:title", itemName, "TEXT", "CLVTitle_"+String.valueOf(i), "GroovyCLVTitle", true, "button_direction=left-to-right","fast_publish=" + uicomponent.getFastPublicLink(viewNode));%>
				 						</h3>
				 						<%
				 					}
				 				}
				 			}
				 			else {
				 				if (isShowTitle) {
				 					%><%
				 					if (isShowLink) {
				 						%><h3 class=" 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></h3><%
				 					} else {
				 						%>
				 						<h3 class=" 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)); %>
				 						</h3>
				 						<%
				 					}
				 				}
				 			}

				 			%>
			 			<div class="clearfix">
 							<p>Posted by&nbsp;</p><a class="pull-left" href="#">$itemOwner</a><a class="pull-right" href="#">$commentCount Comment(s)</a>
			 			</div>
	 				</div>
	 			</div>
	 			<div class="media-inner">
	 			<%
	 			if (isShowImage) {
	 				%><a class="image pull-left img-polaroid" title="$itemName"><img alt="$itemName" rel="tooltip" data-placement="bottom" title="$itemName" src="$imgSrc" /></a><%
	 			}
	 			%>
	 			<i  class="$itemIcon image pull-left"></i>
	 			<div class="media-body">



	 			<%

	 			if (isShowDate) {
	 				%><div class="dateAndMail">$itemDateCreated</div><%
	 			}
	 			if (isShowSummary) {
	 				%><div class="summary margBot3">
	 				<%
	 				if (itemSummaryField!=null) {
	 					print uicomponent.getInlineEditingField(viewNode, itemSummaryField, itemSummary, "TEXTAREA", "Text_"+String.valueOf(i), "CLV1ColumnPresent", true,"fast_publish=" + uicomponent.getFastPublicLink(viewNode));
	 				}
	 				%>
	 				</div>
	 				<%
	 			}%>

	 			<%
	 			if (isShowReadmore) {
	 				%>

	 				<div class="readLink"><a class="btn btn-primary" href="$itemLink" rel="tooltip" data-placement="bottom" title="<%= _ctx.appRes("UICLVPresentation.label.readmore") %>"><%= _ctx.appRes("UICLVPresentation.label.readmore") %></a></div><%
	 			}
	 			%>
	 			</div><!--media-body-->
	 			</div><!--media-inner-->
	 			</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 pull-left">
	 			<a href="$link"  class="btn" rel="tooltip" data-placement="bottom" title="$labelRefreshAction"></a>
	 			</div>
	 			</div>
	 			<%
	 		}
	 		if (uicomponent.showPaginator()) { %>
	 			<div class="paginatorDefault">
	 			<%	uicomponent.renderChild(UICustomizeablePaginator.class); %>
	 			</div>
	 			<%
	 		}
	 		%>

	 		</div><!--uiContentBox-->
	 		<%
	 	}
	 	%>
	 	</div>
	 	</div>