<%
  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;
  import org.exoplatform.services.jcr.RepositoryService;
	
	UIPopupWindow uiPopupWindow = uicomponent.getAncestorOfType(UIPopupWindow.class);
  def resizeBlock = "class=\"UIResizableBlock\"";
  if(uiPopupWindow != null) resizeBlock = ""; 
  Parameter[] params;  
  RepositoryService rService = uicomponent.getApplicationComponent(RepositoryService.class);
  String repository = rService.getCurrentRepository().getConfiguration().getName();  
%>
<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" title="<%=Utils.getTitle(node)%>">
		          <% print uicomponent.getInlineEditingField(node, "exo:title", "", "TEXT", "GtmplTitle", "GtmplTitle", true); %>
		        </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 ClearFix">
					              <div class="FieldIcon SummaryIcon"><span></span></div>
					              <div class="FieldLabel"><%=_ctx.appRes("Article.view.label.summary")%> :</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 uicomponent.getInlineEditingField(node, "exo:summary", "", "WYSIWYG", "Summary", "Content", true);
                            } else {
                              print uicomponent.getInlineEditingField(node, "exo:summary", _ctx.appRes("Article.view.label.none-summary"), "WYSIWYG", "Summary", "Content", true);
                            }
                          %>
					              </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 ClearFix">
					              <div class="FieldIcon ContentIcon"><span></span></div>
					              <div class="FieldLabel"><%=_ctx.appRes("Article.view.label.content")%> :</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 uicomponent.getInlineEditingField(node, "exo:text", node.getProperty("exo:text").getString(), "WYSIWYG", "Text", "Content", true);
                            } else {
                              print uicomponent.getInlineEditingField(node, "exo:text", _ctx.appRes("Article.view.label.none-content"), "WYSIWYG", "Text", "Content", true);
                            }
                        %>
				                </div>
											</div>	
						<%if(relations.size() > 0) {%>		                
			                <div class="ContainerLinks ClearFix">
								<div class="ContentLinks ClearFix">
									<div class="FieldIcon LinksIcon"><span></span></div>
									<div class="FieldLabel"><%=_ctx.appRes("Article.view.label.link")%> :</div>
									
								</div>
								<div class="WorkContentLinks">
									<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.getViewableLink(rel, params);
													} else { 
														actionLink = uicomponent.getRssLink() + wsName + relPath ;
													}
													def linkActionName = (actionLink.startsWith("http")) ? "href" : "onclick";
										%>
				  								    <div> - <a $linkActionName="$actionLink" style="cursor: pointer;">$relName</a></div>
				  						<%		}
											}
										%>
									</div>
								</div>
								
							</div>
						<%}%>
						</div>
					</div>
				</div>
			        </div>
					  </div>
	          <div style="height: 10px;"><span></span></div>
	          <%if(attachments.size() > 0) {%>
	          <div class="ArticleFrame">
						  <div class="TopLeftArticleFrame">
						    <div class="TopRightArtictleFrame ClearFix">
						      <div class="TopCenterArticleFrame">
					          <div class="ArticleField">
				              <div class="FieldIcon AttachmentsIcon"><span></span></div>
				              <div class="FieldLabel"><%=_ctx.appRes("Article.view.label.attachment")%> :</div>
					          
					        </div>
			            </div>
			          </div>
					    </div> 
					    <div class="MiddleLeftArticleFrame">
						    <div class="MidlleRightArticleFrame">
			            <div class="ArticleFrameContainer">
			              <div class="FieldContent">
			              	<div class="FieldContainerContent ClearFix">
						        <%						        
							        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.getViewableLink(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", 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>
                  </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>
