ModifyReportAction.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2014
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. * Base class for interactive report actions
  14. */
  15. function ModifyReportAction() {
  16. this.m_reuseConversation = true;
  17. }
  18. ModifyReportAction.prototype = new CognosViewerAction();
  19. ModifyReportAction.prototype.addActionContextAdditionalParms = function() {};
  20. ModifyReportAction.prototype.runReport = function() { return true; };
  21. ModifyReportAction.prototype.updateRunReport = function() {};
  22. ModifyReportAction.prototype.reuseQuery = function() { return false; };
  23. ModifyReportAction.prototype.reuseGetParameter = function() {return true; };
  24. ModifyReportAction.prototype.reuseConversation = function(reuseConversation) {
  25. if (typeof reuseConversation != "undefined") {
  26. this.m_reuseConversation = reuseConversation;
  27. }
  28. return this.m_reuseConversation;
  29. };
  30. ModifyReportAction.prototype.updateInfoBar = function() { return true; };
  31. ModifyReportAction.prototype.getUndoHint = function() { return ""; };
  32. ModifyReportAction.prototype.isUndoable = function() { return true; };
  33. ModifyReportAction.prototype.saveSpecForUndo = function() { return false; };
  34. ModifyReportAction.prototype.keepFocusOnWidget = function() { return true; };
  35. ModifyReportAction.prototype.keepRAPCache = function() { return true; };
  36. ModifyReportAction.prototype.getActionKey = function() { return null; };
  37. ModifyReportAction.prototype.canBeQueued = function() { return false; };
  38. ModifyReportAction.prototype.getPromptOption = function() { return "false"; };
  39. ModifyReportAction.prototype.createActionDispatcherEntry = function()
  40. {
  41. var actionDispatcherEntry = new ModifyReportDispatcherEntry(this.m_oCV);
  42. actionDispatcherEntry.initializeAction(this);
  43. return actionDispatcherEntry;
  44. };
  45. ModifyReportAction.prototype.isSelectSingleMember = function(selectedObject)
  46. {
  47. var oRAPReportInfo = this.m_oCV.getRAPReportInfo();
  48. var dataItems = selectedObject.getDataItems();
  49. if (oRAPReportInfo && dataItems.length > 0) {
  50. var containerId = this.getContainerId(this.m_oCV.getSelectionController());
  51. var itemInfo = oRAPReportInfo.getItemInfo(containerId, dataItems[0][0]);
  52. if (itemInfo.single =="true") {
  53. return true;
  54. }
  55. }
  56. return false;
  57. };
  58. ModifyReportAction.prototype.execute = function() {
  59. var oCV = this.getCognosViewer();
  60. oCV.setKeepFocus(this.keepFocusOnWidget());
  61. this.updateRunReport();
  62. if (this.runReport() == true) {
  63. var actionDispatcherEntry = this.createActionDispatcherEntry();
  64. this.addAdditionalOptions(actionDispatcherEntry);
  65. oCV.dispatchRequest(actionDispatcherEntry);
  66. }
  67. else {
  68. var cognosViewerRequest = this.createCognosViewerDispatcherEntry( "modifyReport" );
  69. cognosViewerRequest.setCallbacks({"complete":{"object":this, "method":this.updateReportSpecCallback}});
  70. oCV.dispatchRequest(cognosViewerRequest);
  71. }
  72. this.fireModifiedReportEvent();
  73. };
  74. ModifyReportAction.prototype.updateReportSpecCallback = function(oAsynchDataResposne) {
  75. var state = oAsynchDataResposne.getResponseState();
  76. var requestHanlder = new RequestHandler(this.m_oCV);
  77. requestHanlder.updateViewerState(state);
  78. // we'd sometimes add 2 items into the undo stack. One from the onclick and one from
  79. // the onblur. Make sure we only add one item to the undo stack
  80. if (!this.m_bUndoAdded)
  81. {
  82. this.m_bUndoAdded = true;
  83. var oUndoRedoQueue = this.getUndoRedoQueue();
  84. if(oUndoRedoQueue) {
  85. oUndoRedoQueue.initUndoObj({"tooltip" : this.getUndoHint(), "saveSpec" : true});
  86. oUndoRedoQueue.add({"reportUpdated": true});
  87. }
  88. var oWidget = this.getCognosViewer().getViewerWidget();
  89. if(oWidget) {
  90. oWidget.updateToolbar();
  91. }
  92. }
  93. };
  94. /**
  95. * Builds the action context needed for the modifyReport action
  96. */
  97. ModifyReportAction.prototype.addActionContext = function() {
  98. var actionContext = "<reportActions";
  99. if(this.runReport() == false)
  100. {
  101. actionContext += " run=\"false\"";
  102. }
  103. actionContext += ">";
  104. actionContext += this.getReportActionContext();
  105. actionContext += "</reportActions>";
  106. return actionContext;
  107. };
  108. ModifyReportAction.prototype.getReportActionContext = function()
  109. {
  110. var cognosViewer = this.getCognosViewer();
  111. var selectionController = cognosViewer.getSelectionController();
  112. var actionContext = "<" + this.m_sAction + ">";
  113. var containerId = this.getContainerId(selectionController);
  114. if(containerId != "")
  115. {
  116. actionContext += "<id>" + xml_encode(containerId) + "</id>";
  117. }
  118. actionContext += this.getRTStateInfo();
  119. actionContext += this.getSelectionContext();
  120. var sAdditionalParms = this.addActionContextAdditionalParms();
  121. if( sAdditionalParms != null && sAdditionalParms != "undefined")
  122. {
  123. actionContext += sAdditionalParms;
  124. }
  125. actionContext += "</" + this.m_sAction + ">";
  126. if(this.updateInfoBar())
  127. {
  128. actionContext += this.getGetInfoActionContext();
  129. }
  130. return actionContext;
  131. };
  132. ModifyReportAction.prototype.getGetInfoActionContext = function()
  133. {
  134. return "<GetInfo/>";
  135. };
  136. /*Get widget run time information, such as dashboard object title, search path, etc*/
  137. ModifyReportAction.prototype.getRTStateInfo = function()
  138. {
  139. var oWidget = this.getCognosViewer().getViewerWidget();
  140. if(oWidget && oWidget.getBUXRTStateInfoMap){
  141. var oInfoMap = oWidget.getBUXRTStateInfoMap();
  142. return oInfoMap ? oInfoMap : "";
  143. }
  144. return "";
  145. };
  146. ModifyReportAction.prototype.createEmptyMenuItem = function()
  147. {
  148. // Temporary UI String
  149. return { name: "None", label: "(empty)", iconClass: "", action: null, items: null };
  150. };
  151. ModifyReportAction.prototype.getStateFromResponse = function(oResponse)
  152. {
  153. var oResponseState = null;
  154. if( oResponse && typeof oResponse != "undefined" && oResponse.responseText && typeof oResponse.responseText != "undefined" && oResponse.responseText.length > 0 )
  155. {
  156. var responseXML = XMLBuilderLoadXMLFromString(oResponse.responseText);
  157. var stateData = responseXML.getElementsByTagName("state");
  158. if (stateData != null && stateData.length > 0)
  159. {
  160. try {
  161. if (typeof stateData[0].text != "undefined")
  162. {
  163. oResponseState = eval("(" + stateData[0].text + ")");
  164. }
  165. else
  166. {
  167. oResponseState = eval("(" + stateData[0].textContent + ")");
  168. }
  169. }
  170. catch(e) {
  171. if (typeof console != "undefined" && console && console.log) {
  172. console.log(e);
  173. }
  174. }
  175. }
  176. }
  177. return oResponseState;
  178. };
  179. ModifyReportAction.prototype.getSelectedCellTags = function()
  180. {
  181. var params = "";
  182. var selectionObjects = this.getCognosViewer().getSelectionController().getSelections();
  183. for (var i = 0; i < selectionObjects.length; ++i)
  184. {
  185. var cellRef = selectionObjects[i].getCellRef();
  186. var sDataItem = selectionObjects[i].getDataItems()[0];
  187. if (typeof sDataItem == "undefined" || sDataItem == null)
  188. {
  189. sDataItem = "";
  190. }
  191. var tag = this.getRAPLayoutTag(cellRef);
  192. if (tag != null)
  193. {
  194. params += "<tag><tagValue>" + xml_encode(tag) + "</tagValue><dataItem>" + xml_encode(sDataItem) + "</dataItem></tag>";
  195. }
  196. else
  197. {
  198. params += "<tag><tagValue/><dataItem>" + xml_encode(sDataItem) + "</dataItem></tag>";
  199. }
  200. }
  201. if (params != "") {
  202. params = "<selectedCellTags>" + params + "</selectedCellTags>";
  203. }
  204. return params;
  205. };
  206. ModifyReportAction.prototype.getIsNumericFromReportInfo = function(refDataItem)
  207. {
  208. var containerInfo = this.getSelectedReportInfo();
  209. if (containerInfo != null && typeof containerInfo.itemInfo!="undefined")
  210. {
  211. //This container has filters....does it filter this item?
  212. for (var item = 0; item < containerInfo.itemInfo.length; ++item)
  213. {
  214. if (refDataItem == containerInfo.itemInfo[item].item &&
  215. typeof containerInfo.itemInfo[item].numeric != "undefined") {
  216. return (containerInfo.itemInfo[item].numeric == "true");
  217. }
  218. }
  219. }
  220. return false;
  221. };