calcNumericAdvanced.xts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. BI and PM: qs
  5. (C) Copyright IBM Corp. 2001, 2017
  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. <!--
  13. Used for power, square root, absolute, round, round down
  14. -->
  15. <xts:morphlet resolverBase="prompting" version="1.0" xmlns:xts="http://developer.cognos.com/schemas/xts/" messageBase="messages/QSRVUITextPL.xml,messages/portal.xml,messages/portalRL.xml" requiredCapability="canUseQueryStudio">
  16. <xts:block id="browserDetection" path="qs/browserDetection.xslt" mode="interpret" type="exec" processor="XSLT" contentId="browserDetection" partId="1"/>
  17. <xts:block id="page" type="exec" mode="output" processor="XSLT" mimeType="text/html" dependency="browserDetection">
  18. <!-- get the debug logic sheet -->
  19. <xts:logicsheet path="logicsheets/debuglogic.xslt"/>
  20. <!-- get the new theme stuff -->
  21. <!-- apply the following logicsheets in order -->
  22. <xts:logicsheet path="qs/logicsheets/calc_theme.xsl"/>
  23. <xts:logicsheet path="logicsheets/portal.xsl"/>
  24. <xts:logicsheet path="qs/logicsheets/dialogs.xsl"/>
  25. <xts:logicsheet path="logicsheets/presentation/dialog/framework.xsl"/>
  26. <xts:logicsheet path="logicsheets/presentation/layout.xsl"/>
  27. <xts:logicsheet path="logicsheets/presentation/dialog/presentation.xsl"/>
  28. <xts:logicsheet path="logicsheets/presentation/controls/framework.xsl"/>
  29. <xts:logicsheet path="logicsheets/presentation/controls/presentation.xsl"/>
  30. <xts:logicsheet path="logicsheets/cm-logic.xsl"/>
  31. <!-- apply the form logic -->
  32. <xts:logicsheet path="logicsheets/formlogic.xslt"/>
  33. <xsl:stylesheet version="1.0"
  34. xmlns:clcdlg="test_calculationDlg"
  35. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  36. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  37. xmlns:lyt="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/layout/"
  38. xmlns:pf="http://developer.cognos.com/schemas/xts/pf"
  39. xmlns:dp="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/dialog/presentation/"
  40. xmlns:df="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/dialog/framework/"
  41. xmlns:cp="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/controls/presentation/"
  42. xmlns:cf="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/controls/framework/"
  43. xmlns:dbg="http://developer.cognos.com/schemas/xts/logicsheets/xslt/debug/"
  44. xmlns:qsdlg="http://developer.cognos.com/schemas/xts/logicsheets/xslt/qs/dialog/"
  45. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  46. exclude-result-prefixes="clcdlg xsl xts lyt pf dp df cp cf dbg qsdlg xtsext">
  47. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="no"/>
  48. <!-- Default variables (like skin) and prompt variables -->
  49. <qsdlg:variables/>
  50. <qsdlg:promptVariables/>
  51. <!-- Prompt Control XSL include -->
  52. <xsl:include href="p_include.xsl"/>
  53. <!-- add any theme variables -->
  54. <df:variables/>
  55. <pf:variables/>
  56. <!-- start the output -->
  57. <xsl:template match="/root">
  58. <dp:page>
  59. <dp:script>
  60. <xsl:call-template name="getPromptCommonIncludes"/>
  61. <xsl:call-template name="gettextBoxIncludes">
  62. <xsl:with-param name="promptLocale" select="$promptLocale"/>
  63. <xsl:with-param name="promptContentLocale" select="$contentLocale"/>
  64. </xsl:call-template>
  65. <link href="{$qsdlgskin}/qs/QSRVDialog.css" type="text/css" rel="stylesheet"/>
  66. <script type="text/javascript">
  67. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/qs/layout.js</xsl:attribute>
  68. <xsl:text/>//<xsl:text/>
  69. </script>
  70. <script type="text/javascript">
  71. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/rv/cvConstants.js</xsl:attribute>
  72. <xsl:text/>//<xsl:text/>
  73. </script>
  74. <script type="text/javascript">
  75. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/rv/common.js</xsl:attribute>
  76. <xsl:text/>//<xsl:text/>
  77. </script>
  78. <script type="text/javascript">
  79. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/rv/cvui.js</xsl:attribute>
  80. <xsl:text/>//<xsl:text/>
  81. </script>
  82. <script type="text/javascript">
  83. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/common/framework/notification/CObserver.js</xsl:attribute>
  84. <xsl:text/>//<xsl:text/>
  85. </script>
  86. <script type="text/javascript">
  87. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/qs/classes/CDialogManager.js</xsl:attribute>
  88. <xsl:text/>//<xsl:text/>
  89. </script>
  90. <script type="text/javascript">
  91. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/qs/classes/CWindowManager.js</xsl:attribute>
  92. <xsl:text/>//<xsl:text/>
  93. </script>
  94. <script type="text/javascript">&lt;!--
  95. var goDialogManager = new CDialogManager();
  96. <clcdlg:jvs/>
  97. var cf = getConfigFrame();
  98. var calcType = cf.dlgGlobalGetParm('xxCalcType');
  99. var calcParentIds = new Array();
  100. var calcParentLabels = new Array();
  101. var substVarValue = null;
  102. function execute()
  103. {
  104. var oMQMgr = goDialogManager.getMiniQueryManager();
  105. var before_col_id = cf.dlgGlobalGetParm('xxInsBeforeColid');
  106. var calcOp = document.f.calcList.options[document.f.calcList.selectedIndex].value; // power, sqrt, round, round down, absolute
  107. var regularAgg = cf.dlgGlobalGetParm('xxRegularAgg');
  108. var detailAgg = cf.dlgGlobalGetParm('xxDetailAgg');
  109. var calcBy = "none";
  110. var calcExpr = "generated";
  111. var exponentVal = 1;
  112. var cType = -1;
  113. var cUsage = -1;
  114. var listSeparator = goDialogManager.getMiniQueryManager().getListSeparator();
  115. var decimalSeparator = goDialogManager.getMiniQueryManager().getDecimalSeparator();
  116. if (calcOp == "sqrt")
  117. calcExpr = "sqrt(abs(" + document.f.repSel.options[document.f.repSel.options.selectedIndex].value + "))";
  118. else if (calcOp == "round")
  119. calcExpr = "_round(" + document.f.repSel.options[document.f.repSel.options.selectedIndex].value + listSeparator + " 0)";
  120. else if (calcOp == "round down")
  121. calcExpr = "floor(" + document.f.repSel.options[document.f.repSel.options.selectedIndex].value + ")";
  122. else if (calcOp == "absolute")
  123. calcExpr = "abs(" + document.f.repSel.options[document.f.repSel.options.selectedIndex].value + ")";
  124. else
  125. {
  126. if ((typeof textBoxnumberValue != "undefined")&amp;&amp;(document.getElementById("textBoxNumeric").style.display != "none"))
  127. {
  128. if ((textBoxnumberValue.sGetValue() != "")&amp;&amp;(textBoxnumberValue.isValid()))
  129. exponentVal = textBoxnumberValue.sGetValue();
  130. else
  131. return;
  132. }
  133. else if (document.getElementById("textBoxString").style.display != "none")
  134. {
  135. exponentVal = substVarValue;
  136. }
  137. if (decimalSeparator != ".")
  138. {
  139. exponentVal = exponentVal.replace("\.", decimalSeparator);
  140. }
  141. calcExpr = "power(1" + decimalSeparator + "0*" + document.f.repSel.options[document.f.repSel.options.selectedIndex].value + listSeparator + " " + exponentVal + ")";
  142. }
  143. var calcName = getCalcName();
  144. var queryId = -1;
  145. for (var i = 0; i &lt; calcParentLabels.length; i++)
  146. {
  147. if ((calcParentLabels[i] == document.f.repSel.options[document.f.repSel.options.selectedIndex].text)||("(" + calcParentLabels[i] + ")" == document.f.repSel.options[document.f.repSel.options.selectedIndex].text))
  148. {
  149. queryId = i;
  150. break;
  151. }
  152. }
  153. if (queryId &lt; 0)
  154. return;
  155. //TODO - CLEANUP can the following code be replaced by below?
  156. //queryId = oMQMgr.isMeasure(calcParentIds[queryId]);
  157. for (var j = 0; j &lt; oMQMgr.getAllColumns().length; j++)
  158. {
  159. if (calcParentIds[queryId] == oMQMgr.getColumnId(j))
  160. {
  161. queryId = oMQMgr.isMeasure(j);
  162. break;
  163. }
  164. }
  165. if (queryId &lt; 0)
  166. return;
  167. else if (queryId == false)
  168. {
  169. cType = 21;
  170. cUsage = 2;
  171. detailAgg = "none";
  172. regularAgg = "none";
  173. }
  174. getConfigFrame().addCalcColumn(before_col_id, calcExpr, calcExpr, calcName, calcBy, calcOp, "none", 0, cType, cUsage, regularAgg, -1, detailAgg, calcParentIds);
  175. }
  176. function generateName(withQuotes)
  177. {
  178. var calcName = document.f.calcList.options[document.f.calcList.selectedIndex].value; // power, sqrt, round, round down, absolute
  179. var column = document.f.repSel.options[document.f.repSel.options.selectedIndex].text;
  180. {
  181. if (calcName == "sqrt")
  182. calcName = "<xts:string id="CALCULATION_SQUARE_ROOT_EQUATION" encode="javascript"/>";
  183. else if (calcName == "round")
  184. calcName = "<xts:string id="CALCULATION_ROUND_EQUATION" encode="javascript"/>";
  185. else if (calcName == "round down")
  186. calcName = "<xts:string id="CALCULATION_ROUND_DOWN_EQUATION" encode="javascript"/>";
  187. else if (calcName == "absolute")
  188. calcName = "<xts:string id="CALCULATION_ABSOLUTE_EQUATION" encode="javascript"/>";
  189. else
  190. {
  191. calcName = "<xts:string id="CALCULATION_POWER_EQUATION" encode="javascript"/>";
  192. var exponentVal = 1;
  193. if (document.getElementById("textBoxNumeric").style.display != "none")
  194. var textBoxValue = textBoxnumberValue;
  195. else
  196. var textBoxValue = textBoxstringValue;
  197. if ((typeof textBoxValue != "undefined")&amp;&amp;(textBoxValue.isValid())&amp;&amp;(textBoxValue.sGetFormatValue() != ""))
  198. exponentVal = textBoxValue.sGetFormatValue();
  199. else if ((typeof textBoxValue != "undefined")&amp;&amp;(textBoxValue.m_oForm.value)&amp;&amp;(textBoxValue.m_oForm.value != ""))
  200. exponentVal = textBoxValue.m_oForm.value;
  201. calcName = stringReplace (calcName, "\\^1", exponentVal);
  202. }
  203. }
  204. calcName = stringReplace (calcName, "\\^0", column);
  205. return calcName;
  206. }
  207. function init()
  208. {
  209. attachMouseEvents();
  210. for (var i = 0; i &lt; cf.dlgGlobalSize('xxCalcParentIds'); i++)
  211. {
  212. var label = cf.dlgGlobalGetParmAt('xxCalcParentIds', i);
  213. calcParentIds[i] = label[0];
  214. calcParentLabels[i] = label[1];
  215. }
  216. // populate selected columns menu
  217. for (var i = 0; i &lt; cf.dlgGlobalSize('xxColInfo'); i++)
  218. {
  219. var aColInfo = cf.dlgGlobalGetParmAt('xxColInfo', i);
  220. // var aSummExpr = cf.dlgGlobalGetParmAt('xxSummExpr', i);
  221. // Bug Fix COGCQ00247495 - Advanced arithmatic operation with Count distinct on identifier in QS returns incorrect value or causes exceptions
  222. // Set Value for "repSel" options control with Column Expression instead of using columnExprWithoutAggWrapped
  223. document.f.repSel.options[document.f.repSel.options.length] = new Option(aColInfo[0], aColInfo[1]);
  224. }
  225. var validCalcs = new Array();
  226. for (var i = 0; i &lt; cf.dlgGlobalSize('xxValidCalcItem'); i++)
  227. validCalcs[validCalcs.length] = cf.dlgGlobalGetParmAt('xxValidCalcItem', i);
  228. populateCalculationList(calcType, validCalcs, "arithmetic");
  229. // select calculation
  230. document.f.calcList.selectedIndex = cf.dlgGlobalGetParm('xxCalcTypeIdx');
  231. document.f.calcNumberList.selectedIndex = cf.dlgGlobalGetParm('xxCalcSubTypeIdx');
  232. getConfigFrame().cfgSet("CALCULATION_REFRESH", true);
  233. loadHint();
  234. setGlobals(calcType, false);
  235. addInsert();
  236. if (typeof textBoxnumberValue != "undefined")
  237. {
  238. <xsl:choose>
  239. <xsl:when test="/root/browserInfo/isNS6='true'">
  240. textBoxnumberValue.m_oForm.addEventListener("keydown", redrawHint, true);
  241. </xsl:when>
  242. <xsl:otherwise>
  243. textBoxnumberValue.m_oForm.attachEvent("onkeydown", redrawHint);
  244. </xsl:otherwise>
  245. </xsl:choose>
  246. textBoxnumberValue.m_oForm.focus();
  247. }
  248. <xsl:if test="/root/env/param[@name='xxSubstVar']='true' and /root/env/param[@name='xxDialogType']='CALCULATION_POWER'">
  249. <clcdlg:subst_var numeric="true"/>
  250. <xsl:choose>
  251. <xsl:when test="/root/browserInfo/isNS6='true'">
  252. textBoxstringValue.m_oForm.addEventListener("change", redrawHint, true);
  253. </xsl:when>
  254. <xsl:otherwise>
  255. textBoxstringValue.m_oForm.attachEvent("onchange", redrawHint);
  256. </xsl:otherwise>
  257. </xsl:choose>
  258. //hide the second input field
  259. document.getElementById("textBoxString").style.display = "none";
  260. </xsl:if>
  261. }
  262. function redrawHint()
  263. {
  264. setTimeout(loadHint, 10);
  265. }
  266. //--&gt;</script>
  267. </dp:script>
  268. <form style="margin:0px" name="f" method="POST" onsubmit="execute();return false;">
  269. <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%">
  270. <tr>
  271. <td width="100%" height="0%">
  272. <!-- dialog header -->
  273. <clcdlg:basic_header/>
  274. </td>
  275. </tr>
  276. <tr>
  277. <td width="100%" height="100%" valign="top">
  278. <lyt:layout style="2" border="no">
  279. <lyt:section>
  280. <clcdlg:calculationsType/>
  281. <clcdlg:calculations/>
  282. <dp:input>
  283. <dp:section1>
  284. <xts:string id="CALCULATION_REP_ITEM"/>
  285. </dp:section1>
  286. <dp:section2>
  287. <select name="repSel" size="1" style="width:260" onChange="javascript:loadHint();"/>
  288. </dp:section2>
  289. </dp:input>
  290. <xsl:if test="/root/env/param[@name='xxDialogType'] = 'CALCULATION_POWER'">
  291. <table>
  292. <tr>
  293. <td class="formLabel" nowrap="nowrap" valign="middle">
  294. <xsl:choose>
  295. <xsl:when test="/root/env/param[@name='xxSubstVar']='true'">
  296. <xts:string id="CALCULATION_VALUE"/>
  297. </xsl:when>
  298. <xsl:otherwise>
  299. <xts:string id="CALCULATION_EXPONENT_NUMBER"/>
  300. </xsl:otherwise>
  301. </xsl:choose>
  302. </td>
  303. <td id="textBoxNumeric" valign="bottom">
  304. <xsl:call-template name="getTextBox">
  305. <xsl:with-param name="promptLocale" select="$promptLocale"/>
  306. <xsl:with-param name="promptFormName" select="$promptFormName"/>
  307. <xsl:with-param name="promptRequired" select="'false'"/>
  308. <xsl:with-param name="promptId" select="'numberValue'"/>
  309. <xsl:with-param name="promptHideText" select="'false'"/>
  310. <xsl:with-param name="promptMultiLine" select="'false'"/>
  311. <xsl:with-param name="promptParameter" select="'exponentParam'"/>
  312. <xsl:with-param name="promptDataType" select="'number'"/>
  313. <xsl:with-param name="promptMaxLength" select="'15'"/>
  314. </xsl:call-template>
  315. </td>
  316. <xsl:if test="/root/env/param[@name='xxSubstVar']='true'">
  317. <td id="textBoxString" valign="bottom">
  318. <xsl:call-template name="getTextBox">
  319. <xsl:with-param name="promptLocale" select="$promptLocale"/>
  320. <xsl:with-param name="promptFormName" select="$promptFormName"/>
  321. <xsl:with-param name="promptRequired" select="'false'"/>
  322. <xsl:with-param name="promptId" select="'stringValue'"/>
  323. <xsl:with-param name="promptHideText" select="'false'"/>
  324. <xsl:with-param name="promptMultiLine" select="'false'"/>
  325. <xsl:with-param name="promptParameter" select="'exponentParam2'"/>
  326. <xsl:with-param name="promptReadOnly" select="'true'"/>
  327. </xsl:call-template>
  328. </td>
  329. <td id="buttonContainer"/>
  330. </xsl:if>
  331. </tr>
  332. </table>
  333. </xsl:if>
  334. </lyt:section>
  335. <lyt:section>
  336. <clcdlg:calc_hint/>
  337. </lyt:section>
  338. </lyt:layout>
  339. </td>
  340. </tr>
  341. <tr>
  342. <td width="100%" height="0%">
  343. <!-- Use default buttons [ OK = execute() and CANCEL = hideDialogFrame() ] -->
  344. <clcdlg:buttons/>
  345. </td>
  346. </tr>
  347. <!-- <dbg:dumpxml select="/"/> -->
  348. </table>
  349. </form>
  350. </dp:page>
  351. </xsl:template>
  352. </xsl:stylesheet>
  353. </xts:block>
  354. </xts:morphlet>