displayoptions_gen.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: pps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2017
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // This forms the javascript functions used for the display options
  9. // action pane for PowerPlay Studio.
  10. // The functions handle any minor browser differences.
  11. var DISPLAY_CROSSTAB = 0;
  12. var DISPLAY_PIECHART = 1;
  13. var DISPLAY_BARCHART = 2;
  14. var DISPLAY_CLUSTERCHART = 3;
  15. var DISPLAY_LINECHART = 4;
  16. var DISPLAY_STACKEDCHART = 5;
  17. var DISPLAY_THREEDCHART = 6;
  18. var DISPLAY_FINANCIAL_CROSSTAB = 9;
  19. var isNSBrowser = navigator.appName.indexOf("Netscape")>=0;
  20. if( navigator.appVersion == "" )
  21. isNSBrowser = false;
  22. var isNSMac = isNSBrowser && navigator.platform.indexOf("Mac") >= 0;
  23. var isSplitPane = parent.parent.getWindow().name == "FX1";
  24. function findObj(n, d) {
  25. var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  26. d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  27. if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  28. for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  29. if(!x && document.getElementById) x=document.getElementById(n); return x;
  30. }
  31. function writeErrorMessage (msg) {
  32. var err = findObj("ErrorMessage");
  33. if (err) {
  34. if (document.getElementById) { //IE 5.5+ , Netscape 6.0+
  35. err.innerHTML = '<table><tr><td valign="middle"><img src="../ppwb/Graphics/error.gif" height=18 width=18 alt=""></td><td class="CustomExceptionError" valign="middle">' + msg + '</td></tr></table><br><br>';
  36. } else if (isNSBrowser) { // Other Netscape browsers
  37. err.visibility = "visible";
  38. err.moveTo(11, document.layers["referenceLayer"].top + document.layers["referenceLayer"].clip.bottom);
  39. err.resizeTo(parent.FE.innerWidth - 25, 50);
  40. err.document.open();
  41. err.document.write('<html><body><table><tr><td><img src="../ppwb/Graphics/error.gif" height=18 width=18 alt=""></td><td class="CustomExceptionError" valign="middle">' + msg + '</td></tr></table></body></html>');
  42. err.document.close();
  43. } else
  44. alert (msg);
  45. }
  46. }
  47. function getHiddenFormChart () {
  48. if (isSplitPane) {
  49. return parent.FX2.document.fhidden;
  50. } else {
  51. return parent.FX.document.fhidden;
  52. }
  53. }
  54. function getHiddenFormXtab () {
  55. if (isSplitPane) {
  56. return parent.FX1.document.fhidden;
  57. } else {
  58. return parent.FX.document.fhidden;
  59. }
  60. }
  61. function getDisplayType () {
  62. if (isSplitPane) {
  63. return parseInt(getHiddenFormChart().YS.value);
  64. } else {
  65. if (getHiddenFormChart().Y)
  66. return parseInt(getHiddenFormChart().Y.value);
  67. else
  68. return DISPLAY_CROSSTAB;
  69. }
  70. }
  71. function isChartDisplay() {
  72. var displayType = getDisplayType();
  73. return (displayType != DISPLAY_CROSSTAB && displayType != DISPLAY_FINANCIAL_CROSSTAB);
  74. }
  75. function applyDisplayOptions (forceClose) {
  76. if (parent.isXtabStillLoading())
  77. {
  78. setTimeout("applyDisplayOptions()", 50);
  79. return;
  80. }
  81. var hiddenForm = getHiddenFormChart();
  82. if(!hiddenForm)
  83. return;
  84. var htmlToAppend = "";
  85. var command = "";
  86. if (isChartDisplay())
  87. {
  88. var chartType = getDisplayType();
  89. command += "T:";
  90. command += getChartOptions(chartType);
  91. command += '"';
  92. }
  93. if (forceClose)
  94. {
  95. command += "\t\t";
  96. command += "MT";
  97. }
  98. var shortNames = 0;
  99. if(document.optionsForm.ShortNames.checked)
  100. shortNames = 1;
  101. if((!hiddenForm.SHN && shortNames) || (hiddenForm.SHN && shortNames != hiddenForm.SHN.value))
  102. {
  103. command += "\t\t";
  104. command += "OSHN";
  105. }
  106. var fitChartsForm = hiddenForm.F;
  107. var fitChartsElem = document.optionsForm.fitcharts;
  108. if (!fitChartsForm && fitChartsElem && fitChartsElem.checked) {
  109. command += "\t\t";
  110. command += "OF";
  111. }
  112. else if (fitChartsForm && fitChartsElem && (fitChartsForm.value != fitChartsElem.checked)) {
  113. command += "\t\t";
  114. command += "OF";
  115. }
  116. if (!validateFields())
  117. writeErrorMessage(strInvalidMinMaxMsg);
  118. else if (!validateAndSetScaling(hiddenForm))
  119. writeErrorMessage(strInvalidHeightWidthMsg);
  120. else
  121. {
  122. hiddenForm.CNCT.value = 4;
  123. if (isSplitPane)
  124. parent.FX2.doit(command);
  125. else
  126. parent.FX.doit(command);
  127. }
  128. }
  129. function closeit() {
  130. if (isSplitPane) {
  131. parent.FX2.doit('MT');
  132. } else {
  133. parent.FX.doit('MT');
  134. }
  135. }
  136. function onOK() {
  137. applyDisplayOptions(true);
  138. }
  139. function getChartInputStr() {
  140. var chartType = getDisplayType();
  141. if (isChartDisplay())
  142. return '<INPUT TYPE="HIDDEN" NAME="CHOP' + chartType + '" VALUE="' + getChartOptions(chartType) + '">' + "\n";
  143. else
  144. return "";
  145. }
  146. function getChartOptions(n) {
  147. var opts;
  148. switch (n) {
  149. case 1: opts = getPieOptions(); break;
  150. case 2: opts = getBarOptions(); break;
  151. case 3: opts = getClusterOptions(); break;
  152. case 4: opts = getLineOptions(); break;
  153. case 5: opts = getStackedOptions(); break;
  154. case 6: opts = getThreedOptions(); break;
  155. }
  156. return opts;
  157. }
  158. function getPieOptions() {
  159. var opt;
  160. if(document.optionsForm.slicelabels[0].checked)
  161. opt = '"COP_VP;2;0"\t"COP_LP;2;2"';
  162. else
  163. opt = '"COP_VP;2;2"\t"COP_LP;2;0"';
  164. return opt;
  165. }
  166. function getBarOptions() {
  167. var opt;
  168. if (document.optionsForm.ManualScale.checked) {
  169. opt = '"COA_MS;1;1"\t"COA_MSI;3;' + document.optionsForm.MinValue.value + '"\t"COA_MSA;3;' + document.optionsForm.MaxValue.value + '"';
  170. } else {
  171. opt = '"COA_MS;1;0"';
  172. }
  173. if (document.optionsForm.ShowGrid.checked)
  174. opt += '\t"COA_SG;1;1"';
  175. else
  176. opt += '\t"COA_SG;1;0"';
  177. if (document.optionsForm.BarValues.checked)
  178. opt += '\t"COGCB_LP;2;1"';
  179. else
  180. opt += '\t"COGCB_LP;2;0"';
  181. return opt;
  182. }
  183. function getClusterOptions() {
  184. var opt;
  185. if (document.optionsForm.ManualScale.checked) {
  186. opt = '"COA_MS;1;1"\t"COA_MSI;3;' + document.optionsForm.MinValue.value + '"\t"COA_MSA;3;' + document.optionsForm.MaxValue.value + '"';
  187. } else {
  188. opt = '"COA_MS;1;0"';
  189. }
  190. if (document.optionsForm.ShowGrid.checked)
  191. opt += '\t"COA_SG;1;1"';
  192. else
  193. opt += '\t"COA_SG;1;0"';
  194. if (document.optionsForm.BarValues.checked)
  195. opt += '\t"COGCB_LP;2;1"';
  196. else
  197. opt += '\t"COGCB_LP;2;0"';
  198. return opt;
  199. }
  200. function getLineOptions() {
  201. var opt;
  202. if (document.optionsForm.ManualScale.checked) {
  203. opt = '"COA_MS;1;1"\t"COA_MSI;3;' + document.optionsForm.MinValue.value + '"\t"COA_MSA;3;' + document.optionsForm.MaxValue.value + '"';
  204. } else {
  205. opt = '"COA_MS;1;0"';
  206. }
  207. if (document.optionsForm.ShowGrid.checked)
  208. opt += '\t"COA_SG;1;1"';
  209. else
  210. opt += '\t"COA_SG;1;0"';
  211. if (document.optionsForm.Markers.checked)
  212. opt += '\t"COGCL_SM;1;1"';
  213. else
  214. opt += '\t"COGCL_SM;1;0"';
  215. return opt;
  216. }
  217. function getStackedOptions() {
  218. var opt;
  219. if (document.optionsForm.ManualScale.checked) {
  220. opt = '"COA_MS;1;1"\t"COA_MSI;3;' + document.optionsForm.MinValue.value + '"\t"COA_MSA;3;' + document.optionsForm.MaxValue.value + '"';
  221. } else {
  222. opt = '"COA_MS;1;0"';
  223. }
  224. if (document.optionsForm.ShowGrid.checked)
  225. opt += '\t"COA_SG;1;1"';
  226. else
  227. opt += '\t"COA_SG;1;0"';
  228. return opt;
  229. }
  230. function getThreedOptions() {
  231. var opt;
  232. if (document.optionsForm.ManualScale.checked) {
  233. opt = '"COA_MS;1;1"\t"COA_MSI;3;' + document.optionsForm.MinValue.value + '"\t"COA_MSA;3;' + document.optionsForm.MaxValue.value + '"';
  234. } else {
  235. opt = '"COA_MS;1;0"';
  236. }
  237. if (document.optionsForm.ShowGrid.checked)
  238. opt += '\t"COA3_SGL;1;1"\t"COA3_SGR;1;1"\t"COA3_SGB;1;1"';
  239. else
  240. opt += '\t"COA3_SGL;1;0"\t"COA3_SGR;1;0"\t"COA3_SGB;1;0"';
  241. return opt;
  242. }
  243. function validateFields() {
  244. if (document.optionsForm.ManualScale && document.optionsForm.ManualScale.checked) {
  245. if (document.optionsForm.MaxValue && (!document.optionsForm.MaxValue.value.length || !validateField(document.optionsForm.MaxValue)))
  246. return false;
  247. if (document.optionsForm.MinValue && (!document.optionsForm.MinValue.value.length || !validateField(document.optionsForm.MinValue)))
  248. return false;
  249. if (document.optionsForm.MaxValue && document.optionsForm.MinValue && (parseFloat(getNonLocalizedDecimalVal(document.optionsForm.MaxValue.value)) <= parseFloat(getNonLocalizedDecimalVal(document.optionsForm.MinValue.value))))
  250. return false;
  251. }
  252. return true;
  253. }
  254. function validateAndSetScaling(hf) {
  255. if (chartType == 0 || chartType == 9)
  256. return true;
  257. if (document.optionsForm.fitcharts && document.optionsForm.fitcharts.checked) {
  258. var chartType = getDisplayType();
  259. if ((chartType == DISPLAY_PIECHART) || (chartType == DISPLAY_THREEDCHART)) {
  260. if (!validateAndSetValue(document.optionsForm.HeightScaling, hf.POS))
  261. return false;
  262. }
  263. else {
  264. if (!validateAndSetValue(document.optionsForm.HeightScaling, hf.PHS))
  265. return false;
  266. if (!validateAndSetValue(document.optionsForm.WidthScaling, hf.PWS))
  267. return false;
  268. }
  269. }
  270. return true;
  271. }
  272. function validateAndSetValue(elem, formElem) {
  273. if (elem) {
  274. if (!validateField(elem))
  275. return false;
  276. var elemValue = elem.value;
  277. if ((elemValue < minScalingValue) || (elemValue > maxScalingValue))
  278. return false;
  279. formElem.value = elemValue;
  280. }
  281. return true;
  282. }
  283. function switchOnOffTextFields() {
  284. if (!document.optionsForm.ManualScale.checked) {
  285. document.optionsForm.MaxValue.value = "";
  286. document.optionsForm.MinValue.value = "";
  287. }
  288. }
  289. function getNonLocalizedDecimalVal(val) {
  290. return val.replace(decimalpt,'.');
  291. }
  292. function switchOnManualScale() {
  293. if (!document.optionsForm.ManualScale.checked) {
  294. document.optionsForm.ManualScale.checked = true;
  295. }
  296. }
  297. function validateField(FormObj) {
  298. var userInput = FormObj.value;
  299. var reducedInput = "";
  300. var len = userInput.length;
  301. var negative = false;
  302. for ( var i = 0; i < len; i++ ) { //Strip out the thousand Separators.
  303. if ((i==0) && userInput.charAt(i) == '-') {
  304. negative = true;
  305. } else if (userInput.charAt(i) != thousandsep) {
  306. reducedInput += userInput.charAt(i);
  307. }
  308. }
  309. var acceptableChars = "/[^0-9" + decimalpt + "]/";
  310. var pos = reducedInput.search(eval(acceptableChars));
  311. if (pos != -1)
  312. return false;
  313. //Ensure that we only have 1 decimal
  314. if (reducedInput.indexOf(decimalpt) != reducedInput.lastIndexOf(decimalpt))
  315. return false;
  316. if ( negative )
  317. reducedInput = "-" + reducedInput;
  318. FormObj.value = reducedInput;
  319. return true;
  320. }
  321. function sliceLabelsButtonNames()
  322. {
  323. document.optionsForm.slicelabels[0].checked = true;
  324. document.optionsForm.slicelabels[1].checked = false;
  325. }
  326. function sliceLabelsButtonValues()
  327. {
  328. document.optionsForm.slicelabels[0].checked = false;
  329. document.optionsForm.slicelabels[1].checked = true;
  330. }
  331. function processInput(hw) {
  332. var chartType = getDisplayType();
  333. if ((chartType == DISPLAY_PIECHART) || (chartType == DISPLAY_THREEDCHART)) {
  334. if (hw == "h")
  335. document.optionsForm.WidthScaling.value = document.optionsForm.HeightScaling.value;
  336. else
  337. document.optionsForm.HeightScaling.value = document.optionsForm.WidthScaling.value;
  338. }
  339. }
  340. function switchOnScaling() {
  341. if (!document.optionsForm.fitcharts.checked) {
  342. document.optionsForm.fitcharts.checked = true;
  343. }
  344. }