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

%>

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

	<div class="CLV">
		<%
			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="TopBoxHeader">
				<%	
			  if (isShowHeader) {
					%>
						<div class="TitleBarL">
							<div class="TitleBarR">
                <div class="TitleBarM">
                  <%if (isShowRssLink) {
                    %><a class="RssIcon" href="$rssLink" target="_newrss" title="<%= _ctx.appRes("UICLVPresentation.label.rssFeed") %>">&nbsp;</a><%
                  }%>
                  $header                  
                </div>
							</div>
						</div>
					<%
				}
				%>
				<div class="ClearBoth"><span></span></div>
			</div>
			<%
			if (uicomponent.getUIPageIterator().getAvailable() == 0) {
				%>
					<div style="height: 20px; text-align: center; font-size: 13px; background: white; padding: 10px; margin: 5px;">
						<span><%= _ctx.appRes(uicomponent.getParent().getMessageKey()) %></span>
					</div>
				<%
			} else {
			  def currentPageData = uicomponent.getCurrentPageData();
			  %>
			  	<div class="Contents">
			  		<%
							for (viewNode in currentPageData) {
								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 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 isShowSummary = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_SUMMARY) && itemSummary != null;
								
								def itemIcon = uicomponent.getContentIcon(viewNode);
								
      					%>
                <%=uicomponent.addQuickEditDiv("Column1", viewNode)%>
                <%
      			    	if (isShowImage) {
                    %><a class="Image" title="$itemName"><img alt="$itemName" src="$imgSrc" /></a><%
											}
											%>
												<div class="Content">
													<%
													if (isShowTitle) {
														%><div title="$itemName" class="FloatLeft $itemIcon"></div><%
														if (isShowLink) {
															%><div class="Title"><a href="$itemWebdavLink" target="_newdoc" title="$itemName">$itemName</a></div><%
														} else {
															%><div class="Title">$itemName</div><%
														}
													}
													
													if (isShowDate) {
													  %><div class="DateAndMail">$itemDateCreated</div><%
													}
													if (isShowSummary) { 
														%><div class="Summary">$itemSummary</div><% 
													}
													if (isShowReadmore) {
													  %><div class="ClearBoth"><span></span></div><div class="ReadLink"><a href="$itemWebdavLink"><%= _ctx.appRes("UICLVPresentation.label.readmore") %></a></div><%
													}
													%>
												</div>
												<div class="ClearBoth"><span></span></div>
											<%
										%>
									</div>
				    		<%
				  		}
				  	%>
			  	</div>
			  <%	
			}
		%>
	</div>
	<div class="CaptionFunc">
		<% 
		  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 style="clear: left"><span></span></div>
	</div>
</div>
