CSwap.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** BI and PM: qs
  5. **
  6. ** (C) Copyright IBM Corp. 2001, 2015
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or
  9. ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *****************************************************************/
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All Rights Reserved.
  12. // Cognos and the Cognos logo are trademarks of Cognos ULC (formerly Cognos Incorporated) in the United States and/or other countries. IBM and the IBM logo are trademarks of International Business Machines Corporation in the United States, or other countries, or both. Other company, product, or service names may be trademarks or service marks of others.
  13. var SWAP_ERROR_NEED_XTAB = 100;
  14. var SWAP_ERROR_NEED_MORE = 101;
  15. function CSwap()
  16. {
  17. this.m_aExecParams = new Array();
  18. };
  19. CSwap.prototype = new AFeatureObject();
  20. CSwap.prototype.processErrorState = function ()
  21. {
  22. if (this.m_iErrorState === FEATURE_OBJECT_NO_ERROR)
  23. {
  24. return false;
  25. }
  26. else if (this.m_iErrorState === SWAP_ERROR_NEED_XTAB)
  27. {
  28. dlgShowMessage("SWAP_TITLE", "", "SWAP_ERROR_NEED_XTAB");
  29. return true;
  30. }
  31. else if (this.m_iErrorState === SWAP_ERROR_NEED_MORE)
  32. {
  33. dlgShowMessage("SWAP_TITLE", "", "SWAP_ERROR_NEED_MORE");
  34. return true;
  35. }
  36. };
  37. CSwap.prototype.proceedWithoutDialog = function ()
  38. {
  39. return this.execute();
  40. };
  41. CSwap.prototype.setup = function (aFeatureParams)
  42. {
  43. this.m_aParams = new Array();
  44. this.m_iErrorState = FEATURE_OBJECT_NO_ERROR;
  45. this.m_bRequiresDialog = false;
  46. this.m_aExecParams = new Array();
  47. var oMQMgr = goApplicationManager.getMiniQueryManager();
  48. if (oMQMgr.hasPivottedColumns())
  49. {
  50. var hasChart = false;
  51. var hasTable = true;
  52. var nonMeasureCount = 0;
  53. var chartType = "";
  54. var oChart = oMQMgr.getChart();
  55. if (typeof oChart == "object" && oChart.getAttribute("type") !== null)
  56. {
  57. chartType = oChart.getAttribute("type");
  58. if (oChart.getAttribute("showTable") == "false")
  59. {
  60. hasTable = false;
  61. }
  62. }
  63. var numMeasures = oMQMgr.getElementsByAttribute("usage", USAGE_VALUE_MEASURE).length;
  64. if (chartType !== "" && !(chartType == "pie" && numMeasures > 1) )
  65. {
  66. hasChart = true;
  67. for (var i = 0; i < oMQMgr.getAllColumns().length; i++)
  68. {
  69. if (oMQMgr.getHidden(i) == "none" && (!oMQMgr.isReportExpression(i)) && oMQMgr.isMeasure(i) === false && !(oMQMgr.getColumnRole(i) === MINI_QUERY_GROUP_SECTION))
  70. {
  71. nonMeasureCount++;
  72. }
  73. }
  74. }
  75. if (hasChart && (nonMeasureCount >= 2) && hasTable)
  76. {
  77. cfgSet("LAST_DIALOG", "swap");
  78. this.m_bRequiresDialog = true;
  79. this.m_aParams["m"] = "/" + qs_dir + "/swap.xts";
  80. }
  81. else if (hasChart && (nonMeasureCount < 2) && !hasTable)
  82. {
  83. this.m_iErrorState = SWAP_ERROR_NEED_MORE;
  84. }
  85. else if (hasChart && (nonMeasureCount >= 2))
  86. {
  87. this.m_aExecParams = ["chart"];
  88. }
  89. else
  90. {
  91. this.m_aExecParams = ["crosstab"];
  92. }
  93. }
  94. else
  95. {
  96. this.m_iErrorState = SWAP_ERROR_NEED_XTAB;
  97. }
  98. };
  99. CSwap.prototype.execute = function (aParameters)
  100. {
  101. var sCommand = "";
  102. if (this.m_aExecParams.length > 0)
  103. {
  104. if (this.m_aExecParams[0] == "crosstab")
  105. {
  106. sCommand = createCommand("M", "S", ['crosstab']);
  107. }
  108. else if (this.m_aExecParams[0] == "chart")
  109. {
  110. sCommand = createCommand("M", "S", ['chart']);
  111. }
  112. }
  113. else
  114. {
  115. try
  116. {
  117. var oDlgFrame = goApplicationManager.getDialogFrame();
  118. if (typeof oDlgFrame == "object")
  119. {
  120. if ((oDlgFrame.document.f.crosstab.checked === true)&&(oDlgFrame.document.f.chart.checked === true))
  121. {
  122. sCommand = createCommand("M", "S", ['all']);
  123. }
  124. else if (oDlgFrame.document.f.crosstab.checked === true)
  125. {
  126. sCommand = createCommand("M", "S", ['crosstab']);
  127. }
  128. else if (oDlgFrame.document.f.chart.checked === true)
  129. {
  130. sCommand = createCommand("M", "S", ['chart']);
  131. }
  132. }
  133. }
  134. catch (e)
  135. {
  136. }
  137. }
  138. if (sCommand !== "")
  139. {
  140. sendCmd(sCommand, "", true);
  141. }
  142. goApplicationManager.getWindowManager().hideDialogFrame();
  143. };