render-outputs.xslt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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, 2020
  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" xmlns:hts="http://developer.cognos.com/myinbox/common/hts_ui" >
  9. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
  10. <xsl:variable name="report_output_tooltip"><xts:string id="IDS_REPORT_OUTPUT_TOOLTIP"/></xsl:variable>
  11. <xsl:variable name="report_tooltip"><xts:string id="IDS_REPORT_TOOLTIP"/></xsl:variable>
  12. <xsl:template match="/">
  13. <xsl:call-template name="renderUI"/>
  14. </xsl:template>
  15. <xsl:template name="renderUI">
  16. <xsl:param name="path"/>
  17. <xsl:param name="channel"/>
  18. <script type="text/javascript">
  19. dojo.require("dojox.collections.Dictionary");
  20. dojo.require("dojo.html");
  21. var _THIS_userId = "<xsl:value-of select="xtsext:javascriptencode(string(/root/interactions/param[@name='user_id']))"/>";
  22. var _THIS_userName = "<xsl:value-of select="xtsext:javascriptencode(string(/root/interactions/param[@name='user_name']))"/>";
  23. //hold the details of an attachment/link when clicked, key=id, value=object with properties id,objectClass,title
  24. var _THIS_outputDetails = new dojox.collections.Dictionary();
  25. //create the style object for the clist
  26. var _THIS_uiStyle = new CUIStyle("CList_li", "CList_over", "CList_selected", "", null);
  27. /*
  28. create the clist object with the optional button mode (default is toggle)
  29. the clist object has two modes 1. 'toggle' where each item acts like a toggle button and multiple items can be selected 2. 'button' where each item acts like a normal button
  30. In 'button' mode the on click handler MUST be set by calling setSingleClickFunc(...)
  31. */
  32. var _THIS_cListGenTask = new CList("myCList",true, "CList_ul",_THIS_uiStyle,'button');
  33. //create the links object
  34. var _THIS_htsLinks = new HTSLinks(_THIS_cListGenTask,$('_THIS_linksDivGen'));
  35. _THIS_cListGenTask.setSingleClickFunc(_THIS_view);
  36. _THIS_cListGenTask.setKeyPressFunc(_THIS_view);
  37. function _THIS_disableAll() {
  38. var utils = new hts_utils();
  39. var content =$(_THIS_.div);
  40. utils.setUIState(content,true);
  41. }
  42. function _THIS_view(evt,listItem) {
  43. var nodelist = dojo.query("div[id]",listItem)
  44. if (nodelist.length &gt; 0) {
  45. var id = nodelist.at(0).attr("id");
  46. if (id=="") {
  47. alert('<xts:string id="IDS_FRAG_NO_EVENT_LIST" encode="javascript"/>');
  48. return;
  49. }
  50. var details = _THIS_outputDetails.item(id);
  51. var eventList=details.eventList;
  52. var objectClass = details.objectClass;
  53. /*
  54. * open the universal viewer in a new window. customize the appearance by maximizing the fragment and removing the viewer's toolbar
  55. */
  56. var sViewerURL = _F_Config.gateway + "?objRef="+id;
  57. window.open(sViewerURL,&apos;_THIS_&apos;+"viewerWindow","location=no,status=no,resizable=yes");
  58. }
  59. else {
  60. alert('<xts:string id="IDS_FRAG_NO_EVENT_LIST" encode="javascript"/>');
  61. return;
  62. }
  63. }
  64. </script>
  65. <xsl:variable name="previews">
  66. <xsl:call-template name="getFilteredAgentTaskPreviews">
  67. <xsl:with-param name="path" select="$path"/>
  68. </xsl:call-template>
  69. </xsl:variable>
  70. <!-- check if we have any links or attachments -->
  71. <xsl:if test="count($previews/filteredAgentPreview/*[local-name()='agentTaskPreview']/*[local-name()='taskRunPreview']/*[local-name()='outputInfos']) &gt;0 or count(//logic/outputInfo) &gt;0">
  72. <div class="wrapper">
  73. <!-- have to pass the preferences into the template - we switch trees in the call -->
  74. <xsl:variable name="userFormat" select="/root/*[local-name()='biBusHeader']/*[local-name()='userPreferenceVars']/item[./name='format']/value"/>
  75. <xsl:variable name="userLocale" select="/root/preferences/param[@name='contentLocale']"/>
  76. <!-- one 'outputsInfo' for each agent task-->
  77. <hts:script type="text/javascript">
  78. <xsl:for-each select="$previews/filteredAgentPreview/*[local-name()='agentTaskPreview']/*[local-name()='taskRunPreview']/*[local-name()='outputInfos']">
  79. <xsl:call-template name="generateOutputUI">
  80. <xsl:with-param name="displayName" select="../../../display"/>
  81. <xsl:with-param name="format" select="../../../format"/>
  82. <xsl:with-param name="locale" select="../../../locale"/>
  83. <xsl:with-param name="output" select="."/>
  84. <!-- pass the preferences down too -->
  85. <xsl:with-param name="userFormatPreference" select="$userFormat"/>
  86. <xsl:with-param name="userLocalePreference" select="$userLocale"/>
  87. </xsl:call-template>
  88. </xsl:for-each>
  89. <!-- render links too -->
  90. <xsl:for-each select="//logic/outputInfo">
  91. <xsl:call-template name="generateLinkUI">
  92. <xsl:with-param name="output" select="."/>
  93. </xsl:call-template>
  94. </xsl:for-each>
  95. //update the dom when all attachments/links have been added
  96. _THIS_htsLinks.commit('_THIS_linksDivGen');
  97. </hts:script>
  98. <div id="_THIS_linksDivGen"/>
  99. </div>
  100. </xsl:if>
  101. </xsl:template>
  102. <xsl:template name="getAcceptText">
  103. <xsl:param name="input"/>
  104. <xsl:choose>
  105. <xsl:when test="$input/*[local-name()='approveText']=''">
  106. <xts:string id="IDS_FRAG_DEFAULT_APPROVE_TEXT"/>
  107. </xsl:when>
  108. <xsl:otherwise>
  109. <xsl:value-of select="$input/*[local-name()='approveText']"/>
  110. </xsl:otherwise>
  111. </xsl:choose>
  112. </xsl:template>
  113. <xsl:template name="getRejectText">
  114. <xsl:param name="input"/>
  115. <xsl:choose>
  116. <xsl:when test="$input/*[local-name()='rejectText']=''">
  117. <xts:string id="IDS_FRAG_DEFAULT_REJECT_TEXT"/>
  118. </xsl:when>
  119. <xsl:otherwise>
  120. <xsl:value-of select="$input/*[local-name()='rejectText']"/>
  121. </xsl:otherwise>
  122. </xsl:choose>
  123. </xsl:template>
  124. <xsl:template name="generateLinkUI">
  125. <xsl:param name="output"/>
  126. <xsl:call-template name="generateFormatUI">
  127. <xsl:with-param name="output" select="$output"/>
  128. <xsl:with-param name="displayName" select="$output/name"/>
  129. </xsl:call-template>
  130. </xsl:template>
  131. <xsl:template name="generateOutputUI">
  132. <xsl:param name="output"/>
  133. <xsl:param name="displayName"/>
  134. <xsl:param name="format"/>
  135. <xsl:param name="locale"/>
  136. <xsl:param name="userFormatPreference"/>
  137. <xsl:param name="userLocalePreference"/>
  138. <!-- have to find the correct ./outputInfo based on what's there and the preferences - can't just output all of them -->
  139. <xsl:variable name="bestMatchFormat">
  140. <xsl:call-template name="findBestFormat">
  141. <xsl:with-param name="output" select="$output"/>
  142. <xsl:with-param name="formatPreference" select="$userFormatPreference"/>
  143. </xsl:call-template>
  144. </xsl:variable>
  145. <xsl:variable name="bestMatchLocale">
  146. <xsl:call-template name="findBestLocale">
  147. <xsl:with-param name="output" select="$output"/>
  148. <xsl:with-param name="localePreference" select="$userLocalePreference"/>
  149. </xsl:call-template>
  150. </xsl:variable>
  151. <xsl:choose>
  152. <xsl:when test="$output/outputInfo[./format = $format and ./locale = $locale]">
  153. <xsl:call-template name="generateFormatUI">
  154. <xsl:with-param name="output" select="$output/outputInfo[./format = $format and ./locale = $locale]"/>
  155. <xsl:with-param name="displayName" select="$displayName"/>
  156. </xsl:call-template>
  157. </xsl:when>
  158. <xsl:otherwise>
  159. <xsl:call-template name="generateFormatUI">
  160. <xsl:with-param name="output" select="$output/outputInfo[./format = $bestMatchFormat and ./locale = $bestMatchLocale]"/>
  161. <xsl:with-param name="displayName" select="$displayName"/>
  162. </xsl:call-template>
  163. </xsl:otherwise>
  164. </xsl:choose>
  165. </xsl:template>
  166. <!-- template to find the best format -->
  167. <xsl:template name="findBestFormat">
  168. <xsl:param name="output"/>
  169. <xsl:param name="formatPreference"/>
  170. <!-- use the prefered format if it's available !-->
  171. <xsl:choose>
  172. <xsl:when test="$output/outputInfo[./format = $formatPreference]">
  173. <xsl:value-of select="$formatPreference"/>
  174. </xsl:when>
  175. <!-- otherwise we have to pick one of the formats - just make sure it's not MHT or layoutDataXML-->
  176. <xsl:otherwise>
  177. <xsl:value-of select="$output/outputInfo[./format != 'MHT' and ./format!='layoutDataXML'][1]/format"/>
  178. </xsl:otherwise>
  179. </xsl:choose>
  180. </xsl:template>
  181. <!-- template to find best match locale -->
  182. <xsl:template name="findBestLocale">
  183. <xsl:param name="output"/>
  184. <xsl:param name="localePreference"/>
  185. <!-- use the prefered locale if it's available !-->
  186. <xsl:choose>
  187. <xsl:when test="$output/outputInfo[./locale = $localePreference]">
  188. <xsl:value-of select="$localePreference"/>
  189. </xsl:when>
  190. <!-- if we have a variant try to match on language and country only -->
  191. <xsl:when test="substring-after(substring-after($localePreference, '-'),'-') != '' and $output/outputInfo[./locale = concat(substring-before($localePreference, '-'), '-', substring-before(substring-after($localePreference, '-'),'-'))]">
  192. <xsl:value-of select="$output/outputInfo[./locale = concat(substring-before($localePreference, '-'), '-', substring-before(substring-after($localePreference, '-'),'-'))][1]/locale"/>
  193. </xsl:when>
  194. <!-- if we have a country - try to match on language only -->
  195. <xsl:when test="substring-before($localePreference,'-') !='' and $output/outputInfo[./locale = substring-before($localePreference,'-')]">
  196. <xsl:value-of select="$output/outputInfo[./locale = substring-before($localePreference,'-')][1]/locale"/>
  197. </xsl:when>
  198. <!-- try to find a match where the user preference is a subset of the locale generated -->
  199. <xsl:when test="$output/outputInfo[starts-with(./locale,$localePreference)]">
  200. <xsl:value-of select="$output/outputInfo[starts-with(./locale,$localePreference)][1]/locale"/>
  201. </xsl:when>
  202. <!-- can't find a match even on just the language - pick any -->
  203. <xsl:otherwise>
  204. <xsl:value-of select="$output/outputInfo[1]/locale"/>
  205. </xsl:otherwise>
  206. </xsl:choose>
  207. </xsl:template>
  208. <xsl:template name="generateFormatUI">
  209. <xsl:param name="output"/>
  210. <xsl:param name="displayName"/>
  211. <xsl:variable name="id" select="$output/@id"/>
  212. <xsl:variable name="format" select="$output/format"/>
  213. <xsl:variable name="icon">
  214. <xsl:choose>
  215. <xsl:when test="$format = 'HTML'">
  216. <xsl:value-of select="concat('_THIS?frag-resource=/ps/portal/images/', 'icon_result_html.gif', '/THIS_')"/>
  217. </xsl:when>
  218. <xsl:when test="$format = 'singleXLS'">
  219. <xsl:value-of select="concat('_THIS?frag-resource=/ps/portal/images/', 'icon_result_excel_single.gif', '/THIS_')"/>
  220. </xsl:when>
  221. <xsl:when test="$format = 'PDF'">
  222. <xsl:value-of select="concat('_THIS?frag-resource=/ps/portal/images/', 'icon_result_pdf.gif', '/THIS_')"/>
  223. </xsl:when>
  224. <xsl:when test="$format= 'XLS'">
  225. <xsl:value-of select="concat('_THIS?frag-resource=/ps/portal/images/','icon_result_excel.gif', '/THIS_')"/>
  226. </xsl:when>
  227. <xsl:when test="$format = 'XLWA'">
  228. <xsl:value-of select="concat('_THIS?frag-resource=/ps/portal/images/','icon_result_excel_web_arch.gif', '/THIS_')"/>
  229. </xsl:when>
  230. <xsl:when test="$format = 'spreadsheetML'">
  231. <xsl:value-of select="concat('_THIS?frag-resource=/ps/portal/images/','icon_result_excel_2007.gif', '/THIS_')"/>
  232. </xsl:when>
  233. <xsl:when test="$format = 'xlsxData'">
  234. <xsl:value-of select="concat('_THIS?frag-resource=/ps/portal/images/','icon_result_xlsxdata_32.gif', '/THIS_')"/>
  235. </xsl:when>
  236. <xsl:otherwise>
  237. <!-- need to convert the format to lowercase for linux -->
  238. <xsl:variable name="convertedFormat">
  239. <xsl:value-of select="translate( $format, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz' )"/>
  240. </xsl:variable>
  241. <xsl:value-of select="concat('_THIS?frag-resource=/ps/portal/images/','icon_result_', $convertedFormat,'_32.gif', '/THIS_')"/>
  242. </xsl:otherwise>
  243. </xsl:choose>
  244. </xsl:variable>
  245. <xsl:variable name="encDisplayName" select="xtsext:javascriptencode(string($displayName))"/>
  246. var _THIS_entry = new Object();
  247. _THIS_entry.defaultName="<xsl:value-of select="$encDisplayName"/>";
  248. _THIS_entry.key="<xsl:value-of select="$id"/>";
  249. _THIS_entry.objectClass="<xsl:value-of select="$output/objectClass"/>";
  250. <xsl:choose>
  251. <xsl:when test="$output/img">
  252. _THIS_entry.img='<xsl:copy-of select="$output/img"/>';
  253. var _THIS_linkTitle="<xts:string id="IDS_FRAG_LINK" encode="javascript"><xts:param name="displayName"><xsl:value-of select="$encDisplayName"/></xts:param></xts:string>";
  254. </xsl:when>
  255. <xsl:otherwise>
  256. _THIS_entry.img="&lt;img alt=&apos;<xsl:value-of select="$encDisplayName"/>&apos; title=&apos;<xsl:value-of select="$encDisplayName"/>&apos; src=&apos;<xsl:value-of select="$icon"/>&apos;/&gt;";
  257. var _THIS_linkTitle='<xts:string id="IDS_FRAG_ATTACHMENT" encode="javascript"><xts:param name="displayName"><xsl:value-of select="$encDisplayName"/></xts:param></xts:string>';
  258. </xsl:otherwise>
  259. </xsl:choose>
  260. _THIS_entry.linkTitle=_THIS_linkTitle;
  261. _THIS_htsLinks.append(_THIS_entry);
  262. var _THIS_output = new Object();
  263. _THIS_output.id=_THIS_entry.key;
  264. _THIS_output.title=_THIS_entry.defaultName;
  265. _THIS_output.objectClass=_THIS_entry.objectClass;
  266. _THIS_outputDetails.add(_THIS_output.id,_THIS_output);
  267. </xsl:template>
  268. <xsl:template name="getFilteredAgentTaskPreviews">
  269. <xsl:param name="taskLinks" select="/root/input[@name='dep']/queryResponse/*[local-name()='manualTask']/*[local-name()='taskLinksList']/*[local-name()='taskLink']"/>
  270. <xsl:param name="path"/>
  271. <xsl:choose>
  272. <xsl:when test="/root/input[@name='dep']/queryResponse/*[local-name()='manualTask']/*[local-name()='taskLinksList']/*[local-name()='taskLink']/*[local-name()='id'][1]='*'">
  273. <xsl:for-each select="$path/*[local-name()='agentTaskPreview']">
  274. <filteredAgentPreview>
  275. <display>
  276. <xsl:value-of select="./@name"/>
  277. </display>
  278. <xsl:copy-of select="."/>
  279. </filteredAgentPreview>
  280. </xsl:for-each>
  281. </xsl:when>
  282. <xsl:otherwise>
  283. <xsl:for-each select="$taskLinks">
  284. <xsl:variable name="id">
  285. <xsl:value-of select="./*[local-name()='id']"/>
  286. </xsl:variable>
  287. <xsl:if test="$path/*[local-name()='agentTaskPreview'][@targetStoreId=$id or @name=$id]!=''">
  288. <filteredAgentPreview>
  289. <display>
  290. <xsl:value-of select="./*[local-name()='display']"/>
  291. </display>
  292. <format>
  293. <xsl:value-of select="./*[local-name()='format']"/>
  294. </format>
  295. <locale>
  296. <xsl:value-of select="./*[local-name()='locale']"/>
  297. </locale>
  298. <xsl:copy-of select="$path/*[local-name()='agentTaskPreview'][@targetStoreId=$id or @name=$id]"/>
  299. </filteredAgentPreview>
  300. </xsl:if>
  301. </xsl:for-each>
  302. </xsl:otherwise>
  303. </xsl:choose>
  304. </xsl:template>
  305. </xsl:stylesheet>