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

<script>

	require(['SHARED/jquery', 'SHARED/dotdotdot'], function (jQuery, dotdotdot) {
		jQuery(document).ready(function () {
			jQuery(".contentTitle").dotdotdot();
			jQuery(".contentBodyText").dotdotdot();
			jQuery(".rightTitle").dotdotdot();
			jQuery(".rightBody").dotdotdot();
		});

		jQuery(window).resize(function () {
			jQuery(".contentTitle").dotdotdot();
			jQuery(".contentBodyText").dotdotdot();
			jQuery(".rightTitle").dotdotdot();
			jQuery(".rightBody").dotdotdot();
		})
	});
</script>

<%
def header = uicomponent.getHeader();
def isShowHeader = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_HEADER) && header != null && header.trim().length() != 0;

%>
<div id="OfficeMiddleActualites">

	<div class="news-header">
		<div class="global-title">
			<h3 class="news-title-top">$header</h3>
		</div>

		<div class="read-all-news">
			<a class="see-all-news" onclick="window.open('/portal/intranet/news');">See all news</a>
		</div>

	</div>




	<div class="news-content">

		<%
if (uicomponent.getUIPageIterator().getAvailable() == 0) {
%>
		<div class="emptyContent">
			<span><%= _ctx.appRes(uicomponent.getParent().getMessageKey()) %></span>
		</div>
		<%
} else {
  def currentPageData = uicomponent.getCurrentPageData();
  def nodes = new ArrayList();
    for (viewNode in currentPageData) {
        if(!Utils.isViewable(viewNode)) continue;
        nodes.add(viewNode);
    }

  def style = "";
  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_0 = uicomponent.getURL(nodes.get(0));
def itemDateCreated_0 = uicomponent.getCreatedDate(nodes.get(0));
def itemOwner_0 = uicomponent.getAuthor(nodes.get(0));

def imgSrc_0 = uicomponent.getIllustrativeImage(nodes.get(0));
def isShowImage_0 = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_ILLUSTRATION) && imgSrc_0 != null;

def itemName_0 = nodes.get(0).getName();
def itemTitle_0 = uicomponent.getTitle(nodes.get(0));
if (itemTitle_0 != null && itemTitle_0.trim().length() != 0)
  itemName_0 = itemTitle_0;
def itemSummary_0 = uicomponent.getSummary(nodes.get(0));
def itemSummaryField_0 = uicomponent.getSummaryField(nodes.get(0));
def isShowSummary_0 = uicomponent.isShowField(UICLVPortlet.PREFERENCE_SHOW_SUMMARY) && itemSummary_0 != null;

    %>

		<div class="news-contentLeft">

			<div class="backgroundLeft" style="background-image:url($imgSrc_0)">
				<div class="overlay"></div>
			</div>

			<div class="ombre">
			</div>
			<!--<img class="imgContainerOption2" src="$imgSrc_0" />-->
			<div class="contentText">
				<div class="contentTitle">
					<a href="$itemLink_0">$itemTitle_0</a>
				</div>
				<div class="contentBody" style="padding-bottom: 20px;">
					<div class="contentBodyText" >
						$itemSummary_0
					</div>
					<% if (isShowReadmore) { %>
					<span class="more" >
						<a href="$itemLink_0" class="read-more-news slide-read-more">
						<span>Lire la suite</span>
						</a>
					</span>
					<% } %>

				</div>
			</div>
		</div>
		<div class="news-contentRight">
			<% for (int i=1;i<nodes.size();i++) {
def viewNode = nodes.get(i);
        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;



      %>

			<div class="news-line">
				<div class="news-image" style="background-image:url($imgSrc)">
					<div class="overlay"></div>
					<!--<img class="imgContainerOption2" src="$imgSrc" />-->
				</div>
				<div class="rightText">

					<div class="rightTitle">
						<a href="$itemLink">$itemTitle</a>
					</div>

					<div class="rightBody">
						$itemSummary
					</div>
					<% if (isShowReadmore) { %>
					<div class="rightMore" style="padding-top:9px;">
						<a href="$itemLink" class="read-more-news"><span>Lire la suite</span></a>

					</div>
					<% } %>

				</div>

			</div>

			<%
    }

%>
		</div>

		<%

  }

%>
	</div>
</div>
