render-menu.xslt 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: HTS
  5. (C) Copyright IBM Corp. 2005, 2010
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt">
  9. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
  10. <xsl:template match="/">
  11. <xsl:call-template name="renderMenu"/>
  12. </xsl:template>
  13. <!-- the template that creates the menu -->
  14. <xsl:template name="renderMenu">
  15. <xsl:param name="customName"/>
  16. <xsl:param name="menu" select="/root/actions/menu"/>
  17. <xsl:param name="menuType" select="'dropdown'"/>
  18. <xsl:variable name="name" select="$menu/item[@selected='true']/name"/>
  19. <xsl:variable name="mtooltip" select="$menu/@tooltip"/>
  20. <xsl:variable name="tooltip" select="$menu/item[@selected='true']/name"/>
  21. <xsl:variable name="action" select="$menu/item[@selected='true']/action"/>
  22. <xsl:variable name="image" select="$menu/item[@selected='true']/image"/>
  23. <xsl:variable name="skin"><xsl:value-of select="xtsext:javascriptencode(string(/root/preferences/param[@name='skin']))"/></xsl:variable>
  24. <!-- the menu tooltip -->
  25. <xsl:variable name="menuTooltip">
  26. <xsl:choose>
  27. <xsl:when test="$mtooltip">
  28. <xsl:value-of select="$mtooltip"/>
  29. </xsl:when>
  30. <xsl:otherwise>
  31. <xsl:value-of select="$name"/>
  32. </xsl:otherwise>
  33. </xsl:choose>
  34. </xsl:variable>
  35. <!-- the unique menu name -->
  36. <xsl:variable name="menuName">
  37. <xsl:choose>
  38. <xsl:when test="not($customName)">
  39. <xsl:text>_THIS_</xsl:text><xsl:value-of select="$menu/@id"/>
  40. </xsl:when>
  41. <xsl:otherwise><xsl:value-of select="$customName"/></xsl:otherwise>
  42. </xsl:choose>
  43. </xsl:variable>
  44. <xsl:choose>
  45. <xsl:when test="starts-with($menuType,'combo')">
  46. <!-- the tooltip displayed when the mouse is hovered over the drop down arrow, it is empty for a menu with an image, the img tag sets the alt text instead-->
  47. <xsl:variable name="displayName">
  48. <xsl:choose>
  49. <xsl:when test="$menu/@displayName"><xsl:value-of select="$menu/@displayName"/></xsl:when>
  50. <xsl:when test="$menu/item/image"></xsl:when>
  51. <xsl:otherwise><xsl:value-of select="$menu/@id"/></xsl:otherwise>
  52. </xsl:choose>
  53. </xsl:variable>
  54. <xsl:variable name="onClickAction">
  55. <xsl:choose>
  56. <xsl:when test="$menu/@rebuild">ui_menuUpdate(<xsl:value-of select="$menuName"/>);ui_menuShow(event,<xsl:value-of select="$menuName"/>);</xsl:when>
  57. <xsl:otherwise>ui_menuShow(event,<xsl:value-of select="$menuName"/>);</xsl:otherwise>
  58. </xsl:choose>
  59. replaceCheckBox();
  60. </xsl:variable>
  61. <div id="{$menuName}_div" align="right">
  62. <xsl:if test="$menu/@titleStyle">
  63. <xsl:attribute name="class"><xsl:value-of select="$menu/@titleStyle"/></xsl:attribute>
  64. </xsl:if>
  65. <!-- if we have an image under the menu and no menu name then we assume it's a toggle menu-->
  66. <xsl:if test="$menu/item/image and $displayName=''">
  67. <!-- when the toggle menu button is clicked then fire the correct action -->
  68. <script type="text/javascript">
  69. function _THIS_<xsl:value-of select="$menuName"/>() {
  70. var menu = <xsl:value-of select="xtsext:javascriptencode(string($menuName))"/>;
  71. var item = hts_getSelectedMenuItem(menu);
  72. setTimeout(item.action, 1);
  73. }
  74. </script>
  75. <div onKeyPress="if (_hts_getKeyCode(event) == 32) _THIS_{$menuName}()" onclick="_THIS_{$menuName}()">
  76. <xsl:variable name="res">
  77. <xsl:if test="$menu/item/image[@pre]"><xsl:value-of select="$menu/item/image/@pre"/></xsl:if>
  78. <xsl:value-of select="$menu/item/image"/>
  79. <xsl:if test="$menu/item/image[@post]"><xsl:value-of select="$menu/item/image/@post"/></xsl:if>
  80. </xsl:variable>
  81. <xsl:choose>
  82. <!-- render the image for the initial selected image next to the drop down arrow -->
  83. <xsl:when test="$image">
  84. <img id="{$menuName}_img" border="0" src="{$res}" alt="{$menuTooltip}" title="{$menuTooltip}"/>
  85. </xsl:when>
  86. <!-- no image so just show the text -->
  87. <xsl:otherwise><xsl:value-of select="$name"/></xsl:otherwise>
  88. </xsl:choose>
  89. </div>
  90. </xsl:if>
  91. <div id="{$menuName}_div_text" onclick="{$onClickAction}"><xsl:if test="$displayName!=''"><xsl:value-of select="$displayName"/></xsl:if></div>
  92. <img id="{$menuName}_downarrow_img_id" role="button" tabindex="0" alt="{$menuTooltip}" title="{$menuTooltip}" style="vertical-align:middle;" onfocus="hts_setFocusCookie(this.id)" onblur="hts_setFocusCookie('')" onKeyPress=" if ( _hts_getKeyCode(event) == 32) {$onClickAction}" onclick="{$onClickAction}">
  93. <xsl:attribute name="src">
  94. <xsl:text>_THIS?frag-resource=/skins/</xsl:text>
  95. <xsl:value-of select="$skin"/>
  96. <xsl:text>/shared/images/dropdown_arrow.gif/THIS_</xsl:text>
  97. </xsl:attribute>
  98. </img>
  99. <xsl:call-template name="buildMenu">
  100. <xsl:with-param name="menu" select="$menu"/>
  101. <xsl:with-param name="name" select="$menuName"/>
  102. </xsl:call-template>
  103. </div>
  104. </xsl:when>
  105. <xsl:when test="$menuType = 'contextMenu'">
  106. <xsl:call-template name="buildMenu">
  107. <xsl:with-param name="menu" select="$menu"/>
  108. <xsl:with-param name="name" select="$menuName"/>
  109. </xsl:call-template>
  110. </xsl:when>
  111. </xsl:choose>
  112. </xsl:template>
  113. <!-- display the menu -->
  114. <xsl:template name="buildMenu">
  115. <xsl:param name="menu"/>
  116. <xsl:param name="name"/>
  117. <script type="text/javascript">
  118. var _THIS_values = new Array();
  119. var <xsl:value-of select="$name"/>=new ui_menu({id: "<xsl:value-of select="xtsext:javascriptencode(string($name))"/>", fragment: "_THIS_", items:[
  120. <xsl:for-each select="$menu/item">
  121. {
  122. title: "<xsl:value-of select="xtsext:javascriptencode(string(./name))"/>",
  123. <xsl:if test="@selected='true'">
  124. selected: <xsl:value-of select="@selected"/>,
  125. </xsl:if>
  126. <xsl:if test="$menu/item/image[@pre]">
  127. pre: "<xsl:value-of select="xtsext:javascriptencode(string($menu/item/image/@pre))"/>",
  128. </xsl:if>
  129. <xsl:if test="$menu/item/image[@post]">
  130. post: "<xsl:value-of select="xtsext:javascriptencode(string($menu/item/image/@post))"/>",
  131. </xsl:if>
  132. <xsl:if test="./image">
  133. image: "<xsl:value-of select="xtsext:javascriptencode(string(./image))"/>",
  134. </xsl:if>
  135. <xsl:if test="@separatorBefore='true'">
  136. <xsl:text>separatorBefore: true,</xsl:text>
  137. </xsl:if>
  138. action: function(evt) {
  139. <xsl:value-of select="./action"/>
  140. } ,
  141. getItemState: function(menudef, i) {
  142. return _THIS_action_getItemState(menudef, i);
  143. }
  144. }
  145. <xsl:if test="position() != last()">,</xsl:if>
  146. </xsl:for-each>
  147. <xsl:text>]});</xsl:text>
  148. <!-- collect the combo values -->
  149. <xsl:for-each select="$menu/item/value">
  150. <xsl:choose>
  151. <xsl:when test="@type='script'">
  152. var result = function () {<xsl:value-of select="normalize-space(.)"/>}
  153. _THIS_values['<xsl:value-of select="xtsext:javascriptencode(string(../name))"/>']=result();
  154. </xsl:when>
  155. <xsl:otherwise>
  156. _THIS_values["<xsl:value-of select="xtsext:javascriptencode(string(../name))"/>"]="<xsl:value-of select="."/>";
  157. </xsl:otherwise>
  158. </xsl:choose>
  159. </xsl:for-each>
  160. <!-- now load the combo values into the menu definition -->
  161. var _THIS_def = <xsl:value-of select="xtsext:javascriptencode(string($name))"/>.menudef;
  162. for(key in _THIS_def.items) {
  163. var item = _THIS_def.items[key];
  164. if (_THIS_values[item.title] != undefined) {
  165. item.value = _THIS_values[item.title];
  166. }
  167. }
  168. if (typeof _THIS_menuLoaded != 'undefined') {
  169. _THIS_menuLoaded('<xsl:value-of select="xtsext:javascriptencode(string($name))"/>');
  170. }
  171. function replaceCheckBox() {
  172. dojo.query("TD[style*='checkmark.gif']").forEach(
  173. function(node, index, arr) {
  174. var srcImage = dojo.style(node,'backgroundImage');
  175. srcImage = srcImage.replace("fragments/common", "fragments/myinbox");
  176. srcImage = srcImage.replace("checkmark.gif", "radio_enabled.gif");
  177. dojo.style(node,'backgroundImage',srcImage);
  178. }
  179. );
  180. }
  181. </script>
  182. </xsl:template>
  183. </xsl:stylesheet>