view.xslt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: cpscrn
  5. (C) Copyright IBM Corp. 2005, 2011
  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:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  15. xmlns:nav="http://developer.cognos.com/schemas/cps/navigation/1/"
  16. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  17. exclude-result-prefixes="SOAP-ENV nav xtsext">
  18. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="no"/>
  19. <xsl:variable name="navresult" select="/root/navresult"/>
  20. <xsl:variable name="root-container" select="$navresult/SOAP-ENV:Envelope/SOAP-ENV:Body/nav:getContainerResponse/nav:container"/>
  21. <xsl:variable name="action-item" select="$navresult/SOAP-ENV:Envelope/SOAP-ENV:Body/nav:getItemResponse/*[ self::nav:container | self::nav:item | self::nav:shortcut ]"/>
  22. <xsl:variable name="param-actions" select="/root/env/param[@name = 'actions']"/>
  23. <xsl:variable name="container-id" select="/root/env/param[@name = 'container']"/>
  24. <xsl:variable name="open-root" select="/root/env/param[@name = 'openRoot']"/>
  25. <xsl:variable name="container-margin" select="/root/env/param[@name = 'margin']"/>
  26. <xsl:variable name="open-id">
  27. <xsl:if test="not($action-item) and not($container-id) and $open-root = 'true'">
  28. <xsl:value-of select="$root-container/nav:id"/>
  29. </xsl:if>
  30. </xsl:variable>
  31. <xsl:template match="/">
  32. <xsl:choose>
  33. <xsl:when test="$action-item">
  34. <xsl:call-template name="actions"/>
  35. </xsl:when>
  36. <xsl:when test="$container-id">
  37. <xsl:call-template name="fragment"/>
  38. </xsl:when>
  39. <xsl:otherwise>
  40. <xsl:call-template name="mainpage"/>
  41. </xsl:otherwise>
  42. </xsl:choose>
  43. </xsl:template>
  44. <xsl:template name="mainpage">
  45. <script>
  46. var WEBCONTENT_URI = "_THIS?frag-resource=/fragments/navtree/THIS_";
  47. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  48. // Tree code
  49. // - - - - - - - - - - - - - - - - - - - - - - - - - - -
  50. // Preload images
  51. var _THIS_containerImgNames =
  52. [
  53. // 0 - single root
  54. [
  55. "tv_Lplus_top.gif",
  56. "tv_Lminus_top.gif"
  57. ],
  58. // 1 - multiple root top
  59. [
  60. "tv_Tplus_top.gif",
  61. "tv_Tminus_top.gif"
  62. ],
  63. // 2 - middle container
  64. [
  65. "tv_Tplus.gif",
  66. "tv_Tminus.gif"
  67. ],
  68. // 3 - last container
  69. [
  70. "tv_Lplus.gif",
  71. "tv_Lminus.gif"
  72. ]
  73. ];
  74. // preload container images
  75. var _THIS_imgContainer = new Array(_THIS_containerImgNames.length);
  76. for (var i = 0; i &lt; _THIS_containerImgNames.length; i++)
  77. {
  78. _THIS_imgContainer[i] = new Array(2);
  79. for (var j = 0; j &lt; 2; j++)
  80. {
  81. _THIS_imgContainer[i][j] = new Image(19, 20);
  82. _THIS_imgContainer[i][j].src = WEBCONTENT_URI + "/images/" + _THIS_containerImgNames[i][j];
  83. }
  84. }
  85. // - - - - - - - - - - - - - - - - - - - - - - - - - - -
  86. // open/close folders
  87. var _THIS_containers = { };
  88. <xsl:if test="$open-id != ''">
  89. _THIS_containers["<xsl:value-of select="$open-id"/>"] = true;
  90. </xsl:if>
  91. function _THIS_toggleFolder(sId, sMargin, nIndex)
  92. {
  93. var img = $('_THIS_img_' + sId);
  94. var div = $('_THIS_content_' + sId);
  95. if (div.style.display == "none")
  96. {
  97. img.src = _THIS_imgContainer[nIndex][1].src;
  98. div.style.display = "block";
  99. if (!_THIS_containers[sId])
  100. {
  101. _THIS_.retrieve('container=' + sId + '&amp;margin=' + sMargin, div);
  102. _THIS_containers[sId] = true;
  103. }
  104. }
  105. else
  106. {
  107. img.src = _THIS_imgContainer[nIndex][0].src;
  108. div.style.display = "none";
  109. }
  110. }
  111. // - - - - - - - - - - - - - - - - - - - - - - - - - - -
  112. // item selection
  113. var _THIS_currentItem = "";
  114. function _THIS_getItemSpan(sId)
  115. {
  116. var item = $("dragitem_" + sId + "_THIS_");
  117. var span = xGetElementsByTagName("SPAN", item);
  118. if (span.length > 0)
  119. {
  120. span[0].style.backgroundColor = background;
  121. span[0].style.color = color;
  122. }
  123. }
  124. function _THIS_colorItem(sId, color, background)
  125. {
  126. var item = $("dragitem_" + sId + "_THIS_");
  127. var span = xGetElementsByTagName("SPAN", item);
  128. if (span.length > 0)
  129. {
  130. span[0].style.backgroundColor = background;
  131. span[0].style.color = color;
  132. }
  133. }
  134. function _THIS_selectItem(sType, sTitle, sId)
  135. {
  136. if (_THIS_currentItem)
  137. {
  138. _THIS_colorItem(_THIS_currentItem, "black", "white");
  139. _THIS_currentItem = "";
  140. }
  141. if (sId)
  142. {
  143. _THIS_colorItem(sId, "white", "blue");
  144. _THIS_currentItem = sId;
  145. var payload = [ sType, sTitle, sId ];
  146. _THIS_.raiseEvent("cognos.view", payload, "application");
  147. }
  148. }
  149. // - - - - - - - - - - - - - - - - - - - - - - - - - - -
  150. </script>
  151. <xsl:apply-templates select="$root-container">
  152. <xsl:with-param name="content" select="$root-container/nav:content/*[$open-root = 'true']"/>
  153. </xsl:apply-templates>
  154. </xsl:template>
  155. <xsl:template name="fragment">
  156. <xsl:apply-templates select="$navresult//nav:container[nav:id = $container-id][1]/nav:content/*">
  157. <xsl:with-param name="margin" select="$container-margin"/>
  158. </xsl:apply-templates>
  159. </xsl:template>
  160. <xsl:template name="actions">
  161. <xsl:apply-templates select="$action-item" mode="actions"/>
  162. </xsl:template>
  163. <!--
  164. nav:container
  165. -->
  166. <xsl:template match="nav:container">
  167. <xsl:param name="margin"/>
  168. <xsl:param name="content"/>
  169. <xsl:variable name="index">
  170. <xsl:call-template name="calc-index"/>
  171. </xsl:variable>
  172. <xsl:variable name="has-children" select="boolean(nav:hasChildren[. = 'true' or . = '1'])"/>
  173. <xsl:choose>
  174. <xsl:when test="$has-children">
  175. <xsl:variable name="new-margin">
  176. <xsl:value-of select="$margin"/>
  177. <xsl:choose>
  178. <xsl:when test="position() = last()">
  179. <xsl:text>O</xsl:text>
  180. </xsl:when>
  181. <xsl:otherwise>
  182. <xsl:text>I</xsl:text>
  183. </xsl:otherwise>
  184. </xsl:choose>
  185. </xsl:variable>
  186. <div id="dragitem_{ nav:id }_THIS_" dragtype="{ nav:type }" payload="{ nav:id }" itemtitle="{ nav:name }"
  187. style="height: 20px; border: 0; cursor: default; white-space: nowrap">
  188. <xsl:call-template name="render-margin">
  189. <xsl:with-param name="margin" select="$margin"/>
  190. </xsl:call-template>
  191. <xsl:variable name="img-name">
  192. <xsl:call-template name="container-image">
  193. <xsl:with-param name="index" select="$index"/>
  194. <xsl:with-param name="is-open" select="boolean($content)"/>
  195. </xsl:call-template>
  196. </xsl:variable>
  197. <img id="_THIS_img_{ nav:id }" src="_THIS?frag-resource=/fragments/navtree/images/{ $img-name }/THIS_" style="vertical-align: middle;" width="19" height="20" alt=""
  198. onclick="_THIS_toggleFolder('{ nav:id }', '{ $new-margin }', '{ $index }')" />
  199. <xsl:call-template name="render-name"/>
  200. </div>
  201. <div id="_THIS_content_{ nav:id }">
  202. <xsl:choose>
  203. <xsl:when test="$content">
  204. <xsl:apply-templates select="$content">
  205. <xsl:with-param name="margin" select="$new-margin"/>
  206. </xsl:apply-templates>
  207. </xsl:when>
  208. <xsl:otherwise>
  209. <xsl:attribute name="style">display: none</xsl:attribute>
  210. <xsl:call-template name="render-margin">
  211. <xsl:with-param name="margin" select="$new-margin"/>
  212. </xsl:call-template>
  213. <img src="_THIS?frag-resource=/fragments/navtree/images/tv_loading.gif/THIS_" width="19" height="20" style="vertical-align: bottom" alt=""/>
  214. <span style="height: 20px; vertical-align: middle">
  215. <xsl:text>&#160;Loading...</xsl:text>
  216. </span>
  217. </xsl:otherwise>
  218. </xsl:choose>
  219. </div>
  220. </xsl:when>
  221. <xsl:otherwise>
  222. <div id="dragitem_{ nav:id }_THIS_" dragtype="{ nav:type }" payload="{ nav:id }" itemtitle="{ nav:name }"
  223. style="height: 20px; margin: 2px; border: 0; cursor: default; white-space: nowrap">
  224. <xsl:call-template name="render-margin">
  225. <xsl:with-param name="margin" select="$margin"/>
  226. </xsl:call-template>
  227. <xsl:variable name="img-name">
  228. <xsl:call-template name="item-image">
  229. <xsl:with-param name="index" select="$index"/>
  230. </xsl:call-template>
  231. </xsl:variable>
  232. <img src="_THIS?frag-resource=/fragments/navtree/images/{ $img-name }/THIS_" width="19" height="20" style="vertical-align: bottom" alt=""/>
  233. <xsl:call-template name="render-name"/>
  234. </div>
  235. </xsl:otherwise>
  236. </xsl:choose>
  237. </xsl:template>
  238. <xsl:template match="nav:item | nav:shortcut">
  239. <xsl:param name="margin"/>
  240. <div id="dragitem_{ nav:id }_THIS_" dragtype="{ nav:type }" payload="{ nav:id }" itemtitle="{ nav:name }"
  241. style="height: 20px; border: 0; cursor: default; white-space: nowrap"
  242. onclick="_THIS_selectItem('{ nav:type }', '{ nav:name }', '{ nav:id }')">
  243. <xsl:call-template name="render-margin">
  244. <xsl:with-param name="margin" select="$margin"/>
  245. </xsl:call-template>
  246. <xsl:variable name="index">
  247. <xsl:call-template name="calc-index"/>
  248. </xsl:variable>
  249. <xsl:variable name="img-name">
  250. <xsl:call-template name="item-image">
  251. <xsl:with-param name="index" select="$index"/>
  252. </xsl:call-template>
  253. </xsl:variable>
  254. <img src="_THIS?frag-resource=/fragments/navtree/images/{ $img-name }/THIS_" width="19" height="20" style="vertical-align: bottom" alt=""/>
  255. <xsl:call-template name="render-name"/>
  256. </div>
  257. </xsl:template>
  258. <xsl:template name="render-name">
  259. <img id="icon__THIS_{ nav:id }" style="vertical-align: middle" src="{ nav:imgURL }" alt="{ nav:type }"/>
  260. <xsl:text>&#160;&#160;</xsl:text>
  261. <span style="height: 20px; line-height: 20px; vertical-align: bottom">
  262. <xsl:value-of select="nav:name"/>
  263. </span>
  264. </xsl:template>
  265. <!--
  266. <xsl:template name="render-name">
  267. <xsl:variable name="resource-url">
  268. <xslText>http://localhost/series8/cgi-bin/cognos.cgi?m=/cps4/portlets/designer/portlet-impl/navtree/getMarkup.xts&amp;id=</xslText>
  269. <xsl:value-of select="nav:id"/>
  270. <xsl:text>&amp;actions=true</xsl:text>
  271. </xsl:variable>
  272. <xsl:variable name="rewritable-url">
  273. <xsl:text>_THIS?wsrp-urlType=resource&amp;wsrp-url=</xsl:text>
  274. <xsl:value-of select="xtsext:urlencode($resource-url)"/>
  275. <xsl:text>&amp;wsrp-requiresRewrite=true/THIS_</xsl:text>
  276. </xsl:variable>
  277. <img id="icon__THIS_{ nav:id }" style="vertical-align: middle" src="{ nav:imgURL }" alt="{ nav:type }"/>
  278. <xsl:text>&#160;&#160;</xsl:text>
  279. <span style="height: 20px; line-height: 20px; vertical-align: bottom" oncontextmenu="_THIS_contextMenu('{ $rewritable-url }', this); return false" onclick="_THIS_onview('{ nav:id }', '{ nav:type }', '{ nav:name }')">
  280. <xsl:value-of select="nav:name"/>
  281. </span>
  282. </xsl:template>
  283. -->
  284. <xsl:template name="calc-index">
  285. <xsl:choose>
  286. <!-- not root -->
  287. <xsl:when test="ancestor::nav:container[1]">
  288. <xsl:choose>
  289. <xsl:when test="position() = last()">
  290. <xsl:text>3</xsl:text>
  291. </xsl:when>
  292. <xsl:otherwise>
  293. <xsl:text>2</xsl:text>
  294. </xsl:otherwise>
  295. </xsl:choose>
  296. </xsl:when>
  297. <!-- root -->
  298. <xsl:otherwise>
  299. <xsl:choose>
  300. <xsl:when test="position() = 1 and position() = last()">
  301. <xsl:text>0</xsl:text>
  302. </xsl:when>
  303. <xsl:when test="position() = 1">
  304. <xsl:text>1</xsl:text>
  305. </xsl:when>
  306. <xsl:when test="position() = last()">
  307. <xsl:text>3</xsl:text>
  308. </xsl:when>
  309. <xsl:otherwise>
  310. <xsl:text>2</xsl:text>
  311. </xsl:otherwise>
  312. </xsl:choose>
  313. </xsl:otherwise>
  314. </xsl:choose>
  315. </xsl:template>
  316. <xsl:template name="container-image">
  317. <xsl:param name="index"/>
  318. <xsl:param name="is-open"/>
  319. <xsl:choose>
  320. <xsl:when test="$index = '0'">
  321. <xsl:choose>
  322. <xsl:when test="$is-open">
  323. <xsl:text>tv_Lminus_top.gif</xsl:text>
  324. </xsl:when>
  325. <xsl:otherwise>
  326. <xsl:text>tv_Lplus_top.gif</xsl:text>
  327. </xsl:otherwise>
  328. </xsl:choose>
  329. </xsl:when>
  330. <xsl:when test="$index = '1'">
  331. <xsl:choose>
  332. <xsl:when test="$is-open">
  333. <xsl:text>tv_Tminus_top.gif</xsl:text>
  334. </xsl:when>
  335. <xsl:otherwise>
  336. <xsl:text>tv_Tplus_top.gif</xsl:text>
  337. </xsl:otherwise>
  338. </xsl:choose>
  339. </xsl:when>
  340. <xsl:when test="$index = '2'">
  341. <xsl:choose>
  342. <xsl:when test="$is-open">
  343. <xsl:text>tv_Tminus.gif</xsl:text>
  344. </xsl:when>
  345. <xsl:otherwise>
  346. <xsl:text>tv_Tplus.gif</xsl:text>
  347. </xsl:otherwise>
  348. </xsl:choose>
  349. </xsl:when>
  350. <xsl:when test="$index = '3'">
  351. <xsl:choose>
  352. <xsl:when test="$is-open">
  353. <xsl:text>tv_Lminus.gif</xsl:text>
  354. </xsl:when>
  355. <xsl:otherwise>
  356. <xsl:text>tv_Lplus.gif</xsl:text>
  357. </xsl:otherwise>
  358. </xsl:choose>
  359. </xsl:when>
  360. </xsl:choose>
  361. </xsl:template>
  362. <xsl:template name="item-image">
  363. <xsl:param name="index"/>
  364. <xsl:choose>
  365. <xsl:when test="$index = '0'">
  366. <xsl:text>tv_L_top.gif</xsl:text>
  367. </xsl:when>
  368. <xsl:when test="$index = '1'">
  369. <xsl:text>tv_T_top.gif</xsl:text>
  370. </xsl:when>
  371. <xsl:when test="$index = '2'">
  372. <xsl:text>tv_T.gif</xsl:text>
  373. </xsl:when>
  374. <xsl:when test="$index = '3'">
  375. <xsl:text>tv_L.gif</xsl:text>
  376. </xsl:when>
  377. </xsl:choose>
  378. </xsl:template>
  379. <xsl:template name="margin-image">
  380. <xsl:param name="type"/>
  381. <xsl:choose>
  382. <xsl:when test="$type = 'I'">
  383. <xsl:text>tv_I.gif</xsl:text>
  384. </xsl:when>
  385. <xsl:otherwise>
  386. <xsl:text>tv_white.gif</xsl:text>
  387. </xsl:otherwise>
  388. </xsl:choose>
  389. </xsl:template>
  390. <xsl:template name="render-margin">
  391. <xsl:param name="margin"/>
  392. <xsl:if test="$margin != ''">
  393. <xsl:variable name="type" select="substring($margin, 1, 1)"/>
  394. <xsl:variable name="image">
  395. <xsl:call-template name="margin-image">
  396. <xsl:with-param name="type" select="$type"/>
  397. </xsl:call-template>
  398. </xsl:variable>
  399. <img src="_THIS?frag-resource=/fragments/navtree/images/{ $image }/THIS_" width="19" height="20" style="vertical-align: bottom" alt=""/>
  400. <xsl:call-template name="render-margin">
  401. <xsl:with-param name="margin" select="substring($margin, 2)"/>
  402. </xsl:call-template>
  403. </xsl:if>
  404. </xsl:template>
  405. <xsl:template match="*" mode="actions">
  406. <xsl:for-each select="nav:action">
  407. <xsl:call-template name="render-menuitem">
  408. <xsl:with-param name="id" select="../../nav:id"/>
  409. <xsl:with-param name="name" select="nav:name"/>
  410. <xsl:with-param name="alt" select="nav:alt"/>
  411. <xsl:with-param name="img" select="nav:imgName"/>
  412. <xsl:with-param name="url" select="nav:url"/>
  413. </xsl:call-template>
  414. </xsl:for-each>
  415. <!-- hr/ -->
  416. <xsl:call-template name="render-menuitem">
  417. <xsl:with-param name="id" select="nav:id"/>
  418. <xsl:with-param name="name" select="'More...'"/>
  419. <xsl:with-param name="alt" select="''"/>
  420. <xsl:with-param name="img">_THIS?frag-resource=/fragments/navtree/images/space.gif/THIS_</xsl:with-param>
  421. <xsl:with-param name="url" select="nav:actionsURL"/>
  422. </xsl:call-template>
  423. </xsl:template>
  424. <xsl:template name="render-menuitem">
  425. <xsl:param name="id"/>
  426. <xsl:param name="name"/>
  427. <xsl:param name="alt"/>
  428. <xsl:param name="img"/>
  429. <xsl:param name="url"/>
  430. <div id="_THIS_menuitem_{ $id }_{ position() }" style="padding-left:5px; padding-right:5px; height: 20px; width: 150px; white-space: nowrap" url="{ $url }">
  431. <img style="vertical-align: middle" width="16" height="16" src="{ $img }" alt="{ $alt }"/>
  432. <span style="vertical-align: middle; width: 100%">
  433. <xsl:text>&#160;&#160;</xsl:text>
  434. <xsl:value-of select="$name"/>
  435. <xsl:text>&#160;&#160;&#160;&#160;</xsl:text>
  436. </span>
  437. </div>
  438. </xsl:template>
  439. </xsl:stylesheet>