<%
/*
<!--

    Copyright (C) 2003-2016 eXo Platform SAS.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Affero General Public License
    as published by the Free Software Foundation; either version 3
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, see<http://www.gnu.org/licenses/>.

-->
*/
%>
<%

	/* Adapted from integration FileUIActivity.gtmpl of PLF 4.3.1 */

  import org.exoplatform.portal.webui.util.Util;
  import org.exoplatform.webui.form.UIFormTextAreaInput;
  import org.exoplatform.social.core.service.LinkProvider;
  import org.exoplatform.social.core.space.model.Space;
  import org.exoplatform.social.webui.Utils;
  import org.exoplatform.social.core.service.LinkProvider;
  import org.apache.commons.lang.StringUtils;
  import org.exoplatform.wcm.webui.reader.ContentReader;
  import org.apache.commons.lang.StringEscapeUtils;
  
  //ECMS import BEGIN
  import org.exoplatform.wcm.ext.component.activity.ContentPresentation;
  import org.exoplatform.services.jcr.util.Text;
  import org.exoplatform.services.jcr.core.ManageableRepository;
  import org.exoplatform.container.ExoContainer;
  import org.exoplatform.container.ExoContainerContext;
  import org.exoplatform.container.xml.PortalContainerInfo;
  import org.exoplatform.services.cms.jcrext.activity.ActivityCommonService;

  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
  import org.exoplatform.wcm.connector.collaboration.OpenInOfficeConnector;

  //ECMS import END

  def pcontext = Util.getPortalRequestContext();
  def labelActivityHasBeenDeleted = _ctx.appRes("UIActivity.label.Activity_Has_Been_Deleted");
  def activity = uicomponent.getActivity();
  def activityDeletable = uicomponent.isActivityDeletable();
  def activityCommentAndLikable = uicomponent.isActivityCommentAndLikable();
  def streamOwner = activity.getStreamOwner();
  def currentNode = uicomponent.getContentNode(0);
  
  def rcontext = _ctx.getRequestContext();
  rcontext.getJavascriptManager().require("SHARED/jquery", "gj").addScripts("gj(document).ready(function() { gj(\"*[rel='tooltip']\").tooltip();});");

  if (currentNode!=null) {
    def currentNodePath = currentNode.getSession().getWorkspace().getName() + ":" + currentNode.getPath();
    rcontext.getJavascriptManager().require("SHARED/openDocumentInOffice", "od")
    	.addScripts("gj(document).ready(function(){od.OpenDocumentInOffice.updateLabel('$currentNodePath', '${activity.id}'); });");
  }

  def viewActivityTip = _ctx.appRes("UIActivity.msg.ViewActivity");
 
  if (activity != null) {

  def jsManager = pcontext.getJavascriptManager();  
  
  def labelComment = _ctx.appRes("UIActivity.label.Comment");
  def labelLike = _ctx.appRes("UIActivity.label.Like");
  def labelUnlike = _ctx.appRes("UIActivity.label.Unlike");
  def labelSource = _ctx.appRes("UIActivity.label.Source");
  def inputWriteAComment = _ctx.appRes("UIActivity.input.Add_your_comment");
  def labelShowAllComments = _ctx.appRes("UIActivity.label.Show_All_Comments");
  def labelHideAllComments = _ctx.appRes("UIActivity.label.Hide_All_Comments");
  def labelShowPreviousComments = _ctx.appRes("UIActivity.label.Show_Previous_Comments");
  def labelOnePersonLikeThis = _ctx.appRes("UIActivity.label.One_Person_Like_This");
  def labelTwoPersonLikeThis=_ctx.appRes("UIActivity.label.Two_Person_Like_This");
  def labelOneAndOthersLikeThis=_ctx.appRes("UIActivity.label.One_And_Others_Like_This");  
  def labelYouLikeThis = _ctx.appRes("UIActivity.label.You_Like_This");
  def labelYouAndOnePersonLikeThis = _ctx.appRes("UIActivity.label.You_And_One_Person_Like_This");
  def labelYouAndOthersLikeThis = _ctx.appRes("UIActivity.label.You_And_Others_Like_This");

  def captionConfirmation=StringEscapeUtils.escapeHtml(_ctx.appRes("UIActivity.label.Confirmation"));
  def labelConfirmbutton=StringEscapeUtils.escapeHtml(_ctx.appRes("UIActivity.label.Confirm_Delete_Activity-Button"));
  def labelClosebutton=StringEscapeUtils.escapeHtml(_ctx.appRes("UIActivity.label.Cancel_Delete_Activity-Button"));
  def labelToDeleteThisComment=StringEscapeUtils.escapeHtml(_ctx.appRes("UIActivity.msg.Are_You_Sure_To_Delete_This_Comment"));
  def labelToDeleteThisActivity=StringEscapeUtils.escapeHtml(_ctx.appRes("UIActivity.msg.Are_You_Sure_To_Delete_This_Activity"));

  def likeActivityAction = uicomponent.event("LikeActivity", "true");
  def unlikeActivityAction = uicomponent.event("LikeActivity", "false");
  
  def activityStatus = uicomponent.getActivityStatus();
  def contentName = uicomponent.getContentName(0);
  def activityContentTitle = Text.unescapeIllegalJcrChars(activity.title);
  def contentActivityUri =  uicomponent.getPreviewLink(_ctx);
  def mimeType = uicomponent.getMimeType(0);
  
  //
  def commentList = uicomponent.getComments();
  def allComments = uicomponent.getAllComments();
  def commentCount = 0;
  def commentHidden = 0;
  if (allComments) {
    commentCount = allComments.size();
    commentHidden = commentCount-commentList.size();
    labelShowAllComments = labelShowAllComments.replace("{0}", allComments.size() + "");
    labelHideAllComments = labelHideAllComments.replace("{0}", allComments.size() + "");
  }
  def displayedIdentityLikes = uicomponent.getDisplayedIdentityLikes();
  def identityLikesNum = 0;
  def totalLikesNum = uicomponent.getIdentityLikes().length;
  
  def loadLikesAction = uicomponent.event("LoadLikes");
  def labelLikes = null;
  def toggleDisplayLikesAction = uicomponent.event("ToggleDisplayLikes");
  def startTag = "<a onclick=\"$toggleDisplayLikesAction\" id=\"ToggleDisplayListPeopleLikes${activity.id}\" href=\"#ToggleDisplayListPeopleLikes\">";
  def endTag = "</a>";
  if (displayedIdentityLikes != null) {
    identityLikesNum = displayedIdentityLikes.length;
  }
  def commentListStatus = uicomponent.getCommentListStatus();
  def commentFormDisplayed = uicomponent.isCommentFormDisplayed();
  def likesDisplayed = uicomponent.isAllLoaded();
  //params for init UIActivity javascript object
  def params = """ {
      activityId: '${activity.id}',
      inputWriteAComment: '$inputWriteAComment',
      commentMinCharactersAllowed: '${uicomponent.getCommentMinCharactersAllowed()}',
      commentMaxCharactersAllowed: '${uicomponent.getCommentMaxCharactersAllowed()}',
      commentFormDisplayed: '$commentFormDisplayed',
      allCommentSize: '${allComments.size()}',
      commentFormFocused: '${uicomponent.isCommentFormFocused()}'
    } """
  //jsManager.addOnLoadJavascript("initUIActivity${activity.id}");
  jsManager.require("SHARED/social-ui-activity","activity").addScripts("activity.onLoad($params);");  
  jsManager.require("SHARED/wcm-utils", "wcmutil");      
  
  //make sures commentFormFocused is set to false to prevent any refresh to focus, only focus after post a comment
  uicomponent.setCommentFormFocused(false);
  def ownerName, ownerUri = "#", ownerAvatar, activityPostedTime, activityPostedTimeInSpace;
  def listPeopleLikeBlockClass = "", listPeopleBGClass = "";

  if (!likesDisplayed) {
    listPeopleLikeBlockClass = "displayNone";
  }
  
  if (uicomponent.isLiked()) {
    if (totalLikesNum > 2) {
      labelLikes = labelYouAndOthersLikeThis.replace("{0}", totalLikesNum - 1 + "");
    } else if (totalLikesNum == 2) {
      def likeId = (displayedIdentityLikes[0] == Utils.getViewerIdentity().getId()) ? displayedIdentityLikes[1] : displayedIdentityLikes[0];
      def id = Utils.getIdentityManager().getIdentity(likeId);
      labelLikes = labelYouAndOnePersonLikeThis.replace("{0}", id.profile.fullName);
    } else {
      labelLikes = labelYouLikeThis;
    }
  } else {
    if (totalLikesNum > 2) {
      def id = Utils.getIdentityManager().getIdentity(displayedIdentityLikes[0]);
      labelLikes = labelOneAndOthersLikeThis.replace("{0}", id.profile.fullName).replace("{1}", totalLikesNum - 1 + "");
    } else if (totalLikesNum == 1) {
      def id = Utils.getIdentityManager().getIdentity(displayedIdentityLikes[0]);
      labelLikes = labelOnePersonLikeThis.replace("{0}", id.profile.fullName);
    } else if (totalLikesNum == 2) {
      def id1 = Utils.getIdentityManager().getIdentity(displayedIdentityLikes[0]);
      def id2 = Utils.getIdentityManager().getIdentity(displayedIdentityLikes[1]);
      labelLikes = labelTwoPersonLikeThis.replace("{0}", id1.profile.fullName).replace("{1}", id2.profile.fullName);
    }
  }

  if (!labelLikes) {
   //hides diplayPeopleBG
   listPeopleBGClass = "displayNone";
  }

  activityPostedTime = uicomponent.getPostedTimeString(_ctx, activity.postedTime);

  def ownerIdentity = uicomponent.ownerIdentity;
  if (uicomponent.isUserActivity()) {
    ownerUri = LinkProvider.getUserProfileUri(ownerIdentity.getRemoteId());
    ownerAvatar = ownerIdentity.profile.avatarUrl;
    ownerName = ownerIdentity.profile.fullName;
    if (!ownerAvatar) ownerAvatar= LinkProvider.PROFILE_DEFAULT_AVATAR_URL;
  } else {
    Space space = Utils.getSpaceService().getSpaceByPrettyName(ownerIdentity.remoteId);
    ownerUri = Utils.getSpaceHomeURL(space);
    ownerAvatar = space.avatarUrl;
    ownerName = space.displayName;
    if (!ownerAvatar) ownerAvatar = LinkProvider.SPACE_DEFAULT_AVATAR_URL;
  }
%>

<%if (currentNode != null) {
	  //ECMS declare variables - BEGIN
     if (uicomponent.isSymlink(0)) {
       activityContentTitle = uicomponent.getDocTitle(0);
     } else {
       activityContentTitle = uicomponent.getTitle(currentNode);
     }
	  
    def binarySrc = uicomponent.getWebdavURL();
    String repository = ((ManageableRepository)currentNode.getSession().getRepository()).getConfiguration().getName();
    def preferenceWS  = currentNode.getSession().getWorkspace().getName();
    
	  def ilBinarySrc = uicomponent.getImagePath(0);
	
	  def state = uicomponent.getState(0);
	  def author = uicomponent.getAuthor(0);
	  def lastModified = uicomponent.getLastModified(0);
	  def dateCreated = uicomponent.getDateCreated(0);
	  
	  String portalName = uicomponent.getContainerName();
	  
	  String restContextName = org.exoplatform.ecm.webui.utils.Utils.getRestContextName(portalName);
	  if(mimeType.equals("application/rss+xml")) mimeType="text/html";  
	  //ECMS declare variables - END
	  def downloadLink = uicomponent.getDownloadLink(0);
	  def size = uicomponent.getSize(currentNode);
	  def fileSize = uicomponent.getFileSize(currentNode);
	  def description = uicomponent.getSummary(currentNode); 
    //description = ContentReader.simpleEscapeHtml(description); // FYI do not escape it

	  def openInOfficeConnector = WCMCoreUtils.getService(OpenInOfficeConnector.class);
	  def _documentInfos = openInOfficeConnector.getDocumentInfos(currentNode.getName());

	  def remoteEditClass=_documentInfos[1];
	  def remoteEditTitle=_ctx.appRes(_documentInfos[0]);

  // END ECMS
 %>
<script language="JavaScript">
  function loadImageOnError(objImage) {
    var tryCount = objImage.getAttribute("retryCount");
    if (tryCount ==null) return;
    tryCount = parseInt(tryCount);
    if (tryCount>15) return;
    tryCount++;
    if (eXo.ecm.WCMUtils != null && objImage != null) {
      if (objImage.parentNode != null && objImage.parentNode != null)
        eXo.ecm.WCMUtils.loadImageForFileActivityCallback(objImage.parentNode);
    }else {
      objImage.setAttribute("retryCount", tryCount);
      setTimeout(function(){loadImageOnError(objImage)},300);
    }
  }
</script>

<div class="activityStream uiContentActivity fileActivity" id="activityContainer${activity.id}">
	<% uiform.begin() %>
	<div class="activityTimeLine pull-left">
		<div class="activityAvatar avatarCircle">
			<a title="$ownerName" href="$ownerUri">
				<img alt="$ownerName" src="$ownerAvatar"/>
			</a>
		</div>
		<div class="activityType"><span><i class="uiIconOutlookMail uiIconSocWhite"></i></span></div>
	</div><!--end activityTimeLine-->
	<div class="boxContainer" id="boxContainer">
		<div id="ContextBox${activity.id}"class="uiBox contentBox">
			<div id="ActivityContextBox${activity.id}">     
				<div class="heading">
					<span class="arrowLeft"></span>
					<div class="actLink">
					  <a id="Permalink${activity.id}" class="uiIconLink uiIconLightGray" rel="tooltip" data-placement="bottom" title="$viewActivityTip" href="<%=uicomponent.getActivityPermalink(activity.id)%>"></a>
					<% if (activityDeletable) {%>
						  <a href="javascript:void(0)" data-confirm="$labelToDeleteThisActivity" data-caption="$captionConfirmation" data-close="$labelClosebutton" data-ok="$labelConfirmbutton" data-delete="<%=uicomponent.event("DeleteActivity", uicomponent.getId(), "");%>" class="uiIconClose uiIconLightGray controllDelete" id="DeleteActivityButton${activity.id}"></a>
						<%}%>
					</div>
					<div class="author">
						<a title="$ownerName" href="$ownerUri">$ownerName</a>         
					</div>	
					<div class="dataInfor">
						<span class="dateTime"><i class="uiIconClock uiIconLightGray"></i>&nbsp;$activityPostedTime</span> 
						<% if (uicomponent.isUserActivity() && uicomponent.isSpaceStreamOwner() && !uicomponent.isUISpaceActivitiesDisplay()) {
								Space spaceSource = Utils.getSpaceService().getSpaceByPrettyName(streamOwner);
                def spaceSourceURI, spaceName;
                if (spaceSource != null) {
                  spaceSourceURI = LinkProvider.getSpaceUri(spaceSource.url);
                  spaceName = spaceSource.displayName;
                } else {
                  spaceSourceURI = LinkProvider.getActivityUriForSpace(streamOwner, streamOwner);
                  spaceName = Utils.getSpaceIdentity(streamOwner, false).profile.fullName;
                }
						%>
						<a class="spaceName" title="$spaceName" href="$spaceSourceURI"><i class="uiIconSocGroup uiIconSocLightGray"></i>&nbsp;$spaceName</a>
						<%} %>
					</div>
				</div><!--end heading-->
				<% if (activityStatus != null) { %>
				<div class="description">$activityStatus</div><!--end description-->
				<% } %>

				<% /* ============== Adaptation for Outlook message body (text/html) ============== */ %>				
				<div class="uiBox roundedBottom introBox fileShare">	
					<div class="clearfix isPreviewable">
          	<div class="text">
							<%if (currentNode) {%>
							<a class="linkTitle" rel="tooltip" data-placement="bottom" data-original-title="$activityContentTitle" href="${uicomponent.currentDocOpenUri}"> $activityContentTitle </a>
							<%} else {%>
							<span>$activityStatus</span><!-- TODO -->
							<%}%>
							<div class="descriptionText">$description</div><!-- TODO -->		
						</div><!--end text-->
          
          	<div id="MediaContent${activity.id}" class="outlookMessageActivityContent PlayerContianer" onclick="$contentActivityUri">
							<% uicomponent.renderContentPresentation() %>
					 	</div>
					</div>	
				</div><!--end introBox,contentShare-->	
				<% /* ============================ */ %>						
				
				<div class="actionBar clearfix ContentActivityIcon">
				  <% def toggleDisplayCommentAction = uicomponent.event('ToggleDisplayCommentForm', null, false);
					 def commentLink = "";
				  %>
				 <% if (activityCommentAndLikable) { %>						 
					<ul class="pull-right statusAction">						
						<li>
							<a class="$commentLink"  id="CommentLink${activity.id}" href="javascript:void(0);">
								<i class="uiIconComment uiIconLightGray"></i>&nbsp;$commentCount
							</a>
						</li>
					  <% if (uicomponent.isLiked()) { %>
						<li>
							<a onclick="$unlikeActivityAction" id="UnLikeLink${activity.id}" href="javascript:void(0);">
							   <i class="uiIconThumbUp uiIconBlue"></i>&nbsp;$identityLikesNum
							</a> 
						</li>
					  <% } else { %>
						<li>
							<a onclick="$likeActivityAction" id="LikeLink${activity.id}" href="javascript:void(0);">
							  <i class="uiIconThumbUp uiIconLightGray"></i>&nbsp;$identityLikesNum
							</a>
						</li>
					  <% }%>											 
					</ul>  
				 <% }%>
					 <ul class="pull-left statusAction">
				 	<% if(uicomponent.canEditDocument(currentNode)){%>
						<li style="display:none;" ><a href="<%=uicomponent.event("OpenFile")%>"><i class="uiIcon16x16FileDefault uiIconEcmsOpenDocument_$activity.id $remoteEditClass" ></i>&nbsp;$remoteEditTitle</a></li>
				 	<%}%>
					<% if (uicomponent.isFileSupportPreview(currentNode)) { %>
						<li><a onclick="$contentActivityUri" href="javascript:void(0)"><i class="uiIconWatch uiIconLightGray"></i>&nbsp;<%=_ctx.appRes("SocialIntegration.view");%></a></li>
					<% }%>
						<li><a href="$downloadLink"><i class="uiIconDownload uiIconLightGray"></i>&nbsp;<%=_ctx.appRes("SocialIntegration.download");%></a></li>
					 </ul>
				</div><!--end actionBar-->
				
				<% if (identityLikesNum > 0 || uicomponent.isLiked()) {%>
				  <div class="listLikedBox $listPeopleBGClass">		
		          <div class="listPeopleContent">
		          <% if (!labelLikes) labelLikes = ""; %>
					      $labelLikes		
		            <% if (identityLikesNum > 0) {%>
		            <div class="listLiked">
		            <%
		            displayedIdentityLikes.each({
		              def id = Utils.getIdentityManager().getIdentity(it);
		              personLikeFullName = id.profile.fullName;
		              personLikeProfileUri = LinkProvider.getUserProfileUri(id.getRemoteId());
		              personLikeAvatarImageSource = id.profile.avatarUrl;
		              if (!personLikeAvatarImageSource) personLikeAvatarImageSource = LinkProvider.PROFILE_DEFAULT_AVATAR_URL;
		              %>
		                <a class="avatarXSmall" rel="tooltip" data-placement="bottom"  title="$personLikeFullName" href="$personLikeProfileUri">
		                  <img src="$personLikeAvatarImageSource" alt="$personLikeFullName" title="$personLikeFullName" />
		                </a>
		             <% })%>
		               <button onclick="$loadLikesAction" class="btn">...</button>
		            </div>
		            <% }%>
		          </div>
		      </div>
		    <%}%>

				<div id="CommentBlockBound${activity.id}" class="commentBox">					
					  <% if (uicomponent.commentListToggleable()) {
					  def showAllCommentsAction = uicomponent.event("SetCommentListStatus", "all");
					  def hideAllCommentsAction = uicomponent.event("SetCommentListStatus", "none");
					  def loadPreviousCommentsAction = uicomponent.event("SetCommentListStatus", "all");
					  %> 

					 <% if (commentListStatus.getStatus().equals("none")) {%>
			      <div class="commentListInfo hideBottomLine">
			      <% } else {%>
			        <div class="commentListInfo clearfix">
			        <div class="pull-right numberComment">$commentHidden/$commentCount</div>
			      <% } %>
			            <% if (commentListStatus.getStatus().equals("latest") || commentListStatus.getStatus().equals("none")) { %>
			              <a onclick="$showAllCommentsAction" href="#show-all-comments">
			                $labelShowAllComments
			              </a>
			            <% } else if (commentListStatus.getStatus().equals("all")) { %>
                  <%   if (commentHidden > 0) { %>
                         <a onclick="$loadPreviousCommentsAction" href="javascript:void(0);">$labelShowPreviousComments</a>
                  <%   } else { %>
                         <a onclick="$hideAllCommentsAction" href="javascript:void(0);">$labelHideAllComments</a>
                  <%   } %>
			            <% } %>
			      </div>
			     <% } %>


					<div class="commentList">	
				    <%
            def commenterFullName, commenterProfileUri, commentMessage, commentPostedTime, commenterAvatarImgSrc;
            def first = true, commentContentClass;
            def commentCounter = 0;            
            commentList.each({
              commentCounter++;
              if (first & !uicomponent.commentListToggleable()) {
                commentContentClass = "commentContent";
                first = false;
              } else {
                commentContentClass = "";
              }
              def commentId = Utils.getIdentityManager().getIdentity(it.userId);
              commenterFullName = commentId.profile.fullName;
              commenterProfileUri = LinkProvider.getUserProfileUri(commentId.getRemoteId());
              
              
              
              def activityParams = it.getTemplateParams();
				      def systemComment = uicomponent.getSystemCommentBundle(activityParams);
				      def systemCommentTitle ;
				      StringBuffer commentBuffer = new StringBuffer();
				      if (systemComment!=null) {
				        systemCommentTitle = uicomponent.getSystemCommentTitle(activityParams);
				        if (systemComment!=null) {
				          if (systemComment.length>0) {
				            for (def count=0; count<systemComment.length; count++) {
				              commentMessage = _ctx.appRes(systemComment[count]);
				              if (systemCommentTitle!=null) {
				                if (systemCommentTitle.length>count) {
				                  def titles = systemCommentTitle[count].split(ActivityCommonService.METADATA_VALUE_SEPERATOR);
				                  for(def i = 0; i<titles.length; i++) {
				                    commentMessage = commentMessage.replace("{"+i+"}", titles[i]);
				                    commentMessage = org.exoplatform.wcm.ext.component.activity.listener.Utils.getFirstSummaryLines(commentMessage);
				                  }
				                }
				              }
				              if (systemComment!=null) {
				                commentBuffer.append("<p class=\"ContentBlock\">").append(commentMessage).append("</p>");                
				              }else {
				                commentBuffer.append("<p class=\"ContentBlock\">").append(commentMessage).append("</p>");
				              }
				            }
				          }
				          commentMessage = commentBuffer.toString(); 
				        }else {
				          commentMessage = it.title;
				        }
				      } else {
				        commentMessage = it.title;
				      }

              
              
              
              commentPostedTime = uicomponent.getPostedTimeString(_ctx, it.postedTime);
              commenterAvatarImgSrc = commentId.profile.avatarUrl;
              if (!commenterAvatarImgSrc) commenterAvatarImgSrc = LinkProvider.PROFILE_DEFAULT_AVATAR_URL;
              %>
             <div id="commentContainer${it.id}">
              <% if (commentCounter == commentList.size()) {%>
                <div id="CommentBlock${activity.id}${commentCounter}" class="commentItem commentItemLast">
              <% } else { %>
                <div id="CommentBlock${activity.id}${commentCounter}" class="commentItem">
              <% } %>
              <div class="commmentLeft">
                <a class="avatarXSmall" href="$commenterProfileUri" rel="tooltip" data-placement="bottom" title="$commenterFullName" >
                  <img alt="$commenterFullName" src="$commenterAvatarImgSrc" />
                </a>
            </div><!--end commentLeft-->     
            <div class="commentRight">
              <div class="author">
                <a href="$commenterProfileUri">$commenterFullName</a>
                <span class="dateTime">$commentPostedTime</span>
              </div>
              <p class="contentComment">$commentMessage</p>
            </div><!--end commentRight-->
            <div class="actLink">
              <a id="Permalink${it.id}" rel="tooltip" data-placement="bottom" title="$viewActivityTip" class="uiIconLink uiIconLightGray" href="<%=uicomponent.getCommentPermalink(activity.id, it.id)%>"></a>
            <%if (uicomponent.isCommentDeletable(it.userId)) {
              String idDeleteComment = "DeleteCommentButton${it.id}";
            %>
              <a href="javascript:void(0)" id="$idDeleteComment" data-confirm="$labelToDeleteThisComment" data-caption="$captionConfirmation" data-close="$labelClosebutton" data-ok="$labelConfirmbutton" data-delete="<%= uicomponent.event("DeleteComment", uicomponent.id, it.id); %>"  class="uiIconClose uiIconLightGray controllDelete"></a>
            <% } %>
            </div>
              </div><!--end commentItem-->
             </div>
          <% }) %>
          </div> <!--end commentlist-->
          <div class="commentList inputContainer" id="InputContainer${activity.id}">
          <%
            def currentCommenterIdentity = uicomponent.getCommenterIdentity();
            def currentCommenterUri = LinkProvider.getUserProfileUri(currentCommenterIdentity.getRemoteId());
            def currentCommenterAvatar = currentCommenterIdentity.profile.avatarUrl;
            def currentCommenterName = currentCommenterIdentity.profile.fullName;
            if (!currentCommenterAvatar) currentCommenterAvatar= LinkProvider.PROFILE_DEFAULT_AVATAR_URL;
					%>
					<% if (commentList.size() == 0) { %>
					  <div class="commentItem noCommentFormBox" id="CommentFormBlock${activity.id}">
					<% } else { %>
					  <div class="commentItem commentFormBox" id="CommentFormBlock${activity.id}">
					<% } %>
					  <div class="commmentLeft">
							<a class="avatarXSmall" rel="tooltip" data-placement="bottom" title="$currentCommenterName" href="$currentCommenterUri">
								<img src="$currentCommenterAvatar" alt="$currentCommenterName"/>
							</a>
						</div><!--end commentLeft--> 
						<div class="commentRight">
							<div class="commentInputBox ">
								 <button class="btn pull-right btn-primary" onclick="<%= uicomponent.event("PostComment") %>"  rel="tooltip" data-placement="bottom" title="$labelComment" id="CommentButton${activity.id}">$labelComment</button>
								<div class="commentInput"><% uicomponent.renderChild(UIFormTextAreaInput.class); %></div>
							</div>
						</div><!--end commentRight-->      
					  </div> <!--end commentItem-->		
					</div><!--end commentlist-->	  
				</div><!--end commentBox-->
			</div><!--end #ActivityContextBox${activity.id}-->
		</div> <!--end ContextBox${activity.id}-->	
  </div> <!-- #boxContainer-->	  
  <% uiform.end() %>
</div>
<% } else {// currentNode == null %>
<div class="activityStream uiContentActivity fileActivity" id="activityContainer${activity.id}">
	<% uiform.begin() %>
	<div class="activityTimeLine pull-left">
		<div class="activityAvatar avatarCircle">
			<a title="$ownerName" href="$ownerUri">
				<img alt="$ownerName" src="$ownerAvatar"/>
			</a>
		</div>
		<div class="activityType"><span><i class="uiIconSocFileSharing uiIconSocWhite"></i></span></div>
	</div><!--end activityTimeLine-->
	<div class="boxContainer" id="boxContainer">
		<div id="ContextBox${activity.id}"class="uiBox contentBox">
			<div id="ActivityContextBox${activity.id}">     
				<div class="heading">
					<span class="arrowLeft"></span>
					<div class="actLink">
					      <a id="Permalink${activity.id}" class="uiIconLink uiIconLightGray" rel="tooltip" data-placement="bottom" title="$viewActivityTip" href="<%=uicomponent.getActivityPermalink(activity.id)%>"></a>
					<% if (activityDeletable) {%>
						  <a href="javascript:void(0)" data-confirm="$labelToDeleteThisActivity" data-caption="$captionConfirmation" data-close="$labelClosebutton" data-ok="$labelConfirmbutton" data-delete="<%=uicomponent.event("DeleteActivity", uicomponent.getId(), "");%>" class="uiIconClose uiIconLightGray controllDelete" id="DeleteActivityButton${activity.id}"></a>
						<%}%>
					</div>
					<div class="author">
						<a title="$ownerName" href="$ownerUri">$ownerName</a>         
					</div>	
					<div class="dataInfor">
						<span class="dateTime"><i class="uiIconClock uiIconLightGray"></i>&nbsp;$activityPostedTime</span> 
						<% if (uicomponent.isUserActivity() && uicomponent.isSpaceStreamOwner() && !uicomponent.isUISpaceActivitiesDisplay()) {
								Space spaceSource = Utils.getSpaceService().getSpaceByPrettyName(streamOwner);
                def spaceSourceURI, spaceName;
                if (spaceSource != null) {
                  spaceSourceURI = LinkProvider.getSpaceUri(spaceSource.url);
                  spaceName = spaceSource.displayName;
                } else {
                  spaceSourceURI = LinkProvider.getActivityUriForSpace(streamOwner, streamOwner);
                  spaceName = Utils.getSpaceIdentity(streamOwner, false).profile.fullName;
                }
						%>
						<a class="spaceName" title="$spaceName" href="$spaceSourceURI"><i class="uiIconSocGroup uiIconSocLightGray"></i>&nbsp;$spaceName</a>
						<%} %>
					</div>
				</div><!--end heading-->
                <% if (activityStatus != null) { %>
                    <div class="description">$activityStatus</div><!--end description-->
                <% } %>
				<div class="uiBox roundedBottom introBox fileShare">	
					<div class="clearfix isPreviewable">
		              <div id="MediaContent${activity.id}" class="fileTypeContent">
			           <%
		                 def classIconName = uicomponent.getCssClassIconFile(contentName, mimeType);		                             
		               %>
		               <i class="<%=classIconName%>"></i>
					  </div>
						
					  <div class="text">
					    <span>$contentName</span>
						<div class="inforFile"></div>				
					  </div><!--end text-->
   					</div>	
				</div><!--end introBox,contentShare-->	
				
				<div class="actionBar clearfix ContentActivityIcon">
				  <% def toggleDisplayCommentAction = uicomponent.event('ToggleDisplayCommentForm', null, false);
					 def commentLink = "";
				  %>
				 <% if (activityCommentAndLikable) { %>						 
					<ul class="pull-right statusAction">						
						<li>
							<a class="$commentLink"  id="CommentLink${activity.id}" href="javascript:void(0);">
								<i class="uiIconComment uiIconLightGray"></i>&nbsp;$commentCount
							</a>
						</li>
					  <% if (uicomponent.isLiked()) { %>
						<li>
							<a onclick="$unlikeActivityAction" id="UnLikeLink${activity.id}" href="javascript:void(0);">
							   <i class="uiIconThumbUp uiIconBlue"></i>&nbsp;$identityLikesNum
							</a> 
						</li>
					  <% } else { %>
						<li>
							<a onclick="$likeActivityAction" id="LikeLink${activity.id}" href="javascript:void(0);">
							  <i class="uiIconThumbUp uiIconLightGray"></i>&nbsp;$identityLikesNum
							</a>
						</li>
					  <% }%>											 
					</ul>  
				 <% }%>	
				</div><!--end actionBar-->
				
				
				<% if (identityLikesNum > 0 || uicomponent.isLiked()) {%>
				  <div class="listLikedBox $listPeopleBGClass">		
		          <div class="listPeopleContent">
		          <% if (!labelLikes) labelLikes = ""; %>
					      $labelLikes		
		            <% if (identityLikesNum > 0) {%>
		            <div class="listLiked">
		            <%
		            displayedIdentityLikes.each({
		              def id = Utils.getIdentityManager().getIdentity(it);
		              personLikeFullName = id.profile.fullName;
		              personLikeProfileUri = LinkProvider.getUserProfileUri(id.getRemoteId());
		              personLikeAvatarImageSource = id.profile.avatarUrl;
		              if (!personLikeAvatarImageSource) personLikeAvatarImageSource = LinkProvider.PROFILE_DEFAULT_AVATAR_URL;
		              %>
		                <a class="avatarXSmall" rel="tooltip" data-placement="bottom"  title="$personLikeFullName" href="$personLikeProfileUri">
		                  <img src="$personLikeAvatarImageSource" alt="$personLikeFullName" title="$personLikeFullName" />
		                </a>
		             <% })%>
		               <button onclick="$loadLikesAction" class="btn">...</button>
		            </div>
		            <% }%>
		          </div>
		      </div>
		    <%}%>

				<div id="CommentBlockBound${activity.id}" class="commentBox">					
					  <% if (uicomponent.commentListToggleable()) {
					  def showAllCommentsAction = uicomponent.event("SetCommentListStatus", "all");
					  def hideAllCommentsAction = uicomponent.event("SetCommentListStatus", "none");
					  %> 

					 <% if (commentListStatus.getStatus().equals("none")) {%>
			      <div class="commentListInfo hideBottomLine">
			      <% } else {%>
			        <div class="commentListInfo clearfix">
			        <div class="pull-right numberComment">$commentHidden/$commentCount</div>
			      <% } %>
			            <% if (commentListStatus.getStatus().equals("latest") || commentListStatus.getStatus().equals("none")) { %>
			              <a onclick="$showAllCommentsAction" href="#show-all-comments">
			                $labelShowAllComments
			              </a>
			            <% } else if (commentListStatus.getStatus().equals("all")) { %>
                  <%   if (commentHidden > 0) { %>
                         <a onclick="$showAllCommentsAction" href="javascript:void(0);">$labelShowPreviousComments</a>
                  <%   } else { %>
                         <a onclick="$hideAllCommentsAction" href="javascript:void(0);">$labelHideAllComments</a>
                  <%   } %>
			            <% } %>
			      </div>
			     <% } %>


					<div class="commentList">	
				    <%
            def commenterFullName, commenterProfileUri, commentMessage, commentPostedTime, commenterAvatarImgSrc;
            def first = true, commentContentClass = "";
            def commentCounter = 0;            
            commentList.each({
              commentCounter++;
              if (first & !uicomponent.commentListToggleable()) {
                commentContentClass = "commentContent";
                first = false;
              }
              
              def commentIdentity = Utils.getIdentityManager().getIdentity(it.userId);
              commenterFullName = commentIdentity.profile.fullName;
              commenterProfileUri = LinkProvider.getUserProfileUri(commentIdentity.getRemoteId());
              
              commentMessage = it.title;
              def activityParams = it.getTemplateParams();
		      def systemComment = uicomponent.getSystemCommentBundle(activityParams);
		      def systemCommentTitle ;
		      StringBuffer commentBuffer = new StringBuffer();
		      if (systemComment!=null && systemComment.length>0) {
		        systemCommentTitle = uicomponent.getSystemCommentTitle(activityParams);
	            for (def count=0; count<systemComment.length; count++) {
	              commentMessage = _ctx.appRes(systemComment[count]);
	              if (systemCommentTitle!=null && systemCommentTitle.length>count) {
	                  def titles = systemCommentTitle[count].split(ActivityCommonService.METADATA_VALUE_SEPERATOR);
	                  for(def i = 0; i<titles.length; i++) {
	                    commentMessage = commentMessage.replace("{"+i+"}", titles[i]);
	                    commentMessage = ContentReader.getXSSCompatibilityContent(commentMessage);
	                  }
	              }
	              
	              commentBuffer.append("<p class=\"ContentBlock\">").append(commentMessage).append("</p>");                
	            }
		        commentMessage = commentBuffer.toString(); 
		      } 

              commentPostedTime = uicomponent.getPostedTimeString(_ctx, it.postedTime);
              commenterAvatarImgSrc = commentIdentity.profile.avatarUrl;
              if (!commenterAvatarImgSrc) commenterAvatarImgSrc = LinkProvider.PROFILE_DEFAULT_AVATAR_URL;
              %>
             <div id="commentContainer${it.id}">
              <% if (commentCounter == commentList.size()) {%>
                <div id="CommentBlock${activity.id}${commentCounter}" class="commentItem commentItemLast">
              <% } else { %>
                <div id="CommentBlock${activity.id}${commentCounter}" class="commentItem">
              <% } %>
              <div class="commmentLeft">
                <a class="avatarXSmall" href="$commenterProfileUri" rel="tooltip" data-placement="bottom" title="$commenterFullName" >
                  <img alt="$commenterFullName" src="$commenterAvatarImgSrc" />
                </a>
            </div><!--end commentLeft-->     
            <div class="commentRight">
              <div class="author">
                <a href="$commenterProfileUri">$commenterFullName</a>
                <span class="dateTime">$commentPostedTime</span>
              </div>
              <p class="contentComment">$commentMessage</p>
            </div><!--end commentRight-->
            <div class="actLink">
              <a id="Permalink${it.id}" rel="tooltip" data-placement="bottom" title="$viewActivityTip" class="uiIconLink uiIconLightGray" href="<%=uicomponent.getCommentPermalink(activity.id, it.id)%>"></a>
            <%if (uicomponent.isCommentDeletable(it.userId)) {
              String idDeleteComment = "DeleteCommentButton${it.id}";
            %>
              <a href="javascript:void(0)" id="$idDeleteComment" data-confirm="$labelToDeleteThisComment" data-caption="$captionConfirmation" data-close="$labelClosebutton" data-ok="$labelConfirmbutton" data-delete="<%= uicomponent.event("DeleteComment", uicomponent.id, it.id); %>"  class="uiIconClose uiIconLightGray controllDelete"></a>
            <% } %>
            </div>
              </div><!--end commentItem-->
             </div>
          <% }) %>
          </div> <!--end commentlist-->
          <div class="commentList inputContainer" id="InputContainer${activity.id}">
          <%
            def currentCommenterIdentity = uicomponent.getCommenterIdentity();
            def currentCommenterUri = LinkProvider.getUserProfileUri(currentCommenterIdentity.getRemoteId());
            def currentCommenterAvatar = currentCommenterIdentity.profile.avatarUrl;
            def currentCommenterName = currentCommenterIdentity.profile.fullName;
            if (!currentCommenterAvatar) currentCommenterAvatar= LinkProvider.PROFILE_DEFAULT_AVATAR_URL;
					%>
					<% if (commentList.size() == 0) { %>
					  <div class="commentItem noCommentFormBox" id="CommentFormBlock${activity.id}">
					<% } else { %>
					  <div class="commentItem commentFormBox" id="CommentFormBlock${activity.id}">
					<% } %>
					  <div class="commmentLeft">
							<a class="avatarXSmall" rel="tooltip" data-placement="bottom" title="$currentCommenterName" href="$currentCommenterUri">
								<img src="$currentCommenterAvatar" alt="$currentCommenterName"/>
							</a>
						</div><!--end commentLeft--> 
						<div class="commentRight">
							<div class="commentInputBox ">
								<button class="btn pull-right btn-primary" onclick="<%= uicomponent.event("PostComment") %>"  rel="tooltip" data-placement="bottom" title="$labelComment" id="CommentButton${activity.id}">$labelComment</button>
								<div class="commentInput"><% uicomponent.renderChild(UIFormTextAreaInput.class); %></div>
							</div>
						</div><!--end commentRight-->      
					  </div> <!--end commentItem-->		
					</div><!--end commentlist-->	  
				</div><!--end commentBox-->
			</div><!--end #ActivityContextBox${activity.id}-->
		</div> <!--end ContextBox${activity.id}-->	
  </div> <!-- #boxContainer-->	  
  <% uiform.end() %>
</div>
<% } %>
<% } %>
