actions_menu.xslt 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: cogadmin
  5. (C) Copyright IBM Corp. 2005, 2017
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  10. Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  11. -->
  12. <xsl:stylesheet version="1.0"
  13. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  14. xmlns:ui="http://developer.cognos.com/schemas/ui/presentation/markup/"
  15. xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  16. xmlns:muws2="http://docs.oasis-open.org/wsdm/muws2-2.xsd"
  17. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  18. xmlns:resource-prop="http://developer.cognos.com/admin/properties"
  19. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  20. xmlns:admui="http://developer.cognos.com/schemas/xts/admui"
  21. xmlns:wsrf-rp="http://docs.oasis-open.org/wsrf/rp-2"
  22. xmlns:nemo="http://developer.cognos.com/nemo"
  23. exclude-result-prefixes="wsrf-rp resource-prop admui xtsext xsl ui SOAP-ENV muws2 xts nemo">
  24. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  25. <!-- display variables -->
  26. <admui:variables/>
  27. <xsl:key name="supported-actions" match="/root/wsrf-rp:GetResourcePropertyResponse/*/resource-prop:Action" use="resource-prop:Name"/>
  28. <xsl:variable name="metadata" select="/root/metadata/wsrf-rp:GetResourcePropertyResponse/nemo:MetadataDescriptor"/>
  29. <xsl:template match="/root" priority="2">
  30. <xsl:variable name="encodedResourceID" select="xtsext:javascriptencode(xtsext:urlencode(string(key('env-param','objResourceID'))))"/>
  31. <xsl:variable name="jsEncodedMenuName" select="xtsext:javascriptencode(string(key('env-param','menuName')))"/>
  32. <xsl:variable name="doingGroupActions" select="key('env-param','actionType')='group'"/>
  33. <!--
  34. Show the set properties actions if:
  35. - we're doing an action on a specific resource (i.e. not a group action)
  36. - the resource has a valid storeID
  37. - we have a valid objectClass for the resource
  38. -->
  39. <xsl:variable name="showSetProperties" select="not($doingGroupActions) and key('env-param','objStoreID') != '' and key('env-param','objectClass') != '' and starts-with(key('env-param','objResourceID'),'cm:')"/>
  40. <script>
  41. <!-- build up the action menu definition -->
  42. <xsl:variable name="menuDefinition">
  43. <!-- add the set properties action if we're dealing with a cm resource -->
  44. <xsl:if test="$showSetProperties">
  45. <!-- construct the url -->
  46. <xsl:variable name="url" select="concat(/root/configProps/param[@name = 'cps']/property[@name ='gateway']/., '?b_action=xts.run&amp;m=portal/properties_general.xts&amp;m_class=', key('env-param','objectClass'), '&amp;m_path=storeID(%22', /root/storeID, '%22)&amp;m_obj=storeID(%22', key('env-param','objStoreID'), '%22)&amp;backURL=javascript:parent._THIS_callBack();')"/>
  47. {
  48. title: "<xts:string id="IDS_ADM_ACT_SET_PROPERTIES" encode="javascript"/>",
  49. <!-- todo, gen the correct image URL once the menu js file has been fixed -->
  50. image: "<xsl:value-of select="xtsext:javascriptencode(string(concat('/ps/', $common_app, '/images/action_properties.gif')))"/>",
  51. action: function(evt) { ui_modal_dialog.open('<xsl:value-of select="xtsext:javascriptencode(string($url))"/>',false,true,true); }
  52. }
  53. </xsl:if>
  54. <!-- need to get the action context id depending on if we're doing a resource action or group action -->
  55. <xsl:variable name="actionContextID">
  56. <xsl:choose>
  57. <xsl:when test="$doingGroupActions">
  58. <xsl:choose>
  59. <xsl:when test="key('env-param','groupActionContextID') != ''">
  60. <xsl:value-of select="key('env-param','groupActionContextID')"/>
  61. </xsl:when>
  62. <xsl:when test="$metadata/nemo:ActionContexts/nemo:Context[@type='groupAction']">
  63. <xsl:value-of select="$metadata/nemo:ActionContexts/nemo:Context[@type='groupAction']/@id"/>
  64. </xsl:when>
  65. </xsl:choose>
  66. </xsl:when>
  67. <xsl:otherwise>
  68. <xsl:choose>
  69. <xsl:when test="key('env-param','actionContextID') != ''">
  70. <xsl:value-of select="key('env-param','actionContextID')"/>
  71. </xsl:when>
  72. <xsl:when test="$metadata/nemo:ActionContexts/nemo:Context[@type='Action']">
  73. <xsl:value-of select="$metadata/nemo:ActionContexts/nemo:Context[@type='Action']/@id"/>
  74. </xsl:when>
  75. </xsl:choose>
  76. </xsl:otherwise>
  77. </xsl:choose>
  78. </xsl:variable>
  79. <!-- loop through all the actions -->
  80. <xsl:for-each select="$metadata/nemo:Action[key('supported-actions',nemo:Name) and not(nemo:Context[@id = $actionContextID and @exclude='true'])]">
  81. <xsl:variable name="encodedAction" select="xtsext:javascriptencode(string(nemo:Name))"/>
  82. <xsl:variable name="actionContext" select="nemo:Context[@id = $actionContextID]"/>
  83. <xsl:variable name="caption">
  84. <xsl:choose>
  85. <!-- check for the overriden caption -->
  86. <xsl:when test="$actionContext/nemo:Caption != ''">
  87. <xsl:value-of select="$actionContext/nemo:Caption"/>
  88. </xsl:when>
  89. <xsl:when test="nemo:Caption != ''">
  90. <xsl:value-of select="nemo:Caption"/>
  91. </xsl:when>
  92. <xsl:otherwise><xsl:value-of select="resource-prop:Name"/></xsl:otherwise>
  93. </xsl:choose>
  94. </xsl:variable>
  95. <xsl:variable name="encodedCaption">
  96. <xsl:value-of select="xtsext:javascriptencode($caption)"/>
  97. </xsl:variable>
  98. <xsl:variable name="confirm">
  99. <xsl:if test="nemo:Confirm">
  100. ,confirm:true
  101. <xsl:if test="nemo:Confirm/nemo:Caption != ''">
  102. ,confirmMsg:
  103. <xsl:choose>
  104. <xsl:when test="nemo:Confirm/nemo:Caption != ''">
  105. '<xsl:value-of select="xtsext:javascriptencode(nemo:Confirm/nemo:Caption)"/>'
  106. </xsl:when>
  107. <xsl:otherwise>
  108. '<xts:string id="IDS_ACTION_DEFAULT_CONFIRM" encode="javascript"><xts:param name="action"><xsl:value-of select="$encodedCaption"/></xts:param></xts:string>'
  109. </xsl:otherwise>
  110. </xsl:choose>
  111. </xsl:if>
  112. </xsl:if>
  113. </xsl:variable>
  114. <!-- get the target for the action (child, self) -->
  115. <xsl:variable name="actionTarget">
  116. <xsl:choose>
  117. <xsl:when test="$actionContext/nemo:Target">
  118. <xsl:value-of select="$actionContext/nemo:Target"/>
  119. </xsl:when>
  120. <xsl:when test="nemo:Target">
  121. <xsl:value-of select="nemo:Target"/>
  122. </xsl:when>
  123. </xsl:choose>
  124. </xsl:variable>
  125. <!-- Get the queryrelationshipbytype element.. if any -->
  126. <xsl:variable name="QRBT">
  127. <xsl:choose>
  128. <xsl:when test="$actionContext/nemo:QueryRelationshipsByType">
  129. <xsl:value-of select="$actionContext/nemo:QueryRelationshipsByType"/>
  130. </xsl:when>
  131. <xsl:when test="nemo:QueryRelationshipsByType">
  132. <xsl:value-of select="nemo:QueryRelationshipsByType"/>
  133. </xsl:when>
  134. </xsl:choose>
  135. </xsl:variable>
  136. <xsl:if test="position() = 1 and $showSetProperties">,</xsl:if>
  137. <!-- generate the jacascript for the menu -->
  138. {
  139. title: "<xsl:value-of select="$encodedCaption"/>",
  140. <xsl:if test="nemo:Icon">
  141. image: "<xsl:value-of select="xtsext:javascriptencode(string(concat('/', nemo:Icon)))"/>",
  142. </xsl:if>
  143. <xsl:variable name="precedingGroup">
  144. <xsl:value-of select="preceding-sibling::nemo:Action[1]/nemo:Group"/>
  145. </xsl:variable>
  146. <xsl:if test="not(string(nemo:Group) = string($precedingGroup))">
  147. separatorBefore:true,
  148. </xsl:if>
  149. <xsl:variable name="capability">
  150. <xsl:choose>
  151. <xsl:when test="boolean($doingGroupActions)">http://cognos.com/admin/supportedactions/resourcegroup/</xsl:when>
  152. <xsl:otherwise>http://cognos.com/admin/supportedactions/resource/</xsl:otherwise>
  153. </xsl:choose>
  154. </xsl:variable>
  155. action: function(evt) { _THIS_.relationshipsObj.doAction({isGroupAction:<xsl:value-of select="boolean($doingGroupActions)"/>,capability: '<xsl:value-of select="xtsext:javascriptencode($capability)"/>', action:'<xsl:value-of select="$encodedAction"/>', actionLabel:'<xsl:value-of select="$encodedCaption"/>', target:'<xsl:value-of select="xtsext:javascriptencode(string($actionTarget))"/>', qrbt:'<xsl:value-of select="xtsext:javascriptencode(string($QRBT))"/>'<xsl:value-of select="normalize-space($confirm)"/>}); }
  156. }
  157. <xsl:if test="position() != last()">,</xsl:if>
  158. </xsl:for-each>
  159. </xsl:variable>
  160. <!-- build up the menu -->
  161. var <xsl:value-of select="$jsEncodedMenuName"/>=new ui_menu ({id: "<xsl:value-of select="$jsEncodedMenuName"/>", fragment: "_THIS_", title: "<xts:string id="IDS_ADM_TOP_ACTIONS_TOOLTIP" encode="javascript"/>", items:[
  162. <xsl:choose>
  163. <xsl:when test="$menuDefinition != ''"><xsl:value-of select="$menuDefinition"/></xsl:when>
  164. <xsl:otherwise>
  165. {
  166. title: "<xts:string id="IDS_ADM_ACT_NO_ACTIONS"/>"
  167. }
  168. </xsl:otherwise>
  169. </xsl:choose>
  170. ]});
  171. <!--
  172. Show the menu
  173. -->
  174. ui_menuShow(_THIS_.relationshipsObj, <xsl:value-of select="$jsEncodedMenuName"/>);
  175. </script>
  176. </xsl:template>
  177. <xsl:template match="node()" priority="-1">
  178. <xsl:copy>
  179. <xsl:copy-of select="@*"/>
  180. <xsl:apply-templates/>
  181. </xsl:copy>
  182. </xsl:template>
  183. <xsl:template match="text()" priority="-1">
  184. <xsl:value-of select="."/>
  185. </xsl:template>
  186. </xsl:stylesheet>