menubar.xslt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: AGS
  5. (C) Copyright IBM Corp. 2005, 2014
  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"
  9. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  10. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  11. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  12. exclude-result-prefixes="xsl xts xtsext">
  13. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="no"/>
  14. <!-- create the menu bar-->
  15. <xsl:template match="/">
  16. <xsl:apply-templates select="/root/menuBar"/>
  17. </xsl:template>
  18. <!-- create the JS to load the menu bar-->
  19. <xsl:template match="menuBar">
  20. <script type="text/javascript">
  21. //Contains the menus that have capablities only.
  22. var menuItemMap = new Object();
  23. function loadMenu() {
  24. var menuItemStyle = new CUIStyle('menuItem_normal', 'menuItem_hover', 'menuItem_hover', 'menuItem_hover', 'menuItem_disabled');
  25. var menuTitleStyle = new CUIStyle('menuTitle_normal', 'menuTitle_hover', 'menuTitle_hover', 'menuTitle_hover', '');
  26. var menuStyle = new CUIStyle('menuContainer', 'menuTitle_pressed', 'menuTitle_pressed', 'menuTitle_pressed', '');
  27. // define the separators
  28. var gMenuSeperatorStyle = new CUIStyle('menuHorizontalSeperator','','','','');
  29. var menuSeperator = new CSeperator('horizontal_line', '1',gMenuSeperatorStyle);
  30. var blankSeparator = new CSeperator("horizonal_blank", "16");
  31. m_menu = new CBar('menuBar');
  32. var accessibility_cookie = getCookie("AGS_ACCESSIBILITY_ENABLED");
  33. //define the menu items
  34. if (accessibility_cookie != 'true') {
  35. <xsl:apply-templates select="label">
  36. <xsl:with-param name="a11y_enabled">false</xsl:with-param>
  37. </xsl:apply-templates>
  38. }
  39. else {
  40. <xsl:apply-templates select="label">
  41. <xsl:with-param name="a11y_enabled">true</xsl:with-param>
  42. </xsl:apply-templates>
  43. }
  44. m_menu.setMenuType(cHorizonalBar);
  45. m_menu.draw();
  46. }
  47. </script>
  48. </xsl:template>
  49. <!-- create the top level menu label-->
  50. <xsl:template match="label">
  51. <xsl:param name="a11y_enabled"/>
  52. <!-- create a unique label menu id-->
  53. <xsl:variable name="menuName" select="concat('label',generate-id())"/>
  54. <!-- add the menu label-->
  55. var <xsl:value-of select="$menuName"/>=new CMenuItem(m_menu, &quot;<xsl:value-of select='xtsext:javascriptencode(string(normalize-space(name)))'/>&quot;,&quot;<xsl:value-of select='xtsext:javascriptencode(string(normalize-space(id)))'/>&quot;, '','',menuTitleStyle);
  56. var <xsl:value-of select="$menuName"/>_menuItems = <xsl:value-of select="$menuName"/>.createDropDownMenu(menuStyle);
  57. <xsl:value-of select="$menuName"/>_menuItems.setOffsetXCoords(-1);
  58. <xsl:value-of select="$menuName"/>_menuItems.setOffsetYCoords(3);
  59. <!-- add the menu items for the current label-->
  60. <xsl:apply-templates select="./items/item">
  61. <xsl:with-param name="parentMenu" select="concat($menuName,'_menuItems')"/>
  62. <xsl:with-param name="a11y_flag" select="$a11y_enabled"/>
  63. </xsl:apply-templates>
  64. </xsl:template>
  65. <!-- this template will loop through the menu items and create the JS for each one-->
  66. <xsl:template match="items/item">
  67. <xsl:param name="parentMenu"/>
  68. <xsl:param name="a11y_flag"/>
  69. <xsl:variable name="subMenuName" select="concat('item',generate-id())"/>
  70. <!-- define the action, it may be null -->
  71. <xsl:variable name="action">
  72. <xsl:choose>
  73. <xsl:when test="action != ''">&quot;javascript:<xsl:value-of select="xtsext:javascriptencode(string(action))"/>&quot;</xsl:when>
  74. <xsl:when test="not(items/item)">&quot;javascript:alert('This menu item is not implemented yet');&quot;</xsl:when>
  75. <xsl:otherwise>null</xsl:otherwise>
  76. </xsl:choose>
  77. </xsl:variable>
  78. <xsl:if test="not(./hide) or (./hide and /root/evts/configuration/property[@name='enableHiddenMenuItems']='true')">
  79. <!-- add the menu item-->
  80. var <xsl:value-of select="$subMenuName"/>= new CMenuItem(<xsl:value-of select="$parentMenu"/>, "<xsl:value-of select="xtsext:javascriptencode(string(normalize-space(name)))"/>", "<xsl:value-of select="xtsext:javascriptencode(string(normalize-space(id)))"/>", <xsl:value-of select="$action"/>, "<xsl:value-of select="xtsext:javascriptencode(string(icon))"/>", menuItemStyle, "<xsl:value-of select="xtsext:javascriptencode(string(tooltip))"/>","", "<xsl:value-of select="xtsext:javascriptencode(string(userCapability))"/>" );
  81. // add cascade true so that we can get space in the right after menuitem text
  82. <xsl:value-of select="$parentMenu"/>.setContainsCascadedChildren(true);
  83. <!--keyed menu items can be retrieved using the key, keys should be unique for all menu items in the application menu bar-->
  84. <xsl:if test="./key">
  85. menuItemMap[&quot;<xsl:value-of select="./key"/>&quot;] = <xsl:value-of select="$subMenuName"/>;
  86. </xsl:if>
  87. <!-- Do not add the ones with key again. -->
  88. <xsl:if test="not(./key) and ./userCapability">
  89. menuItemMap[&quot;<xsl:value-of select="xtsext:javascriptencode(string(normalize-space(id)))"/>&quot;] = <xsl:value-of select="$subMenuName"/>;
  90. </xsl:if>
  91. <!-- A11Y check for switch the enable or disable accessibility menu item-->
  92. <xsl:if test="./accessibility">
  93. <xsl:value-of select="$subMenuName"/>.hide();
  94. <xsl:choose>
  95. <xsl:when test="accessibility = 'enable' and $a11y_flag = 'false'">
  96. <xsl:value-of select="$subMenuName"/>.show();
  97. </xsl:when>
  98. <xsl:when test="accessibility = 'disable' and $a11y_flag = 'true'">
  99. <xsl:value-of select="$subMenuName"/>.show();
  100. </xsl:when>
  101. </xsl:choose>
  102. </xsl:if>
  103. <xsl:if test="./items/item">
  104. var <xsl:value-of select="$subMenuName"/>_cascaded = <xsl:value-of select="$subMenuName"/>.createCascadedMenu(menuStyle,5);
  105. <xsl:value-of select="$subMenuName"/>_cascaded.setOffsetYCoords(-1);
  106. <xsl:apply-templates select="./items/item">
  107. <xsl:with-param name="parentMenu" select="concat($subMenuName,'_cascaded')"/>
  108. </xsl:apply-templates>
  109. </xsl:if>
  110. </xsl:if>
  111. </xsl:template>
  112. <!-- create a menu separator (hr) -->
  113. <xsl:template match="items/item[@type='separator']">
  114. <xsl:param name="parentMenu"/>
  115. <xsl:value-of select="$parentMenu"/>.add(menuSeperator);
  116. </xsl:template>
  117. </xsl:stylesheet>