picker.xslt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. This stylesheet uses the following global variables:
  12. $interactions
  13. $metaData
  14. -->
  15. <xsl:stylesheet version="1.0"
  16. xmlns:layout="http://developer.cognos.com/common/layout"
  17. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  18. xmlns:nav="http://developer.cognos.com/schemas/cps/navigation/1/"
  19. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  20. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  21. xmlns:cmobj="http://developer.cognos.com/fragments/extensions/cm/1/"
  22. xmlns:pick="http://developer.cognos.com/fragments/extensions/picker/1/"
  23. xmlns:val="http://developer.cognos.com/schemas/validator/1/">
  24. <xsl:template name="generateSelectorControl">
  25. <xsl:param name="hasResponse" select="false()"/>
  26. <xsl:param name="propName"/>
  27. <xsl:param name="propValue"/>
  28. <xsl:param name="displayField"/>
  29. <xsl:param name="matchControlId" select="''"/>
  30. <layout:section format="select-dialog">
  31. <xsl:choose>
  32. <xsl:when test="$hasResponse = true()">
  33. <xsl:copy-of select="$displayField"/>
  34. </xsl:when>
  35. <xsl:otherwise>
  36. <layout:row format="select">
  37. <layout:text><xts:string id="IDS_PROP_OBJECT_NONE"/></layout:text>
  38. </layout:row>
  39. </xsl:otherwise>
  40. </xsl:choose>
  41. <layout:row>
  42. <layout:link href="javascript:_F_Config.emptyFunction()" onclick="_THIS_chooseSelection(_THIS_control{$propName});return false;"><xts:string id="IDS_PROP_OBJECT_SELECT_CAPTION"/></layout:link>
  43. <xsl:if test="$hasResponse = true()">
  44. <layout:link href="javascript:_F_Config.emptyFunction()" onclick="_THIS_clearSelection(_THIS_control{$propName});return false;"><xts:string id="IDS_PROP_OBJECT_RESET_CAPTION"/></layout:link>
  45. </xsl:if>
  46. </layout:row>
  47. </layout:section>
  48. <layout:script>
  49. var _THIS_control<xsl:value-of select="$propName"/> =
  50. {
  51. name: "<xsl:value-of select="$propName"/>",
  52. hasresponse: <xsl:value-of select="string($hasResponse=true())"/>,
  53. controlset: "<xsl:if test="$matchControlId != ''">_THIS_<xsl:value-of select="$matchControlId"/></xsl:if>",
  54. controlreset: "<xsl:if test="string(control/@resetsTo) != ''">_THIS__<xsl:value-of select="control/@resetsTo"/></xsl:if>",
  55. selectionParams: new Array()
  56. };
  57. with(_THIS_control<xsl:value-of select="$propName"/>.selectionParams)
  58. {&#10;<xsl:text/>
  59. <xsl:text>var temp = new Object().href="_THIS?frag-urlType=gatewayproxy/THIS_";push({name: "so.return.gateway", value: temp});</xsl:text>
  60. <xsl:text>push({name: "so.return.domain", value: document.domain});</xsl:text>
  61. <xsl:text>push({name: "so.return.m", value: "/fragments/common/dialog/callback.xts"});</xsl:text>
  62. <xsl:text>push({name: "so.return.b_action", value: "xts.run"});</xsl:text>
  63. <xsl:text>push({name: "md.displayOptions", value: "h1"});</xsl:text>
  64. <xsl:for-each select="control/extension/*/pick:picker/pick:param">
  65. <xsl:text>&#9;push({name: "</xsl:text>
  66. <xsl:value-of select="xtsext:javascriptencode(@name)"/>
  67. <xsl:text>", value: "</xsl:text>
  68. <xsl:choose>
  69. <xsl:when test="not(pick:custom)">
  70. <xsl:value-of select="xtsext:javascriptencode(.)"/>
  71. </xsl:when>
  72. <xsl:otherwise>
  73. <xsl:variable name="custParamName" select="pick:custom/@name"/>
  74. <xsl:variable name="actualValue">
  75. <xsl:choose>
  76. <xsl:when test="$interactions/param[@name = concat('p_',$custParamName)]">
  77. <xsl:value-of select="$interactions/param[@name = concat('p_',$custParamName)]"/>
  78. </xsl:when>
  79. <xsl:when test="$interactions/param[@name = $custParamName]">
  80. <xsl:value-of select="$interactions/param[@name = $custParamName]"/>
  81. </xsl:when>
  82. <xsl:when test="starts-with($metaData/customProperties[@name = $custParamName]/default/value,'path:')">
  83. <xsl:value-of select="substring-after($metaData/customProperties[@name = $custParamName]/default/value,'path:')"/>
  84. </xsl:when>
  85. <xsl:otherwise>
  86. <xsl:value-of select="$metaData/customProperties[@name = $custParamName]/default/value"/>
  87. </xsl:otherwise>
  88. </xsl:choose>
  89. </xsl:variable>
  90. <xsl:value-of select="xtsext:javascriptencode($actualValue)"/>
  91. <xsl:text>", type: "custom", customName: "</xsl:text>
  92. <xsl:value-of select="xtsext:javascriptencode($custParamName)"/>
  93. </xsl:otherwise>
  94. </xsl:choose>
  95. <xsl:text>"});&#10;</xsl:text>
  96. </xsl:for-each>
  97. <xsl:text>}&#10;_THIS_control</xsl:text>
  98. <xsl:value-of select="$propName"/>
  99. <xsl:text>.selectionParams.defaultStartLocations = new Array();&#10;</xsl:text>
  100. <xsl:for-each select="control/extension/*/pick:picker/pick:defaultStartLocation">
  101. <xsl:text>_THIS_control</xsl:text>
  102. <xsl:value-of select="$propName"/>
  103. <xsl:text>.selectionParams.defaultStartLocations.push("</xsl:text>
  104. <xsl:value-of select="xtsext:javascriptencode(.)"/>
  105. <xsl:text>");&#10;</xsl:text>
  106. </xsl:for-each>
  107. <xsl:text>_THIS_control</xsl:text>
  108. <xsl:value-of select="$propName"/>
  109. <xsl:text>.selectionParams.xPathToResponse = "</xsl:text>
  110. <xsl:value-of select="xtsext:javascriptencode(control/extension/*/pick:picker/pick:xPathToResponse)"/>
  111. <xsl:text>";&#10;</xsl:text>
  112. </layout:script>
  113. </xsl:template>
  114. <xsl:template name="generateCleanupItems">
  115. <xsl:param name="propName"/>
  116. <xsl:param name="dependentItems"/>
  117. <xsl:text>_THIS_dependencyCleanup["</xsl:text>
  118. <xsl:value-of select="xtsext:javascriptencode($propName)"/>
  119. <xsl:text>"] = new Array();&#10;with(_THIS_dependencyCleanup["</xsl:text>
  120. <xsl:value-of select="xtsext:javascriptencode($propName)"/>
  121. <xsl:text>"])&#10;{&#10;</xsl:text>
  122. <xsl:for-each select="$dependentItems">
  123. <xsl:text>push("</xsl:text>
  124. <xsl:value-of select="xtsext:javascriptencode(parent::*/parent::*/parent::*/parent::*/@name)"/>
  125. <xsl:text>");&#10;</xsl:text>
  126. </xsl:for-each>
  127. <xsl:text>&#10;}&#10;</xsl:text>
  128. </xsl:template>
  129. <xsl:template name="generatePickerScripts">
  130. var ccModalCallBack;
  131. var _THIS_currentCallbackResultPath;
  132. var _THIS_currentControl = null;
  133. function _THIS_reloadAfterSelectObject(response)
  134. {
  135. response = xmldecode(response);
  136. var form = _F_Form.find(_THIS_currentForm);
  137. var xml = new XMLBuilderLoadXMLFromString(response);
  138. if (form !== undefined &amp;&amp; xml &amp;&amp; _THIS_currentForm != "" &amp;&amp; _THIS_currentControl)
  139. {
  140. var idNode = _F_DOM.selectSingleNode(xml, _THIS_currentCallbackResultPath);
  141. var id = _F_DOM.text(idNode);
  142. form["p_" + _THIS_currentControl.name].value = id;
  143. _THIS_resetDependents(form, _THIS_currentControl);
  144. _THIS_.addEventListener("fragment.retrieve.after","_THIS_closeSelectDialogEvent",false);
  145. form.submit();
  146. }
  147. else
  148. {
  149. window.alert("BUG: no response or missing parameters");
  150. }
  151. }
  152. function _THIS_closeSelectDialog()
  153. {
  154. _THIS_modalDialog.destroy();
  155. _THIS_modalDialog = null;
  156. }
  157. function _THIS_closeSelectDialogEvent(evt)
  158. {
  159. if(evt.eventPhase == evt.AT_TARGET)
  160. {
  161. _THIS_closeSelectDialog();
  162. _THIS_.removeEventListener("fragment.retrieve.after","_THIS_closeSelectDialogEvent",false);
  163. }
  164. }
  165. function _THIS_clearSelection(ctrl)
  166. {
  167. var form = _F_Form.find(_THIS_currentForm);
  168. if (form !== undefined)
  169. {
  170. if (_THIS_validateFields())
  171. {
  172. _THIS_clearObject(form, ctrl);
  173. form.submit();
  174. }
  175. }
  176. else
  177. {
  178. window.alert("BUG: no response or missing parameters");
  179. }
  180. }
  181. function _THIS_clearObject(form, ctrl)
  182. {
  183. form["p_" + ctrl.name].value = "";
  184. if (ctrl &amp;&amp; ctrl.controlreset != '')
  185. {
  186. var ctrlset = $(ctrl.controlset);
  187. if (ctrlset &amp;&amp; ctrlset.checked)
  188. {
  189. var ctrlreset = $(ctrl.controlreset);
  190. if (ctrlreset &amp;&amp; ctrl.controlset != ctrl.controlreset)
  191. ctrlreset.checked=true;
  192. else
  193. ctrlset.checked=false;
  194. }
  195. }
  196. _THIS_resetDependents(form, ctrl);
  197. }
  198. function _THIS_resetDependents(form, ctrl)
  199. {
  200. if (_THIS_dependencyCleanup !== undefined &amp;&amp; _THIS_dependencyCleanup[ctrl.name] != null)
  201. {
  202. var deps = _THIS_dependencyCleanup[ctrl.name];
  203. for (var index=0;index &lt; deps.length;index++)
  204. {
  205. var ctrl = window["_THIS_control" + deps[index]];
  206. _THIS_clearObject(form, ctrl);
  207. }
  208. }
  209. }
  210. function _THIS_ccModalCallBack(cmd,sResponse)
  211. {
  212. var save = (cmd == 'ok' &amp;&amp; sResponse);
  213. if(_THIS_currentControl) {
  214. if(_THIS_currentControl.controlset != "") {
  215. if (save) {
  216. $(_THIS_currentControl.controlset).checked = true;
  217. } else if (_THIS_currentControl.hasresponse != true &amp;&amp;
  218. _THIS_currentControl.controlreset != "" &amp;&amp;
  219. $(_THIS_currentControl.controlset).checked) {
  220. $(_THIS_currentControl.controlreset).checked = true;
  221. }
  222. }
  223. }
  224. if (save) {
  225. _THIS_reloadAfterSelectObject(sResponse);
  226. }else {
  227. setTimeout('_THIS_closeSelectDialog()', 1);
  228. }
  229. return;
  230. }
  231. function _THIS_chooseSelection(ctrl){
  232. if (_THIS_validateFields())
  233. {
  234. if (_THIS_modalDialog != null)
  235. {
  236. _THIS_modalDialog.destroy();
  237. _THIS_modalDialog = null;
  238. }
  239. _THIS_validatedChooseSelection(ctrl);
  240. }
  241. }
  242. function _THIS_validatedChooseSelection(ctrl)
  243. {
  244. _THIS_currentControl = ctrl;
  245. var pickerParamsArray = _THIS_currentControl.selectionParams;
  246. var pickerFormAction = _THIS_currentControl.pickerFormAction;
  247. if ( !pickerFormAction ){
  248. pickerFormAction = _THIS_defaultPickerAction;
  249. var additionalQuery = null;
  250. var queryIndex = pickerFormAction.indexOf('?');
  251. if (queryIndex != -1){
  252. additionalQuery = pickerFormAction.substring(queryIndex + 1);
  253. var currentPickerForm = getPickerForm("_THIS_pickerForm");
  254. pickerFormAction = pickerFormAction.substring(0,queryIndex);
  255. }
  256. _THIS_currentControl.pickerFormAction = pickerFormAction;
  257. if (additionalQuery != null){
  258. var params = additionalQuery.split('&amp;');
  259. for (var i = 0; i&lt; params.length; ++i)
  260. {
  261. var param = params[i];
  262. if (param.length > 0)
  263. {
  264. var eq_index = param.indexOf("=");
  265. var additionalParam = new Object();
  266. additionalParam.type="";
  267. if (eq_index != -1)
  268. {
  269. additionalParam.name = decodeURIComponent(param.substring(0, eq_index));
  270. additionalParam.value = decodeURIComponent(param.substring(eq_index + 1));
  271. }
  272. else
  273. {
  274. additionalParam.name = decodeURIComponent(param);
  275. additionalParam.value = "";
  276. }
  277. pickerParamsArray.push(additionalParam);
  278. }
  279. }
  280. }
  281. }
  282. recreatePickerForm("_THIS_pickerForm", pickerFormAction);
  283. var currentPickerForm = getPickerForm("_THIS_pickerForm");
  284. //now update the form with the correct elements
  285. for (var index=0; index &lt; pickerParamsArray.length; index++)
  286. {
  287. <!--
  288. // Ignore the md.callBack and md.backURL parameters, we will use return url to communicate with the caller
  289. // javascript callback will not work because in 3rd party portal the caller is in a different domain
  290. -->
  291. if ("md.callBack" == pickerParamsArray[index].name || "md.backURL" == pickerParamsArray[index].name )
  292. continue;
  293. var value = pickerParamsArray[index].value;
  294. //if it is custom then we should update the value based on the most current value for that property
  295. if (pickerParamsArray[index].type == "custom")
  296. {
  297. var custEl = $("_THIS_p_" + pickerParamsArray[index].customName);
  298. if (custEl != null)
  299. {
  300. value = getValueFromSimpleElement(custEl);
  301. createPickerInput(currentPickerForm,"picker_" + index, pickerParamsArray[index].name, value);
  302. }
  303. else if (!getSelectElements(pickerParamsArray[index].name, pickerParamsArray[index].customName, currentPickerForm))
  304. {
  305. if (!getSelect1Elements(pickerParamsArray[index].name, pickerParamsArray[index].customName, currentPickerForm)){
  306. getMultiLingualElements(pickerParamsArray[index].name, pickerParamsArray[index].customName, currentPickerForm, $("_THIS_Selector"), $("_THIS_" + pickerParamsArray[index].customName));
  307. }
  308. }
  309. }
  310. else
  311. {
  312. createPickerInput(currentPickerForm, "picker_" + index, pickerParamsArray[index].name, value);
  313. }
  314. }
  315. ccModalCallBack = _THIS_ccModalCallBack;
  316. _THIS_currentCallbackResultPath = pickerParamsArray.xPathToResponse;
  317. var iframeStaticHeight = parseInt(xClientHeight() * .75);
  318. var iframeStaticWidth = parseInt(xClientWidth() * .75);
  319. //open the dialog to an empty url and submit the form as the form is targeted to the modal dialog
  320. var url = "about:blank";
  321. if (_THIS_modalDialog == null)
  322. {
  323. _THIS_modalDialog = new ui_dialog("_THIS_modalDialogViewer", '<xts:string id="IDS_GEN_SELECTION_TITLE" encode="javascript"/>', ui_dialog.style.BTN_NOBUTTONS | ui_dialog.style.CENTER | ui_dialog.style.IFRAME, -1, -1, iframeStaticWidth, iframeStaticHeight, _THIS_.div, url);
  324. }
  325. _THIS_modalDialog.show();
  326. currentPickerForm.target = _THIS_modalDialog.iframeName;
  327. currentPickerForm.submit();
  328. }
  329. if (window._THIS_modalDialog === undefined){
  330. var _THIS_modalDialog = null;
  331. var _THIS_currentPickControl = null;
  332. }
  333. </xsl:template>
  334. </xsl:stylesheet>
  335. <!-- $Header$ -->
  336. <!-- $DateTime$ -->
  337. <!-- $Change$ -->