task-info.xslt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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:xts="http://developer.cognos.com/schemas/xts/" 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="/" mode="common">
  11. <script type="text/javascript">
  12. /*
  13. * Retrieve the task information (if available) and convert the XML into a JSON object.
  14. * Raise a new 'cognos.hts.task_info' event with the JSON payload
  15. */
  16. function _THIS_raiseTaskInfo() {
  17. var oTaskInfo = null;
  18. //convert the task information into a JSON string
  19. <xsl:variable name="jsonTaskInfo">
  20. <xsl:call-template name="convertToJSON">
  21. <xsl:with-param name="taskInfo" select="/root/input[@name='dep']/queryResponse/*[local-name()='getTaskInfoResponse']"/>
  22. </xsl:call-template>
  23. </xsl:variable>
  24. //now turn it into a javascript object. The magic of JSON
  25. <xsl:if test="$jsonTaskInfo != ''">
  26. try {
  27. oTaskInfo = eval("({<xsl:value-of select="xtsext:javascriptencode(string($jsonTaskInfo))"/>})");
  28. oTaskInfo = oTaskInfo.task;
  29. } catch (ex) {
  30. alert('<xts:string id="IDS_FRAG_ERROR_MESSAGE" encode="javascript"/>' + ex);
  31. }
  32. </xsl:if>
  33. //only fire the event when the transient taskid matches the task info response. This fixes the issue
  34. //of multiple firings of the task_info event when a task is selected. Once when the current task is
  35. //cleared and then again for the new selected task
  36. if(oTaskInfo &amp;&amp; oTaskInfo.id == _THIS_.transientState['taskid']){
  37. //pass the task details to those fragments interested
  38. _THIS_.raiseEvent('cognos.hts.task_info',oTaskInfo);
  39. }
  40. }
  41. </script>
  42. </xsl:template>
  43. </xsl:stylesheet>