<%
  /**
  Copyright (C) 2012 eXo Platform SAS.
 
  This is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2.1 of
  the License, or (at your option) any later version.
 
  This software is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with this software; if not, write to the Free
  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
%>
<%
import org.exoplatform.ecm.webui.utils.Utils; 
import org.exoplatform.clouddrive.CloudDrive
import org.exoplatform.wcm.webui.reader.ContentReader

def rcontext = _ctx.getRequestContext()

// should be set in CloudFileFilter
def drive = rcontext.getAttribute(CloudDrive.class)  
if (drive) {
	def serviceName = drive.user.serviceName
	def openOn = _ctx.appRes("CloudFileViewer.event.OpenOn")
	def viewable = uicomponent.isViewable()
%>
<div id="CloudFileViewer" file-open-on="${openOn} ${serviceName}"
		style="position: relative; padding-top: 0; padding-bottom: 0; height: <%=viewable ? "100%" : "200px"%>; overflow: hidden;">
	<%
	if(viewable) {
	  // preview/edit view
  	def viewFile = _ctx.appRes("CloudFileViewer.event.ViewFile")
  	def editFile = _ctx.appRes("CloudFileViewer.event.EditFile")
	%>
	<div style="display: none;" class="file-content">
    <a id="ViewerSwitch" view-title="${viewFile}" edit-title="${editFile}"
      style="position: relative; padding-left: 5px; font-weight: normal;"
      class="pull-right">
      ${editFile}
    </a>
		<iframe frameborder="0"
			style="position: absolute; width: 100%; height: 100%;"
			src="">
		</iframe>
	</div>
<%
	} else {
%><div class="center">
		<div class="uiUnEditable NotViewable clearfix">
			<div class="iconContainer">
			  <i class="<%=Utils.getNodeTypeIcon(uicomponent.getParent().node, "uiIcon64x64")%>"></i>
			</div>
			<div class="detailContainer">
			  <h4><%=_ctx.appRes("File.view.label.not-viewable")%></h4>
			  <a class="btn btn-primary" href="$uicomponent.file.link"><%=_ctx.appRes("File.view.label.download")%></a>
		  </div>
		</div>
	</div>
<%
  }
} else {
%>
<p>Cannot load cloud file viewer. Refresh the page.</p>
<%
}
%>
</div>