<%
    /**
     * Created by The eXo Platform SARL
     * Author : Pham Duy Dong
     *                    phamdong@gmail.com
     * Nov 26, 2014
     * version: $Id$
     */
  import org.exoplatform.services.cms.impl.Utils;
  import org.exoplatform.social.core.service.LinkProvider;

    def rcontext = _ctx.getRequestContext();
    rcontext.getJavascriptManager()
        .require("SHARED/document-preview", "docPre")
        .addScripts("eXo.ecm.DocumentPreview.initScreen();");

    def contentNode = uicomponent.getOriginalNode();

%>


<div class="maskLayer">
    <div class="uiDocumentPreview" id="$uicomponent.id">
        <div class="exitWindow">
            <a class="uiIconClose uiIconWhite" title="<%=_ctx.appRes("UIPopupWindow.Close")%>" onclick="<%=uicomponent.event("Close")%>"></a>
        </div>
        <div class="uiDocumentPreviewMainWindow clearfix">
            <%
            uicomponent.renderChild(org.exoplatform.wcm.ext.component.activity.UIPreviewCommentArea);
            %>
            <div class="resizeButton " id="ShowHideAll">
                <i style="display: block;" class="uiIconMiniArrowRight uiIconWhite"></i>
            </div>
            <%
            def isWebContent = uicomponent.isWebContent();
            def embedHtml = uicomponent.getEmbedHtml();
            if (embedHtml != null) {
            %>
                <div class="EmbedHtml">$embedHtml</div>
            <%
            } else {
                if (isWebContent) {%>
                    <div class="uiPreviewWebContent">
                <%
                }
                      uicomponent.renderChild(org.exoplatform.social.plugin.doc.UIDocViewer);
                if (isWebContent) {
                %>
                    </div>
                <%
                }

                double voteRating = 0 ;
                if(contentNode.hasProperty("exo:votingRate")) voteRating = contentNode.getProperty("exo:votingRate").getDouble() ;
                long voteTotal = 0 ;
                if(contentNode.hasProperty("exo:voteTotalOfLang")) voteTotal = contentNode.getProperty("exo:voteTotalOfLang").getLong() ;
                %>
                <%if (voteTotal > 0) {%>
                    <div class="uiVote clearfix">
                        <div class="voteRatingInfo">
                                <%=_ctx.appRes("Vote.view.label.avg-rating")%>: <span>$voteRating</span>
                                <%=_ctx.appRes("Vote.view.label.subscription")%>: <span>$voteTotal</span>
                        </div>
                        <div class="avgRatingImages clearfix">
                            <%
                                int iVote = 0;
                                while(++iVote <= voteRating) {
                            %>
                                        <i class="voted"></i>
                                <%
                                    }
                                    while(iVote++ <= 5) {
                                %>
                                    <i class="unvoted"></i>
                                <%}%>
                        </div>
                    </div>
                <%}%>
                <%
                  def downloadLink = org.exoplatform.ecm.webui.utils.Utils.getDownloadRestServiceLink(contentNode);
                  def openLink = uicomponent.getLinkInDocumentsApp();
                 %>
                    <div class="previewBtn">
                        <div class="openBtn">
                            <a href="$openLink" rel="tooltip" data-placement="top" title="<%=_ctx.appRes("File.view.label.open-in-documents-tooltip"); %>">
                              <i class="uiIconGotoFolder uiIconWhite"></i>&nbsp;<%=_ctx.appRes("File.view.label.open-in-documents")%>
                            </a>
                        </div>
                        <div class="downloadBtn">
                            <a href="$downloadLink"><i class="uiIconDownload uiIconWhite"></i>&nbsp;<%=_ctx.appRes("File.view.label.download")%></a>
                        </div>
                    </div>
                <%
              }
            %>
        </div>
        <style>
            .uiActivityStream, .uiActivitiesLoader {
                position: static;
            }
        </style>
    </div>
</div>
