<% 
	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="UICLVPresentation" id="$uicomponent.id"> 

	<%	
		String 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 ClearFix">
			<%
			if (isShowHeader) {
				%>
				<div class="Header"><%= header %></div>	
				<%
			}
			if (isShowRssLink) {
				%><a class="RssIcon" onclick="javascript:window.open('$rssLink');" style="cursor:pointer"><%= _ctx.appRes("UICLVPresentation.label.rssFeed") %></a><%
			}
			%>
				
			</div>
	<div class="Caption">
		<% 	
			String labelRefreshAction = _ctx.appRes("UICLVPresentation.action.refresh");		
			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();							
				String labelReadMore = _ctx.appRes("UICLVPresentation.label.readmore");
				String draftLabel = _ctx.appRes("UICLVPresentation.label.draft");
				String editActionLabel = _ctx.appRes("UICLVPresentation.action.edit");
				def i= 0;
				for (viewNode in currentPageData) {
					if(!Utils.isViewable(viewNode)) continue;
					i++;
					String itemLink = uicomponent.getURL(viewNode);
					String itemName = viewNode.getName();
					String itemSummary = uicomponent.getSummary(viewNode);
					String itemSummaryField = uicomponent.getSummaryField(viewNode);
			    	String itemTitle = uicomponent.getTitle(viewNode);
					String itemDateCreated = uicomponent.getCreatedDate(viewNode);
					String itemOwner = uicomponent.getAuthor(viewNode);			
					String imgSrc = uicomponent.getIllustrativeImage(viewNode);								
					if (itemTitle != null && itemTitle.trim().length() != 0) {
						itemName = itemTitle;
					}						
					%>
					<%=uicomponent.addQuickEditDiv("CaptionItem", viewNode)%>
				<%
                if(imgSrc != null && uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_ILLUSTRATION)) {
                    %><img alt="$itemName" src="$imgSrc" width="30" style="float:left; padding-right:5px;" /><%
                }
								if (uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_TITLE)) {
									%>
										<div class="CaptionTitle" >
											<% 
												if (uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_LINK)) {
													%><a href="$itemLink">$itemName</a><% 
												} else { 
                          print uicomponent.getInlineEditingField(viewNode, "exo:title", itemName, "TEXT", "CLVTitle_"+String.valueOf(i), "GroovyCLVTitle", true, "button_direction=left-to-right");
												} 
											%> 
										</div>
									<%							
								} 
								if (itemDateCreated != null && uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_DATE_CREATED)) { 
									%><div class="CaptionDate"><%=itemDateCreated%></div><% 
								} 
							%>											
							<div class="CaptionContent">				
								<% 
									if (itemSummary != null && itemSummary.trim().length() != 0 && uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_SUMMARY)) {
                    if (itemSummaryField!=null) {
                      print uicomponent.getInlineEditingField(viewNode, itemSummaryField, itemSummary, "TEXTAREA", "Text_"+String.valueOf(i), "CLV1ColumnPresent", true);
                    }
									}
								%>
							</div>
	            <%
	            if (uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_READMORE)) {
	            %>
	            <div class="CaptionViewMore"><a href="$itemLink"><%=labelReadMore%>&raquo;</a></div>
	            <%
	            }
	            %>
						</div>
					<%							
				} //end for
			} //end else	
		%>
		<div class="CaptionFunc ClearFix">
			<% 
			  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>
</div>
