<?xml version="1.0" encoding="UTF-8" ?>
<!--
##############################################################################
#
# Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
#
# This software is distributed under the terms of the Kupu
# License. See LICENSE.txt for license text. For a list of Kupu
# Contributors see CREDITS.txt.
#
##############################################################################

XSL transformation from Kupu Library XML to HTML for the image library
drawer.

$Id: drawer.xsl.jspx 58444 2008-09-26 12:14:50Z mihxil $
-->
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:mm="http://www.mmbase.org/mmbase-taglib-2.0"
  xmlns:i18n="http://xml.zope.org/namespaces/i18n"
  >
  <mm:content type="application/xml"
              expires="0">

    <mm:link absolute="true" page="../../common/kupudrawers/drawer.xsl">
      <!-- Must be absolute, or otherwise IE chokes -->
      <xsl:import href="${_}" />
    </mm:link>


    <!--
        Overridden to use the 'showupload' parameter always, if an 'uploadbutton' tab is present
    -->
    <xsl:template match="*" mode="panel">
      <xsl:choose>
        <xsl:when test="$showupload='yes'">
          <xsl:apply-templates
              select="/libraries/*[@selected]//uploadbutton"
              mode="upload"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="//resource[@selected]">
            <xsl:choose>
              <xsl:when test="$drawertype='image'">
                <xsl:apply-templates
                    select="/libraries/*[@selected]//resource[@selected]"
                    mode="image-properties"/>
              </xsl:when>
              <xsl:when test="$drawertype='link'">
                <xsl:apply-templates
                    select="/libraries/*[@selected]//resource[@selected]"
                    mode="link-properties"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:apply-templates
                    select="/libraries/*[@selected]//resource[@selected]"
                    mode="properties"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

    <!--
        Just overridden to rename it, because we use upload also for attachments, not only for images
        (Called in 'panel' mode)
    -->
    <xsl:template match="uploadbutton" mode="upload">

      <xsl:choose>
        <xsl:when test="@media = 'image'">
          <xsl:apply-templates select="." mode="image-upload" />
        </xsl:when>
        <xsl:when test="@media = 'attachment'">
          <xsl:apply-templates select="." mode="attachment-upload" />
        </xsl:when>
        <xsl:when test="@media = 'flash'">
          <xsl:apply-templates select="." mode="attachment-upload" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="." mode="attachment-upload" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>


    <xsl:template match="uploadbutton" mode="currentpanel">
        <button class="kupu-dialog-button kupu-upload">
            <xsl:attribute name="onclick"> drawertool.current_drawer.selectUpload(); </xsl:attribute>
            <span>Upload <xsl:value-of select="gui" /></span>
        </button>
    </xsl:template>

    <xsl:template match="uploadbutton" mode="attachment-upload">
      <div id="kupu-upload-instructions" i18n:translate="attachment_upload_instructions">
        Select a file from your computer and click ok to have it automatically uploaded to
      selected folder and inserted into the editor. </div>
      <form name="kupu_upload_form" id="kupu_upload_form" method="POST"
            scrolling="off"
            target="kupu_upload_form_target" enctype="multipart/form-data" style="margin: 0;
                                                                                  border: 0;">
        <xsl:attribute name="action"><xsl:value-of select="uri"/></xsl:attribute>
        <xsl:apply-templates select="." mode="upload-fields" />
      </form>
      <iframe id="kupu_upload_form_target" name="kupu_upload_form_target" src="javascript:''"
              scrolling="off" frameborder="0" width="0px" height="0px" display="None">&#160;</iframe>
    </xsl:template>


    <xsl:template match="label|title">
      <span class="drawer-item-title">
        <xsl:copy-of select="./*|text()" />
      </span>
    </xsl:template>

    <!--
        Overridden to remove 'target', we're not interested in that.
    -->
    <xsl:template match="resource|collection" mode="link-properties">
      <xsl:apply-templates select="." mode="base-properties"/>
    </xsl:template>

    <!--
        We know height and width beforehand, so we don't use the 'kupuFixImage' function.
        That works faster and more reliable.
        They are added as attributes on all tags (icon, preview and uri).
    -->
    <xsl:template match="icon">
      <img src="{.}" alt="{../title}">
        <xsl:if test="@height">
          <xsl:attribute name="height"><xsl:value-of select="@height" /></xsl:attribute>
        </xsl:if>
        <xsl:if test="@width">
          <xsl:attribute name="width"><xsl:value-of select="@width" /></xsl:attribute>
        </xsl:if>
      </img>
    </xsl:template>


    <xsl:template match="resource|collection" mode="image-view">
      <xsl:choose>
        <xsl:when test="media = 'flash'">
          <xsl:variable name="p" select="preview"></xsl:variable>
          <object src="{$p}" data="{$p}" type="application/x-shockwave-flash"
                  width="100" height="100">
            <param name="movie" value="{$p}" />
          </object>
        </xsl:when>
        <xsl:when test="preview">
          <img src="{preview}" title="{title}"  width="{preview/@width}" height="{preview/@height}"/>
        </xsl:when>
        <xsl:otherwise>
          <img width="{uri/@width}" height="{uri/@height}" src="{uri}" title="{title}"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

    <xsl:template match="resource|collection|uploadbutton" mode="image-extra-properties-alt" />
    <xsl:template match="uploadbutton" mode="upload-to" />


    <xsl:template name="mystyle">
      <!--

          <link type="text/css" rel="stylesheet" media="all">
          <xsl:attribute name="href">mydrawerstyle.css</xsl:attribute>
          </link>
      -->
    </xsl:template>
  </mm:content>
</xsl:stylesheet>
