ViewerDispatcherEntry.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2012
  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. *******************************************************************************
  14. *** View DispatcherEntry.js for information on the dispatcher entry classes ***
  15. *******************************************************************************
  16. */
  17. function ViewerDispatcherEntry(oCV) {
  18. ViewerDispatcherEntry.baseConstructor.call(this, oCV);
  19. if (oCV) {
  20. ViewerDispatcherEntry.prototype.setDefaultFormFields.call(this);
  21. this.setCallbacks( {
  22. "complete" : {"object" : this, "method" : this.onComplete},
  23. "prompting" : {"object" : this, "method" : this.onPrompting},
  24. "cancel" : {"object" : this, "method" : this.onCancel}
  25. });
  26. }
  27. }
  28. ViewerDispatcherEntry.prototype = new ReportDispatcherEntry();
  29. ViewerDispatcherEntry.baseConstructor = ReportDispatcherEntry;
  30. ViewerDispatcherEntry.prototype.parent = ReportDispatcherEntry.prototype;
  31. ViewerDispatcherEntry.prototype.setDefaultFormFields = function() {
  32. var oCV = this.getViewer();
  33. var envParams = oCV.envParams;
  34. this.addFormField("cv.showFaultPage", "true");
  35. this.addDefinedNonNullFormField("cv.header", envParams["cv.header"]);
  36. this.addDefinedNonNullFormField("cv.toolbar", envParams["cv.toolbar"]);
  37. this.addDefinedNonNullFormField("ui.backURL", envParams["ui.backURL"]);
  38. this.addDefinedNonNullFormField("errURL", envParams["ui.backURL"]);
  39. this.addDefinedNonNullFormField("errURL", envParams["ui.errURL"]);
  40. this.addDefinedNonNullFormField("cv.catchLogOnFault", "true");
  41. this.addDefinedNonNullFormField("m_sessionConv", envParams["m_sessionConv"]);
  42. // needed for legacy viewer portlet
  43. if (envParams["m_session"]) {
  44. this.addFormField("m_session", envParams["m_session"]);
  45. this.addFormField("cv.ignoreState", "true");
  46. }
  47. };
  48. ViewerDispatcherEntry.prototype.prepareRequest = function() {
  49. this.parent.prepareRequest.call(this);
  50. if(this.getUsePageRequest()) {
  51. this.m_oCV.setKeepSessionAlive(true);
  52. if (typeof this.m_oCV.envParams["cv.responseFormat"] != "undefined" && this.m_oCV.envParams["cv.responseFormat"] != null && this.m_oCV.envParams["cv.responseFormat"] != "") {
  53. this.addFormField("cv.responseFormat", this.m_oCV.envParams["cv.responseFormat"]);
  54. } else if (this.getFormField("cv.responseFormat") != "view") {
  55. this.addFormField("cv.responseFormat", "page");
  56. }
  57. var oPinFreezeManager = this.m_oCV.getPinFreezeManager();
  58. if (oPinFreezeManager && oPinFreezeManager.hasFrozenContainers()) {
  59. this.addFormField("pinFreezeInfo", oPinFreezeManager.toJSONString());
  60. }
  61. if (this.m_oCV.envParams["cv.createCallback"]) {
  62. this.addFormField("cv.createCallback", this.m_oCV.envParams["cv.createCallback"]);
  63. }
  64. }
  65. };
  66. ViewerDispatcherEntry.prototype.sendRequest = function(){
  67. // if we're not doing an ajax call then build and post a form
  68. if (this.getUsePageRequest()) {
  69. this.prepareRequest();
  70. var formRequest = this.buildRequestForm();
  71. if(typeof document.progress != "undefined") {
  72. setTimeout("document.progress.src=\"" + this.m_oCV.getSkin() + "/branding/progress.gif" + "\";", 1);
  73. }
  74. formRequest.submit();
  75. } else {
  76. this.getViewer().closeContextMenuAndToolbarMenus();
  77. this.parent.sendRequest.call(this);
  78. }
  79. };
  80. ViewerDispatcherEntry.prototype.buildRequestForm = function() {
  81. var oCV = this.getViewer();
  82. var requestForm = document.createElement("form");
  83. requestForm.setAttribute("id", "requestForm");
  84. requestForm.setAttribute("name", "requestForm");
  85. requestForm.setAttribute("method", "post");
  86. requestForm.setAttribute("target", "_self");
  87. requestForm.setAttribute("action", oCV.getGateway());
  88. requestForm.style.display = "none";
  89. document.body.appendChild(requestForm);
  90. var formFields = this.getRequest().getFormFields();
  91. var formFieldNames = formFields.keys();
  92. for (var index = 0; index < formFieldNames.length; index++) {
  93. requestForm.appendChild(this.createHiddenFormField(formFieldNames[index], formFields.get(formFieldNames[index])));
  94. }
  95. // Loop through all the form field to send along any missing ones
  96. for(param in oCV.envParams) {
  97. if(!formFields.exists(param) && param != "cv.actionState") {
  98. requestForm.appendChild(this.createHiddenFormField(param, oCV.envParams[param]));
  99. }
  100. }
  101. return requestForm;
  102. };
  103. ViewerDispatcherEntry.prototype.createHiddenFormField = function(name, value) {
  104. var formField = document.createElement("input");
  105. formField.setAttribute("type", "hidden");
  106. formField.setAttribute("name", name);
  107. formField.setAttribute("id", name);
  108. formField.setAttribute("value", value);
  109. return(formField);
  110. };
  111. ViewerDispatcherEntry.prototype.onCancel = function() {
  112. var oCV = this.getViewer();
  113. // after a cancel we always need to set the status to complete
  114. oCV.setStatus("complete");
  115. // the cancel callback on the Viewer object is used to do a backURL.
  116. // only call it if ajax is off or the report hasn't shown up yet
  117. if (this.getUsePageRequest() || !oCV.isReportRenderingDone()) {
  118. oCV.executeCallback("cancel");
  119. }
  120. };
  121. ViewerDispatcherEntry.prototype.onFault = function(asynchResponse) {
  122. // currently fault callbacks are only set when we're in RS
  123. // so blank out of fault dialog and add in their callback
  124. if (this.getViewer().callbackExists("fault")) {
  125. this.getViewer().setSoapFault(asynchResponse.getSoapFault());
  126. this.getViewer().executeCallback("fault");
  127. }
  128. else {
  129. this.parent.onFault.call(this, asynchResponse);
  130. }
  131. };
  132. ViewerDispatcherEntry.prototype.onComplete = function(response) {
  133. var oCV = this.getViewer();
  134. oCV.saveBackJaxInformation(response);
  135. // we only need to clear the selection if the report had already been rendered once before,
  136. // otherwise we run into timing issues and the context menu doesn't show all the items
  137. if (oCV.isReportRenderingDone()) {
  138. this.getViewer().getSelectionController().resetSelections();
  139. }
  140. this.parent.onComplete.call(this, response);
  141. };
  142. ViewerDispatcherEntry.prototype.onPrompting = function(response) {
  143. var oCV = this.getViewer();
  144. oCV.updateSkipToNavigationLink(true);
  145. // Report Studio sets up a prompt callback, if it's not there
  146. // then treat prompting as complete
  147. if (!oCV.executeCallback("prompt")) {
  148. this.onComplete(response);
  149. }
  150. };
  151. ViewerDispatcherEntry.prototype.onEntryComplete = function(response) {
  152. if (this.getRequestHandler()) {
  153. // Need to keep the dispatcher entry around in case we have to resubmit in safe mode
  154. this.getRequestHandler().setDispatcherEntry(this);
  155. }
  156. this.parent.onEntryComplete.call(this, response);
  157. };