propedit.xslt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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:xts="http://developer.cognos.com/schemas/xts/"
  15. xmlns:bus="http://developer.cognos.com/schemas/bibus/3/"
  16. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  17. xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  18. xmlns:nav="http://developer.cognos.com/schemas/cps/navigation/1/"
  19. xmlns:pui="http://developer.cognos.com/common/portal/logic/ui/1/"
  20. xmlns:exsl="http://exslt.org/common"
  21. xmlns:layout="http://developer.cognos.com/common/layout"
  22. extension-element-prefixes="exsl"
  23. exclude-result-prefixes="xts bus xtsext SOAP-ENV nav pui exsl layout">
  24. <!--
  25. the following imports requires these variables to be defined:
  26. $metaData, $interactions, $logic, $userPreferences, $navRequest, $navResponse
  27. -->
  28. <xsl:import href="/common/propeditor/types/xsdtypes.xslt"/>
  29. <xsl:import href="/common/propeditor/types/fragextTypes.xslt"/>
  30. <xsl:import href="/common/propeditor/types/cmtypes.xslt"/>
  31. <xsl:import href="/common/propeditor/types/cmmtypes.xslt"/>
  32. <xsl:import href="/common/propeditor/types/generictypes.xslt"/>
  33. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="no"/>
  34. <!--
  35. Variable declarations. The xpath "/*[false()]" provides an empty node set result.
  36. -->
  37. <xsl:variable name="interactions" select="/root/interactions"/>
  38. <xsl:variable name="state" select="/root/state"/>
  39. <xsl:variable name="userPreferences" select="/root/preferences"/>
  40. <xsl:variable name="logic" select="/root/logic"/>
  41. <xsl:variable name="metaData" select="$logic/targetMeta/meta"/>
  42. <xsl:variable name="fragMeta" select="/root/fragment/meta"/>
  43. <xsl:variable name="navRequest" select="/root/input[@name='request']/*/SOAP-ENV:Envelope/SOAP-ENV:Body/nav:request/nav:queries"/>
  44. <xsl:variable name="navResponse" select="/root/input[@name='response']/*/*"/>
  45. <xsl:variable name="config" select="/root/input[@name='configurationResponse']/config"/>
  46. <xsl:key name="env-param" match="/root/interactions/param" use="@name"/>
  47. <layout:selectortemplates/>
  48. <xsl:template match="/">
  49. <xsl:choose>
  50. <xsl:when test="$interactions/param[@name='privateAction' and (.='save' or .='cancel')]">
  51. <script type="text/javascript">_THIS_.setOnloadHandler( function() { window.setTimeout("_THIS_.setMode('view')", 1); } );</script>
  52. </xsl:when>
  53. <xsl:otherwise>
  54. <xsl:call-template name="generateMarkupForFullPage"/>
  55. </xsl:otherwise>
  56. </xsl:choose>
  57. </xsl:template>
  58. <xsl:template name="generateMarkupForFullPage">
  59. <!-- generate global variables -->
  60. <layout:script>
  61. var _THIS_dependencyCleanup = new Array();
  62. var _THIS_validationFunctionArray = new Array();
  63. _THIS_validationFunctionArray.form = "_THIS_form";
  64. _THIS_validationFunctionArray.multiLingualSelector = "Selector";
  65. _THIS_validationFunctionArray.localFormName = "form";
  66. var _THIS_defaultPickerAction = "_THIS?frag-urlType=gateway/THIS_";
  67. </layout:script>
  68. <pui:aboutscript/>
  69. <pui:delegatehelpscript/>
  70. <layout:form name="_THIS_form" id="_THIS_form" action="_THIS?/THIS_" method="post">
  71. <layout:hidden name="privateAction" value=""/>
  72. <layout:section format="header">
  73. <layout:text>
  74. <xsl:choose>
  75. <xsl:when test="$fragMeta/description"><xsl:value-of select="$fragMeta/description"/></xsl:when>
  76. <xsl:otherwise><xts:string id="IDS_PROP_GENERICEDITOR_INTRO"/></xsl:otherwise>
  77. </xsl:choose>
  78. </layout:text>
  79. <layout:actionlist>
  80. <layout:action>
  81. <pui:aboutlink/>
  82. </layout:action>
  83. <layout:action>
  84. <pui:helplink/>
  85. </layout:action>
  86. </layout:actionlist>
  87. </layout:section>
  88. <!-- first itterate over all the properties and see if they want to add soemthing to the top of the page -->
  89. <layout:section id="_THIS_header">
  90. <layout:row>
  91. <xsl:apply-templates select="$metaData/customProperties" mode="markup-header"/>
  92. </layout:row>
  93. </layout:section>
  94. <layout:section id="_THIS_properties">
  95. <xsl:for-each select="$metaData/customProperties[control/group]">
  96. <xsl:sort select="control/group/@order"/>
  97. <xsl:variable name="propname" select="@name"/>
  98. <xsl:variable name="name" select="string(./control/group)"/>
  99. <xsl:if test="not(preceding-sibling::*[string(control/group) = $name])">
  100. <xsl:if test="$name !=''">
  101. <layout:label divider="true">
  102. <layout:text>
  103. <xsl:value-of select="$name"/>
  104. </layout:text>
  105. </layout:label>
  106. </xsl:if>
  107. <xsl:for-each select="$metaData/customProperties[control/group = $name and string(control/@order)!='']">
  108. <xsl:sort select="number(control/@order)" data-type="number" order="ascending"/>
  109. <layout:section>
  110. <xsl:apply-templates select="." mode="markup">
  111. <xsl:with-param name="propSiblings" select="$metaData/customProperties[not(@name=$propname)]"/>
  112. </xsl:apply-templates>
  113. </layout:section>
  114. </xsl:for-each>
  115. <xsl:for-each select="$metaData/customProperties[control/group = $name and string(control/@order)='']">
  116. <layout:section>
  117. <xsl:apply-templates select="." mode="markup">
  118. <xsl:with-param name="propSiblings" select="$metaData/customProperties[not(@name=$propname)]"/>
  119. </xsl:apply-templates>
  120. </layout:section>
  121. </xsl:for-each>
  122. </xsl:if>
  123. </xsl:for-each>
  124. <xsl:choose>
  125. <xsl:when test="$metaData/customProperties[control/@relatesTo]"/>
  126. <xsl:otherwise>
  127. <xsl:if test="($metaData/customProperties[not(control/group) and control/@order]) or ($metaData/customProperties[not(control/group) and not(control/@order)])">
  128. <layout:section divider="true">
  129. <xsl:for-each select="$metaData/customProperties[not(control/group) and control/@order]">
  130. <xsl:sort select="control/@order"/>
  131. <xsl:variable name="propname" select="@name"/>
  132. <xsl:apply-templates select="." mode="markup" >
  133. <xsl:with-param name="propSiblings" select="$metaData/customProperties[not(@name=$propname)]"/>
  134. </xsl:apply-templates>
  135. </xsl:for-each>
  136. <xsl:for-each select="$metaData/customProperties[not(control/group) and not(control/@order)]">
  137. <xsl:variable name="propname" select="@name"/>
  138. <xsl:apply-templates select="." mode="markup">
  139. <xsl:with-param name="propSiblings" select="$metaData/customProperties[not(@name=$propname)]"/>
  140. </xsl:apply-templates>
  141. </xsl:for-each>
  142. </layout:section>
  143. </xsl:if>
  144. </xsl:otherwise>
  145. </xsl:choose>
  146. </layout:section>
  147. <!--render the button bar -->
  148. <layout:section format="footer" divider="true" id="_THIS_footer">
  149. <layout:row>
  150. <layout:button id="_THIS_okButton" onclick="_THIS_okClicked();">
  151. <layout:value><xts:string id="IDS_PROP_OK_BUTTON_TEXT"/></layout:value>
  152. </layout:button>
  153. <layout:button onclick="_THIS_cancelClicked();">
  154. <layout:value><xts:string id="IDS_PROP_CANCEL_BUTTON_TEXT"/></layout:value>
  155. </layout:button>
  156. </layout:row>
  157. </layout:section>
  158. </layout:form>
  159. <xsl:call-template name="generateScript"/>
  160. </xsl:template>
  161. <xsl:template match="customProperties" mode="markup">
  162. <xsl:param name="propSiblings"/>
  163. <xsl:param name="matchControlId" select="''"/>
  164. <xsl:variable name="usePCI">
  165. <xsl:choose>
  166. <xsl:when test="$matchControlId='' and string(./control/@relatesTo)!=''">
  167. <xsl:value-of select="concat('_',./control/@relatesTo)"/>
  168. </xsl:when>
  169. <xsl:otherwise>
  170. <xsl:value-of select="$matchControlId"/>
  171. </xsl:otherwise>
  172. </xsl:choose>
  173. </xsl:variable>
  174. <xsl:variable name="propname" select="@name"/>
  175. <xsl:variable name="prefix" select="substring-before(datatype, ':')"/>
  176. <xsl:variable name="type" select="substring-after(datatype, ':')"/>
  177. <xsl:variable name="namespaceSpecificCustomProps">
  178. <xsl:element name="{$prefix}:{$type}" namespace="{datatype/namespace::*[name() = $prefix]}">
  179. <xsl:copy-of select="self::node()"/>
  180. </xsl:element>
  181. </xsl:variable>
  182. <xsl:if test="$type = 'multilingualString' and count(preceding-sibling::*[local-name()='customProperties']/*[local-name()='datatype' and contains(string(.),$type)])=0">
  183. <xsl:apply-templates select="$namespaceSpecificCustomProps/*" mode="selector">
  184. <xsl:with-param name="propSiblings" select="$propSiblings"/>
  185. <xsl:with-param name="matchControlId" select="$usePCI"/>
  186. </xsl:apply-templates>
  187. </xsl:if>
  188. <xsl:apply-templates select="$namespaceSpecificCustomProps/*">
  189. <xsl:with-param name="propSiblings" select="$propSiblings"/>
  190. <xsl:with-param name="matchControlId" select="$usePCI"/>
  191. </xsl:apply-templates>
  192. </xsl:template>
  193. <xsl:template match="customProperties" mode="markup-scripting">
  194. <xsl:variable name="prefix" select="substring-before(datatype, ':')"/>
  195. <xsl:variable name="type" select="substring-after(datatype, ':')"/>
  196. <xsl:variable name="namespaceSpecificCustomProps">
  197. <xsl:element name="{$prefix}:{$type}" namespace="{datatype/namespace::*[name() = $prefix]}">
  198. <xsl:copy-of select="self::node()"/>
  199. </xsl:element>
  200. </xsl:variable>
  201. <xsl:apply-templates select="$namespaceSpecificCustomProps/*" mode="scripting"/>
  202. </xsl:template>
  203. <xsl:template match="customProperties" mode="markup-header">
  204. <xsl:variable name="prefix" select="substring-before(datatype, ':')"/>
  205. <xsl:variable name="type" select="substring-after(datatype, ':')"/>
  206. <xsl:variable name="namespaceSpecificCustomProps">
  207. <xsl:element name="{$prefix}:{$type}" namespace="{datatype/namespace::*[name() = $prefix]}">
  208. <xsl:copy-of select="self::node()"/>
  209. </xsl:element>
  210. </xsl:variable>
  211. <xsl:apply-templates select="$namespaceSpecificCustomProps/*" mode="header"/>
  212. </xsl:template>
  213. <!-- used in markup mode only -->
  214. <xsl:template name="getPropertyValue">
  215. <xsl:param name="propertyName"/>
  216. <xsl:variable name="formProp" select="concat('p_',$propertyName)"/>
  217. <xsl:choose>
  218. <xsl:when test="$interactions/param[@name= $formProp]">
  219. <xsl:value-of select="$interactions/param[@name= $formProp]"/>
  220. </xsl:when>
  221. <xsl:when test="$interactions/param[@name= $propertyName]">
  222. <xsl:value-of select="$interactions/param[@name= $propertyName]"/>
  223. </xsl:when>
  224. <xsl:otherwise>
  225. <xsl:value-of select="default/value"/>
  226. </xsl:otherwise>
  227. </xsl:choose>
  228. </xsl:template>
  229. <!-- used in markup mode only -->
  230. <xsl:template name="createLanguageSelector">
  231. <xsl:param name="name"/>
  232. <xsl:param name="fieldList"/>
  233. <layout:localeselectorcontrol name="Selector">
  234. <layout:config><xsl:copy-of select="$config/param[@name='contentLocales']/*"/></layout:config>
  235. <layout:label>
  236. <layout:text><xts:string id="IDS_PROP_LANGUAGE_CAPTION"/></layout:text>
  237. </layout:label>
  238. <layout:controlparameters>
  239. <formname>form</formname>
  240. <contentlocales><xsl:copy-of select="$config/param[@name='contentLocales']/*"/></contentlocales>
  241. <customs>
  242. <xsl:variable name="fields" select="substring($fieldList,0,string-length($fieldList) )"/>
  243. <!-- render all the languages for which there are value for above the line -->
  244. <xsl:copy-of select="$state/param[contains($fields, @name)]"/>
  245. </customs>
  246. <fieldlist><xsl:value-of select="substring($fieldList,0,string-length($fieldList) )"/></fieldlist>
  247. <preferences>
  248. <xsl:copy-of select="$userPreferences/*"/>
  249. </preferences>
  250. </layout:controlparameters>
  251. </layout:localeselectorcontrol>
  252. </xsl:template>
  253. <xsl:template name="generateScript">
  254. <layout:script>
  255. var _THIS_currentForm="_THIS_form";
  256. function _THIS_refreshEdit(evt)
  257. {
  258. if(evt.eventPhase == evt.AT_TARGET)
  259. {
  260. checkToRefresh("_THIS_form",evt,"<xts:string id="IDS_PROP_REFRESH_LANGUAGE_MSG" encode="javascript"/>");
  261. }
  262. }
  263. _THIS_.addEventListener("fragment.refresh","_THIS_refreshEdit",false);
  264. function _THIS_getValue(formElement)
  265. {
  266. return formElement.value;
  267. }
  268. function _THIS_cancelClicked(){
  269. document._THIS_form.reset();
  270. document._THIS_form.privateAction.value='cancel';
  271. document._THIS_form.submit();
  272. }
  273. function _THIS_okClicked()
  274. {
  275. if (_THIS_validateFields())
  276. {
  277. document._THIS_form.privateAction.value='save';
  278. document._THIS_form.submit();
  279. document._THIS_form._THIS_okButton.disabled=true;
  280. }
  281. }
  282. function _THIS_validateFields()
  283. {
  284. for(var index=0;index &lt; _THIS_validationFunctionArray.length;index++)
  285. {
  286. if ( !_THIS_validationFunctionArray[index].validateFunction(_THIS_validationFunctionArray[index].propertyName, _THIS_validationFunctionArray[index].inputName))
  287. return false;
  288. }
  289. return true;
  290. }
  291. function _THIS_multiLingualGenericEditValidate(propertyName)
  292. {
  293. var cForm = document.forms[_THIS_validationFunctionArray.form];
  294. var res = validateMultiLingualProperty(_THIS_validationFunctionArray.multiLingualSelector, propertyName, _THIS_validationFunctionArray.localFormName, "_THIS_", _THIS_, _THIS_validationFunctionArray.multiLingualItemList);
  295. if (res == CValidator.RES_VALID)
  296. {
  297. return true;
  298. }
  299. else
  300. {
  301. var entryEl = document.getElementById("_THIS_" + propertyName);
  302. alert(entryEl.getAttribute("valerr:message"));
  303. entryEl.focus();
  304. return false;
  305. }
  306. }
  307. function _THIS_genericEditValidate(propertyName, inputName)
  308. {
  309. var cForm = document.forms[_THIS_validationFunctionArray.form];
  310. var el = cForm.elements[inputName];
  311. var valErr = _THIS_.validate(propertyName, el.value);
  312. var message = "";
  313. if (valErr ==CValidator.RES_VALID)
  314. return true;
  315. switch(valErr)
  316. {
  317. case CValidator.RES_NUMERIC_NAN:
  318. message = "<xts:string id='IDS_GEN_CLIENT_VALIDATION_ERROR_INVALID_NUMBER' encode='javascript'/>";
  319. break;
  320. case CValidator.RES_NUMERIC_MIN:
  321. message = "<xts:string id='IDS_GEN_CLIENT_VALIDATION_ERROR_NUMBER_MIN' encode='javascript'/>";
  322. break;
  323. case CValidator.RES_NUMERIC_MAX:
  324. message = "<xts:string id='IDS_GEN_CLIENT_VALIDATION_ERROR_NUMBER_MAX' encode='javascript'/>";
  325. break;
  326. case CValidator.RES_TYPE_INT:
  327. message = "<xts:string id='IDS_GEN_CLIENT_VALIDATION_ERROR_NUMBER_INT' encode='javascript'/>";
  328. break;
  329. case CValidator.RES_TYPE_LONG:
  330. message = "<xts:string id='IDS_GEN_CLIENT_VALIDATION_ERROR_NUMBER_LONG' encode='javascript'/>";
  331. break;
  332. case CValidator.RES_TYPE_UNSIGNED_INT:
  333. message = "<xts:string id='IDS_GEN_CLIENT_VALIDATION_ERROR_NUMBER_UNSIGNEDINT' encode='javascript'/>";
  334. break;
  335. case CValidator.RES_INTEGRAL:
  336. message = "<xts:string id='IDS_GEN_CLIENT_VALIDATION_ERROR_NUMBER_INTEGRAL' encode='javascript'/>";
  337. break;
  338. default:
  339. message =el.getAttribute("valerr:message");
  340. break;
  341. }
  342. alert(message);
  343. el.focus();
  344. return false;
  345. }
  346. function _THIS_isValidURL(url, mandatory)
  347. {
  348. if (url.length == 0 &amp;&amp; mandatory == false) {
  349. // a blank is fine only if the option is not selected
  350. return true;
  351. }
  352. var sep = url.indexOf("//");
  353. var protocol = url.substring(0, sep).toLowerCase();
  354. var badChars = false;
  355. for (i = 0; i &lt; url.length; i++)
  356. {
  357. var n = url.charCodeAt(i);
  358. if ( n &lt;= 32 || n > 127 )
  359. {
  360. badChars = true;
  361. break;
  362. }
  363. }
  364. return ( ( (protocol == "http:") || (protocol == "https:") ) &amp;&amp; (!badChars) &amp;&amp; (url.length > sep + 2) );
  365. }
  366. <xsl:apply-templates select="$metaData/customProperties" mode="markup-scripting"/>
  367. </layout:script>
  368. </xsl:template>
  369. <xsl:template name="relatedControl">
  370. <xsl:param name="relControlCustomProperties"/>
  371. <xsl:param name="propSiblings" select="/*[false()]"/>
  372. <xsl:param name="matchControlId" select="''"/>
  373. <!-- render layout of ordered customProperties followed by any non-ordered ones -->
  374. <xsl:for-each select="$relControlCustomProperties[control/@order]">
  375. <xsl:sort select="number(./control/@order)" data-type="number" order="ascending"/>
  376. <xsl:apply-templates select="." mode="markup">
  377. <xsl:with-param name="propSiblings" select="$propSiblings"/>
  378. <xsl:with-param name="matchControlId" select="$matchControlId"/>
  379. </xsl:apply-templates>
  380. </xsl:for-each>
  381. <xsl:if test="$relControlCustomProperties[not(control/@order)]">
  382. <xsl:apply-templates select="$relControlCustomProperties[not(control/@order)]" mode="markup">
  383. <xsl:with-param name="propSiblings" select="$propSiblings"/>
  384. <xsl:with-param name="matchControlId" select="$matchControlId"/>
  385. </xsl:apply-templates>
  386. </xsl:if>
  387. </xsl:template>
  388. <xsl:template name="keyScript">
  389. <xsl:param name="matchControl" select="''"/>
  390. <xsl:param name="resetControl" select="''"/>
  391. <xsl:param name="setControl" select="''"/>
  392. <xsl:param name="currentControl" select="''"/>
  393. <xsl:if test="$matchControl != '' or $resetControl != '' or $setControl != ''">
  394. <xsl:text>javascript:if(event.keyCode==9)return true;</xsl:text>
  395. </xsl:if>
  396. <xsl:if test="$matchControl != ''">
  397. <xsl:if test="$currentControl != ''">
  398. <xsl:text>if(document.getElementById("_THIS_</xsl:text>
  399. <xsl:value-of select="xtsext:javascriptencode(string($currentControl))"/>
  400. <xsl:text>").checked==true)</xsl:text>
  401. </xsl:if>
  402. <xsl:text>document.getElementById("_THIS_</xsl:text>
  403. <xsl:value-of select="xtsext:javascriptencode(string($matchControl))"/>
  404. <xsl:text>").checked=true;</xsl:text>
  405. </xsl:if>
  406. <xsl:if test="$setControl!='' and $setControl=$resetControl">
  407. <xsl:variable name="setencoded" select="xtsext:javascriptencode($setControl)"/>
  408. <xsl:text>if(!document.getElementById("_THIS_p_</xsl:text>
  409. <xsl:value-of select="$setencoded"/>
  410. <xsl:text>") || document.getElementById("_THIS_p_</xsl:text>
  411. <xsl:value-of select="$setencoded"/>
  412. <xsl:text>").value=="")_THIS_chooseSelection(_THIS_control</xsl:text>
  413. <xsl:value-of select="$setencoded"/>
  414. <xsl:text>);</xsl:text>
  415. </xsl:if>
  416. <xsl:if test="$resetControl!='' and $setControl != $resetControl">
  417. <xsl:variable name="resetencoded" select="xtsext:javascriptencode($resetControl)"/>
  418. <xsl:text>if(document.getElementById("_THIS_p_</xsl:text>
  419. <xsl:value-of select="$resetencoded"/>
  420. <xsl:text>"))_THIS_clearSelection(_THIS_control</xsl:text>
  421. <xsl:value-of select="$resetencoded"/>
  422. <xsl:text>);</xsl:text>
  423. </xsl:if>
  424. </xsl:template>
  425. </xsl:stylesheet>
  426. <!-- $Header: //cpscrn/main/src/java/etc/webapps/cps/WEB-INF/fragments/producers/common/propeditor/propedit.xslt#1 $ -->
  427. <!-- $DateTime: 2008/10/22 11:12:04 $ -->
  428. <!-- $Change: 25109 $ -->