<%
	import java.text.SimpleDateFormat ;
	import org.exoplatform.web.application.Parameter ;
  import org.exoplatform.ecm.webui.utils.PermissionUtil;
  import org.exoplatform.ecm.webui.utils.Utils;
  import org.exoplatform.webui.core.UIPopupWindow;
  import org.exoplatform.ecm.webui.utils.Utils;
  import org.exoplatform.services.jcr.RepositoryService;
  import org.exoplatform.services.jcr.util.Text;
  
	UIPopupWindow uiPopupWindow = uicomponent.getAncestorOfType(UIPopupWindow.class);
  def resizeBlock = "class=\"UIResizableBlock\"";
  if(uiPopupWindow != null) resizeBlock = ""; 
  
	def node = uicomponent.getNode() ;
	def originalNode = uicomponent.getOriginalNode()
	SimpleDateFormat dateFormat = new SimpleDateFormat() ;
	Parameter[] params;
  RepositoryService rService = uicomponent.getApplicationComponent(RepositoryService.class);
  String repository = rService.getCurrentRepository().getConfiguration().getName();	  
%>
<style>
  <% _ctx.include(uicomponent.getTemplateSkin("exo:sample", "Stylesheet")); %>
</style>
<div $resizeBlock id="$uicomponent.id">
	<div class="WorkSample">
		<div class="SampleBG">
		  <table><tr>
				<td class="text"><%=_ctx.appRes("Sample.view.label.node-name")%> </td>
				<td class="TextDetail"><%=Text.unescapeIllegalJcrChars(originalNode.getName())%></td>
			</tr></table>
		</div>
		<div class="SampleBG">
		  <table><tr>
  			<td class="text"><%=_ctx.appRes("Sample.view.label.title")%></td>
  			<td class="TextDetail">  
          <% 
            String title = uicomponent.getInlineEditingField(node, "exo:title", "", "TEXT", "TdGtmplTitle", "TdGtmplTitle", true); 
            print title;
          %>
  			</td>
			</tr></table>
		</div>
		<div class="SampleBG">
		  <table><tr>
  			<td class="text"><%=_ctx.appRes("Sample.view.label.date")%> </td>
  			<td class="TextDetail">
  				<%if(node.hasProperty("exo:date")) {
  				  dateFormat.applyPattern("MMMMM dd yyyy") ;						
  				%>
  					<%=dateFormat.format(node.getProperty("exo:date").getDate().getTime())%>
  				<%}%>
  			</td>
  		</tr></table>
		</div>
		<div class="SampleBG">
		  <table><tr>
  			<td class="text"><%=_ctx.appRes("Sample.view.label.date-time")%> </td>
  			<td class="TextDetail">
  				<%if(node.hasProperty("exo:datetime")) {
  					 dateFormat.applyPattern("MMMMM dd yyyy hh:mm:ss") ;
  					 print dateFormat.format(node.getProperty("exo:datetime").getDate().getTime());
  				}%>	
  			</td>
  		</tr></table>
		</div>
		<div style="overflow: hidden">
			<div class="LableLeftDescription" >
				<div class="TitleBG">
					<label class="text" style="padding-left: 5px"><%=_ctx.appRes("Sample.view.label.description")%></label>
				</div>
				<div class="summary" >
				  <%			  
            print uicomponent.getInlineEditingField(node, "exo:description", "", "TEXTAREA", "Description", "Content", true);
          %>
				</div>
			</div>
			<% if(node.hasNode("exo:image")) {
         def imageNode = node.getNode("exo:image");
			%>
					<div class="LableRightDescription">
						<div class="TitleBG" >
							<label class="text" style="padding-left: 5px"><%=_ctx.appRes("Sample.view.label.image")%></label>
						</div>
						<div style= "width: 95%; height: 160px ; text-align: center; padding: 5px;">
            <% if (imageNode.getProperty("jcr:data").getStream().available() > 0) {
               imgSrc = uicomponent.getImage(node) ; 
            %>
			      	<img src="$imgSrc" alt="$title" width="250" height="150"/> 
            <% } %>
						</div>
					</div>
			<% } %>
		</div>
		<!-- div for  Summary and Image -->
		<div style="overflow: hidden;">
			<div class="LableLeftDescription">
				<div class="TitleBG">
					<label class="text" style="padding-left: 5px"><%=_ctx.appRes("Sample.view.label.summary")%></label>
				</div>
				<div class="summary" >
			   <%
            print uicomponent.getInlineEditingField(node, "exo:summary", "", "TEXTAREA", "Summary", "Content", true);
         %>
				</div>
			</div>
			<div class="LableRightDescription">
				<div class="TitleBG" >
					<label class="text" style="padding: 5px;"><%=_ctx.appRes("Sample.view.label.content")%></label>
				</div>
				<div class="content">
			   <%          
            print uicomponent.getInlineEditingField(node, "exo:content", "", "TEXTAREA", "Content", "Content", true);
         %>
				</div>
			</div>
		</div>
		<!-- div for Content -->
		<!-- div for  relation and attackments -->
		<div style="overflow: hidden;" class=" ClearFix">
			<div class="LableLeftDescription">
				<div class="TitleBG" >
					<label class="text" style="padding-left: 5px;"><%=_ctx.appRes("Sample.view.label.relation")%></label>
				</div>
				<%
				  def relations = uicomponent.getRelations() ;
				  if(relations.size() > 0) {
				%>
					<div style="width: 100%;" >
						<%
						  for(rel in relations) {
							  if (rel != null) {
							  	params  = [new Parameter("workspaceName", rel.getSession().getWorkspace().getName()), new Parameter("findDrive","true")];
							  	String actionLink2 = uicomponent.event("ChangeNode", rel.getPath(), params);
							%>
								<div style="font-size: 12px; padding: 10px;">
									-	<a href="$actionLink2">
											<%=rel.getName()%>
										</a>
								</div>
								
						<%  }
						  }%>	  	
					</div>		  
				<%} else {%>
					<div style="width: 100%; height: 20px;"> </div>
			  <%}%>
			</div>
			<div class="LableRightDescription">
				<div class="TitleBG" >
					<label class="text" style="padding-left: 5px;"><%=_ctx.appRes("Sample.view.label.attachment")%></label>
				</div>
				<%
				  def attachments = uicomponent.getAttachments() ;
				  if(attachments.size() > 0) {
					  def removeattachcomponent = uicomponent.getRemoveAttach();
					  String wsName = "";
				%>			
					<div style="width: 100%" >
						<%
						  for(att in attachments) {
						  	wsName = att.getSession().getWorkspace().getName();
  							params  = [new Parameter("workspaceName", wsName), new Parameter("findDrive","true")];
  							def viewAttachmentLink =  uicomponent.getAttachmentURL(att, params);
  							def linkActionName = (viewAttachmentLink.startsWith("http")) ? "href" : "onclick";
						%>
							<div style="font-size: 12px; padding: 10px;" class=" ClearFix">
								<div class="RemoveNodeFloat">
								 <a $linkActionName="$viewAttachmentLink" style="cursor: pointer;">-<%=att.getName()%></a>
								</div>
								<div class="RemoveNodeFloat"> 	
							 	 <% if (PermissionUtil.canRemoveNode(att)) {
							 	 			params = [new Parameter("workspaceName", wsName), new Parameter("repository", repository)];
							 	 			if (removeattachcomponent != null) {
							 	 %>
									<a onclick="<%=removeattachcomponent.event("RemoveAttach", Utils.formatNodeName(att.getPath()), params)%>" style="cursor: pointer;" title="<%=_ctx.appRes(uicomponent.getId() + ".tooltip.remove-attachment")%>">
				                      <div class="RemoveAttachments"><span></span></div>
				                    </a>
                <%    }  
                    } %>
				                </div>

							</div>
						<%}%>	  	
					</div>		  
				<%} else { %>
					<div style="width: 100%; height: 20px;"> </div>
				<%}%>
			</div>	

		</div>		
	</div>
	<div><% _ctx.include(uicomponent.getViewTemplate("mix:votable", "view1")); %></div>
  <div><% _ctx.include(uicomponent.getViewTemplate("exo:comments", "view1")); %></div>
</div>
