<%
  import java.text.SimpleDateFormat ;
  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;
	
	UIPopupWindow uiPopupWindow = uicomponent.getAncestorOfType(UIPopupWindow.class);
  def resizeBlock = "class=\"UIResizableBlock\"";
  if(uiPopupWindow != null) resizeBlock = ""; 
  SimpleDateFormat dateFormat = new SimpleDateFormat() ;
  Parameter[] params;
%>
<style>
  <% _ctx.include(uicomponent.getTemplateSkin("exo:event", "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">

      <%if(node.hasProperty("exo:endEvent")) {
        Calendar cal = node.getProperty("exo:endEvent").getDate();
        def day = cal.get(Calendar.DAY_OF_MONTH);
        dateFormat.applyPattern("MMM") ;
        def month = dateFormat.format(cal.getTime());       
        def year = cal.get(Calendar.YEAR);
      %>
      <div class="EndDateLabel">
        <div class="datetime"> 
        <div class="top"><p><%=month%></p></div> 
        <p class="day"><%=day%></p> 
        <p class="yr"><%=year%></p> 
        </div>
      </div>
      <div class="ArrowDate" height="30px"><span></span></div>
      <%}%>     

      <%if(node.hasProperty("exo:startEvent")) {
        Calendar cal = node.getProperty("exo:startEvent").getDate();
        def day = cal.get(Calendar.DAY_OF_MONTH);
        dateFormat.applyPattern("MMM") ;
        def month = dateFormat.format(cal.getTime());       
        def year = cal.get(Calendar.YEAR);
      %>
      <div class="StartDateLabel">
        <div class="datetime"> 
        <div class="top"><p><%=month%></p></div> 
        <p class="day"><%=day%></p> 
        <p class="yr"><%=year%></p> 
        </div>
      </div>
      <%}%>     
      
      <%if(node.hasProperty("exo:location")) { %>
      <div class="LocationLabel"><%=node.getProperty("exo:location").getString()%></div>
      <%}%>           

      <div class="TitleLabel">
        <%if(node.hasProperty("exo:url")) { %>
        <a href="<%=node.getProperty("exo:url").getString()%>" target="_newPage">
        <%}%>           
        <%=node.getProperty("exo:title").getString()%>
        <%if(node.hasProperty("exo:url")) { %>
        </a>
        <%}%>           
			</div>
			
			<div style="clear:both"></div>
												
			<div class="ArticleFrame">
        <% if(node.hasProperty("exo:summary")) { %>
          <div class="LabelContent">
            <% print node.getProperty("exo:summary").getString() ; %>
          </div>
        <% } %>
        <% if(node.hasProperty("exo:text")) { %>
          <div class="LabelContent">
            <% print node.getProperty("exo:text").getString() ; %>
          </div>
        <% } %>
			</div>

      <% if(node.hasProperty("exo:maps") && node.getProperty("exo:maps").getBoolean()) { %>
        <div class="MapsFrame">
          <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" 
          src="http://maps.google.com/maps?q=<%=node.getProperty("exo:location").getString()%>&output=embed">
          </iframe><br />
          <small><a href="http://maps.google.com/maps?q=<%=node.getProperty("exo:location").getString()%>" style="color:#0000FF;text-align:left" target="_maps">View Larger Map</a>
          </small>
        </div>            
      <% } %>

						
      <%if(relations.size() > 0) {%>
				<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.link")%> :</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">
                      <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>	
	              </div>
	            </div>
	          </div>
	        </div>
	        
        </div>
      <%}%>
			        
			        

      <% if(attachments.size() > 0) { %>
        <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">
	              	<%
					        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")];
												%>
												  <div class="AttachmentsContainer">	
					                  <div class="AttachmentsContentIcon">
					                  	<a onclick="<%=uicomponent.event("ChangeNode", Utils.formatNodeName(att.getPath()), params)%>" 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>
				              	 
			<% }%>
			
  		<% _ctx.include(uicomponent.getViewTemplate("mix:votable", "view1")); %> 
	
		</div>

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

  <%} else {%>
    <div class="UIArticle">
      <div class="FieldLabel"><%=_ctx.appRes("Article.msg.no-view")%> </div>
    </div>
  <%}%>
</div>
