EditContentAction.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2013, 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. function EditContentAction()
  13. {
  14. this._oMissingMemberRecoveryMode = null;
  15. }
  16. EditContentAction.prototype = new CognosViewerAction();
  17. EditContentAction.superclass = CognosViewerAction.prototype;
  18. EditContentAction.prototype.execute = function() {
  19. if (typeof this.preferencesChanged != "undefined" && this.preferencesChanged !== null && this.preferencesChanged === true ) {
  20. this.deleteCWAContainer();
  21. return;
  22. }
  23. window.CVEditContentActionInstance = this;
  24. var buaAlreadyLoaded = window.viewerCWAContainer ? true : false;
  25. if (!window.viewerCWAContainer) {
  26. this.createCWAContainer();
  27. }
  28. this.addWindowEventListeners();
  29. this.buildBUAObjects();
  30. window.viewerCWAContainer.show();
  31. if (buaAlreadyLoaded) {
  32. window.BUAEvent("appReady");
  33. }
  34. };
  35. EditContentAction.prototype.createCWAContainer = function() {
  36. this.deleteCWAContainer();
  37. var containerDiv = this.createCWAIFrame();
  38. var blocker = this.createBlocker();
  39. window.viewerCWAContainer = {
  40. "type" : "iframe",
  41. "containerDiv" : containerDiv,
  42. "blocker" : blocker,
  43. "iframePadding" : "18",
  44. "show" : function() {
  45. this.resize();
  46. this.containerDiv.style.display = "block";
  47. this.blocker.style.display = "block";
  48. },
  49. "hide" : function() {
  50. this.blocker.style.display = "none";
  51. this.containerDiv.style.display = "none";
  52. },
  53. "resize" : function() {
  54. var windowBox = dojo.window.getBox();
  55. this.containerDiv.style.height = windowBox.h - this.iframePadding + "px";
  56. this.containerDiv.style.width = windowBox.w - this.iframePadding + "px";
  57. }
  58. };
  59. };
  60. EditContentAction.prototype.deleteCWAContainer = function() {
  61. var containerObj = window.viewerCWAContainer;
  62. if (containerObj) {
  63. containerObj.hide();
  64. document.body.removeChild(containerObj.containerDiv);
  65. document.body.removeChild(containerObj.blocker);
  66. delete window.viewerCWAContainer;
  67. window.viewerCWAContainer = null;
  68. }
  69. };
  70. EditContentAction.prototype.hideCWAContainer = function() {
  71. this.removeWindowEventListeners();
  72. if (window.viewerCWAContainer) {
  73. window.viewerCWAContainer.hide();
  74. }
  75. window.CVEditContentActionInstance = null;
  76. };
  77. EditContentAction.prototype.createCWAIFrame = function() {
  78. var containerDiv = document.createElement("div");
  79. containerDiv.className = "buaContainer";
  80. document.body.appendChild(containerDiv);
  81. var iframeElement = document.createElement("iframe");
  82. iframeElement.setAttribute("id","buaIframe");
  83. iframeElement.setAttribute("src", this.getWebContent() + "/pat/rsapp.htm");
  84. iframeElement.setAttribute("name", "buaIframe");
  85. iframeElement.setAttribute("frameborder",'0');
  86. iframeElement.className = "buaIframe";
  87. containerDiv.appendChild(iframeElement);
  88. return containerDiv;
  89. };
  90. EditContentAction.prototype.createBlocker = function() {
  91. var blocker = document.createElement("div");
  92. blocker.setAttribute("id","reportBlocker");
  93. blocker.setAttribute("name", "reportBlocker");
  94. blocker.setAttribute("tabIndex", "1");
  95. blocker.className = "reportBlocker";
  96. document.body.appendChild(blocker);
  97. return blocker;
  98. };
  99. EditContentAction.prototype.buildBUAObjects = function() {
  100. window.RSParameters = {
  101. "rs_UIProfile" : "BUA",
  102. "ui.action" : "edit",
  103. "gateway" : location.protocol + "//" + location.host + this.getGateway(),
  104. "theme" : "corporate",//make look&feel consistent between CW and CWA
  105. "capabilitiesXML" : this.getCapabilitiesXml(),
  106. "cafcontextid" : this.getCafContextId(),
  107. "paneOnRight" : this.getViewerIWidget().getPaneOnRight()
  108. };
  109. var viewerWidget = this.getViewerIWidget();
  110. if(viewerWidget !== null) {
  111. var cvGateway = viewerWidget.getAttributeValue("gateway");
  112. if(cvGateway) {
  113. window.RSParameters["cv.gateway"] = cvGateway;
  114. }
  115. var cvWebcontent = viewerWidget.getAttributeValue("webcontent");
  116. if(cvWebcontent) {
  117. window.RSParameters["cv.webcontent"] = cvWebcontent;
  118. }
  119. }
  120. this.addExtraLaunchParameters(window.RSParameters);
  121. };
  122. EditContentAction.prototype.getBUAIframe = function() {
  123. return document.getElementById("buaIframe");
  124. };
  125. EditContentAction.prototype.getBUAWindow = function() {
  126. var buaWindow = null;
  127. var buaIframe = this.getBUAIframe();
  128. if(buaIframe !== null) {
  129. buaWindow = buaIframe.contentWindow;
  130. }
  131. return buaWindow;
  132. };
  133. EditContentAction.prototype.setReportSettings = function() {
  134. var oCV = this.getCognosViewer();
  135. var widget = oCV.getViewerWidget();
  136. //Fire an IWidget event to get the title
  137. widget.fireEvent("com.ibm.bux.widget.getDisplayTitle", null, { callback: function(sTitle) { window.CVEditContentActionInstance.openReportWithBUA(sTitle); } });
  138. };
  139. EditContentAction.prototype.openReportWithBUA = function(sTitle) {
  140. var subStringIndex = this.m_oCV.envParams["ui.spec"].indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  141. if (subStringIndex == -1) { subStringIndex = 0; } else { subStringIndex = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".length; }
  142. var sReportXML = this.m_oCV.envParams["ui.spec"].substr(subStringIndex, this.m_oCV.envParams["ui.spec"].length);
  143. var oContext = {
  144. "displayName" : xml_decode(sTitle), //Chrome HTML encoded this sTtitle
  145. "parameterValues" : this.m_oCV.getExecutionParameters(),
  146. "reportXML" : sReportXML,
  147. "showOpenTransition" : false
  148. };
  149. if (this.ifPassTrackingtoBUA()) {
  150. oContext.tracking = this.m_oCV.getTracking();
  151. }
  152. var buaWindow = this.getBUAWindow();
  153. buaWindow.Application.SetBUAContext(oContext);
  154. };
  155. EditContentAction.prototype.getViewerIWidget = function() {
  156. return this.m_oCV.getViewerWidget();
  157. };
  158. EditContentAction.prototype.getGateway = function() {
  159. return this.m_oCV.getGateway();
  160. };
  161. EditContentAction.prototype.getCapabilitiesXml = function() {
  162. return this.m_oCV.capabilitiesXML;
  163. };
  164. EditContentAction.prototype.getCafContextId = function() {
  165. return typeof this.m_oCV.cafContextId != "undefined" ? this.m_oCV.cafContextId : "";
  166. };
  167. EditContentAction.prototype.getWebContent = function() {
  168. return this.getCognosViewer().getWebContentRoot();
  169. };
  170. EditContentAction.prototype.addExtraLaunchParameters = function(RSParameters) {};
  171. EditContentAction.prototype.runUpdatedReportFromBUA = function() {
  172. var buaWindow = this.getBUAWindow();
  173. var originalSpec = this.m_oCV.envParams["ui.spec"];
  174. var oContext = buaWindow.Application.GetBUAContext();
  175. if (oContext.isSpecModified) {
  176. this.m_oCV.envParams["ui.spec"] = oContext.reportXML;
  177. this.m_oCV.setTracking(oContext.tracking);
  178. this.m_oCV.setExecutionParameters(oContext.parameterValues);
  179. this._invokeRedrawAction(originalSpec);
  180. }
  181. };
  182. EditContentAction.prototype._invokeRedrawAction = function(originalSpec)
  183. {
  184. this.getUndoRedoQueue().setOriginalSpec(originalSpec);
  185. var redrawAction = this.m_oCV.getAction("Redraw");
  186. redrawAction.setSpecUpdated(true);
  187. this.m_oCV.getViewerWidget().setPromptParametersRetrieved(false);
  188. redrawAction.execute();
  189. };
  190. EditContentAction.prototype.ifPassTrackingtoBUA = function()
  191. {
  192. if (this.m_oCV.getRAPReportInfo()) {
  193. return this.m_oCV.getRAPReportInfo().getPassTrackingtoBUA();
  194. }
  195. return true;
  196. };
  197. EditContentAction.prototype.setRequestParms = function(params) {
  198. EditContentAction.superclass.setRequestParms(params);
  199. if (params) {
  200. if (params.preferencesChanged) {
  201. this.preferencesChanged = params.preferencesChanged;
  202. }
  203. if (params.MissingMemberRecoveryMode) {
  204. this._oMissingMemberRecoveryMode = params.MissingMemberRecoveryMode;
  205. }
  206. }
  207. };
  208. EditContentAction.prototype.runUpdatedReportFromBUA_MissingMemberRecoveryMode = function() {
  209. var buaWindow = this.getBUAWindow();
  210. var originalSpec = this.m_oCV.envParams["ui.spec"];
  211. var oContext = buaWindow.Application.GetBUAContext();
  212. this.m_oCV.setTracking(oContext.tracking);
  213. this.m_oCV.envParams["ui.spec"] = oContext.reportXML;
  214. this.m_oCV.setExecutionParameters(oContext.parameterValues);
  215. if (this._oMissingMemberRecoveryMode && this._oMissingMemberRecoveryMode.oFaultDialog) {
  216. this._oMissingMemberRecoveryMode.oFaultDialog.hide();
  217. }
  218. this._invokeRedrawAction(originalSpec);
  219. };
  220. EditContentAction.prototype.cancelPressed = function() {};
  221. EditContentAction.prototype.addWindowEventListeners = function() {
  222. if (window.attachEvent) {
  223. window.attachEvent("onresize", window.CVEditContentActionInstance.onWindowResize);
  224. }
  225. else {
  226. window.addEventListener("resize", window.CVEditContentActionInstance.onWindowResize, false);
  227. }
  228. };
  229. EditContentAction.prototype.removeWindowEventListeners = function() {
  230. if (window.detachEvent) {
  231. window.detachEvent("onresize", window.CVEditContentActionInstance.onWindowResize);
  232. }
  233. else {
  234. window.removeEventListener("resize", window.CVEditContentActionInstance.onWindowResize, false);
  235. }
  236. };
  237. EditContentAction.prototype.onWindowResize = function() {
  238. var containerObj = window.viewerCWAContainer;
  239. if (containerObj) {
  240. containerObj.resize();
  241. }
  242. };
  243. /**
  244. * Interface that CWA will call
  245. * @param eventType
  246. */
  247. function BUAEvent(eventType)
  248. {
  249. var editContentObj = window.CVEditContentActionInstance;
  250. switch (eventType)
  251. {
  252. case "appReady":
  253. editContentObj.setReportSettings();
  254. break;
  255. case "donePressed":
  256. editContentObj.hideCWAContainer();
  257. if (editContentObj._oMissingMemberRecoveryMode) {
  258. editContentObj.runUpdatedReportFromBUA_MissingMemberRecoveryMode();
  259. } else {
  260. editContentObj.runUpdatedReportFromBUA();
  261. }
  262. break;
  263. case "cancelPressed":
  264. editContentObj.cancelPressed();
  265. editContentObj.hideCWAContainer();
  266. break;
  267. }
  268. }