<%
  import org.exoplatform.ecm.webui.utils.PermissionUtil;
  import org.exoplatform.ecm.webui.utils.Utils ;
  import org.exoplatform.web.application.Parameter ;
  import org.exoplatform.webui.core.UIPopupWindow;
  import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo;
	
	UIPopupWindow uiPopupWindow = uicomponent.getAncestorOfType(UIPopupWindow.class);
  def resizeBlock = "class=\"UIResizableBlock\"";
  if(uiPopupWindow != null) resizeBlock = ""; 
  Parameter[] params;
%>
<style>
  <% _ctx.include(uicomponent.getTemplateSkin("exo:article", "Stylesheet")); %>
</style>
<div id="$uicomponent.id" $resizeBlock>
	<%
	 def node = uicomponent.getNode() ;		
	 def relations = uicomponent.getRelations() ;
	 def attachments = uicomponent.getAttachments() ;
	 if(node.hasProperty("exo:title")) {
	%>
		<div class="UIArticle">
			<div class="ArticleTLDecorator">
				<div class="ArticleTRDecorator">
					<div class="ArticleTCDecorator">
		        <div class="TitleLabel"><%=node.getProperty("exo:title").getString()%></div>
	        </div>
				</div>
			</div>
			<div class="ArticleMLDecorator">
				<div class="ArticleMRDecorator">
					<div class="ArticleMCDecorator">
						<div class="ArticleFrame">
						  <div class="TopLeftArticleFrame">
						    <div class="TopRightArtictleFrame">
						      <div class="TopCenterArticleFrame">
						        <div class="ArticleField">
				              <div class="FieldIcon SummaryIcon"><span></span></div>
				              <div class="FieldLabel"><%=_ctx.appRes("Article.view.label.summary")%> :</div>
				              <div style="clear: left;"><span></span></div>
		                </div>
						      </div>
						    </div>
						  </div>
						  <div class="MiddleLeftArticleFrame">
						    <div class="MidlleRightArticleFrame">
			            <div class="ArticleFrameContainer">
			              <div class="FieldContent">
			              	<div class="FieldContainerContent">
			              		<div class="LabelContent">
					                <%
					                  if(node.hasProperty("exo:summary")) {
					                    print node.getProperty("exo:summary").getString() ;
					                  } else {
					                %>
					                  <%=_ctx.appRes("Article.view.label.none-summary")%>
					                <%}%>
					              </div>
											</div>	
			              </div>
			            </div>
			          </div>
			        </div>
	          </div>
	          <div style="height: 10px;"><span></span></div>
						<div class="ArticleFrame">
						  <div class="TopLeftArticleFrame">
						    <div class="TopRightArtictleFrame">
						      <div class="TopCenterArticleFrame">
						        <div class="ArticleField">
				              <div class="FieldIcon ContentIcon"><span></span></div>
				              <div class="FieldLabel"><%=_ctx.appRes("Article.view.label.content")%> :</div>
				              <div style="clear: left;"><span></span></div>
				            </div>
				          </div>
						    </div>
						  </div>
						  <div class="MiddleLeftArticleFrame">
						    <div class="MidlleRightArticleFrame">
			            <div class="ArticleFrameContainer">
			              <div class="FieldContent">
			                <div class="FieldContainerContent">
			                	<div class="LabelContent">
					                <%
					                  if(node.hasProperty("exo:text")) {
					                    print node.getProperty("exo:text").getString() ;
					                  } else {
					                %>
					                  <%=_ctx.appRes("Article.view.label.none-content")%>
					                <%}%>
				                </div>
											</div>			                
			                <div class="ContainerLinks">
			                	<div class="ContentLinks">
				                  <div class="FieldIcon LinksIcon"><span></span></div>
							            <div class="FieldLabel"><%=_ctx.appRes("Article.view.label.link")%> :</div>
							            <div style="clear: left;"><span></span></div>
							          </div>
							          <div class="WorkContentLinks">
						    					<%if(relations.size() > 0) {%>
								              <div class="Links">
																<%
												          for(rel in relations) {
													          if(rel != null) {
																	    String wsName = rel.getSession().getWorkspace().getName() ;
																      String actionLink ;
																	    String relPath = rel.getPath() ;
																	    String relName = relPath.substring(relPath.lastIndexOf("/") + 1, relPath.length()) ; 
																	    if(!uicomponent.isRssLink()) { 
																	    	params  = [new Parameter("workspaceName", wsName), new Parameter("findDrive","true")];
																	      actionLink = uicomponent.event("ChangeNode", Utils.formatNodeName(relPath), params);
																      } else { 
																	 	    actionLink = uicomponent.getRssLink() + wsName + relPath ;
																      }
																    
														    %>
					  								    <div> - <a onclick="$actionLink" style="cursor: pointer;">$relName</a></div>
					  							    <%		}
					  							    	}%>
							              </div>
								          <%}%>
								        </div>
								        <div style="clear: left;"><span></span></div>
				              </div>
				            </div>
			            </div>
			          </div>
			        </div>
					  </div>
	          <div style="height: 10px;"><span></span></div>
	          <div class="ArticleFrame">
						  <div class="TopLeftArticleFrame">
						    <div class="TopRightArtictleFrame">
						      <div class="TopCenterArticleFrame">
					          <div class="ArticleField">
				              <div class="FieldIcon AttachmentsIcon"><span></span></div>
				              <div class="FieldLabel"><%=_ctx.appRes("Article.view.label.attachment")%> :</div>
						          <div style="clear: left;"><span></span></div>
						        </div>
			            </div>
			          </div>
					    </div> 
					    <div class="MiddleLeftArticleFrame">
						    <div class="MidlleRightArticleFrame">
			            <div class="ArticleFrameContainer">
			              <div class="FieldContent">
			              	<div class="FieldContainerContent">
						        <%
						        if(attachments.size() > 0) {
							        def removeattachcomponent = uicomponent.getRemoveAttach();
							        String wsName = "";
									for (att in attachments) {
										if(att != null) {
			  							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 class="AttachmentsContainer">	
							                  <div class="AttachmentsContentIcon">
							                  	<a $linkActionName="$viewAttachmentLink" style="cursor: pointer;"><%=att.getName()%></a>
							                  </div>
							                  <% if (PermissionUtil.canRemoveNode(att)) {
							                       params = [new Parameter("workspaceName", wsName), new Parameter("repository", uicomponent.getRepository())];
							                    %>
							                    <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 style="clear: left;"><span></span></div>
							                </div>
						              <%	}
						              	} 
												 	}%>
											</div>
										</div>
								  </div>
							  </div>
		          </div>
		        </div>
		        <div style="height: 10px;"><span></span></div>
					</div>
				</div>
			</div>
			<div class="ArticleBLDecorator">
				<div class="ArticleBRDecorator">
					<div class="ArticleBCDecorator"><span></span></div>
				</div>
			</div> 
			<% try{
			 _ctx.include(uicomponent.getViewTemplate("mix:votable", "view1"));
			 }catch (Exception e) {}%> 
		</div>
		<% try{ 
		_ctx.include(uicomponent.getViewTemplate("exo:comments", "view1"));
		}catch (Exception e) {}%>
  <%} else {%>
      <div class="UIArticle">
        <div class="FieldLabel"><%=_ctx.appRes("Article.msg.no-view")%> </div>
      </div>
  <%}%>
</div>
