<%
	 /**
	 	* 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;


	 	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 rcontext = _ctx.getRequestContext() ;
		def jsManager = rcontext.getJavascriptManager().require("SHARED/WCMTemplatePack", "WCMTemplatePack");
	 	%>

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

	 	<div class="box-module homeWelcome">
	 	<h3 class="module-heading">Welcome</h3>
	 	<div class="module-content">
	 	<%
	 	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">
	 		<%
	 		if(currentPageData.size() > 0){
		 		viewNode = currentPageData.get(currentPageData.size() - 1);
	 			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/MM/yyyy");
	 			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;

	 			def itemIcon = uicomponent.getContentIcon(viewNode);

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

	 			%>
	 			<%=uicomponent.addQuickEditDiv("Column1 media " + ((i%2==1)?"odd":"even"),, viewNode)%>
	 			<div class="media-inner">


	 			<div class="media-body">

	 			<%

	 			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 (isShowSummary) {
	 				%><div class="summary">
	 				<%
	 				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 href="$itemLink" rel="tooltip" data-placement="bottom" title="<%= _ctx.appRes("UICLVPresentation.label.readmore") %>"><%= _ctx.appRes("UICLVPresentation.label.readmore") %></a></div><%
	 			}
	 			%>
	 			</div>
	 			</div><!--media-body-->
	 			</div><!--media-inner-->
	 			</div>
	 			<a class="btn btn-primary" href="$itemLink">More</a>
	 			<%
	 		}
	 		%>

	 		<%
	 		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">$labelRefreshAction</a>
	 			</div>
	 			</div>
	 			<%
	 		}
	 		if (uicomponent.showPaginator()) { %>
	 			<div class="paginatorDefault">
	 			<%	uicomponent.renderChild(UICustomizeablePaginator.class); %>
	 			</div>
	 			<%
	 		}
	 		%>

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