FindNextOnServerAction.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2013
  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. * FindNextOnServerAction
  14. */
  15. function FindNextOnServerAction() {
  16. this.m_requestParams = null;
  17. this.m_sAction = 'findNextOnServer';
  18. }
  19. FindNextOnServerAction.prototype = new FindAction();
  20. FindNextOnServerAction.baseclass = FindAction.prototype;
  21. FindNextOnServerAction.prototype.setRequestParms = function(params)
  22. {
  23. this.setConfigAndState();
  24. }
  25. FindNextOnServerAction.prototype.execute = function() {
  26. return this.sendRequest();
  27. }
  28. FindNextOnServerAction.prototype.sendRequest = function() {
  29. if (!this.findState) {
  30. return -1;
  31. }
  32. var cv = this.getCognosViewer();
  33. var request = new ViewerDispatcherEntry(cv);
  34. // Save the original complete callback
  35. this.originalCompleteCallback = request.getCallbacks()["complete"];
  36. request.setCallbacks( {
  37. "complete" : {"object" : this, "method" : this.onRequestComplete}
  38. });
  39. request.addFormField("ui.action", "reportAction");
  40. request.addFormField("generic.anyURI.http://developer.cognos.com/ceba/constants/runOptionEnum#pageNumber", this.findState.getPageNoForFindNext());
  41. request.addFormField("generic.anyURI.http://developer.cognos.com/ceba/constants/runOptionEnum#search", this.findState.getKeyword());
  42. request.addFormField("generic.boolean.http://developer.cognos.com/ceba/constants/runOptionEnum#caseSensitiveSearch", this.findState.isCaseSensitive());
  43. request.addFormField("generic.boolean.http://developer.cognos.com/ceba/constants/runOptionEnum#wrapAroundSearch", this.findState.isWrapAroundSearch());
  44. this.findState.findOnServerStarted();
  45. return cv.dispatchRequest(request);
  46. }
  47. FindNextOnServerAction.prototype.onRequestComplete = function(response) {
  48. var status = response.getAsynchStatus();
  49. var callbackFunc = GUtil.generateCallback(this.originalCompleteCallback.method, [response], this.originalCompleteCallback.object);
  50. if (status === "complete") {
  51. var sHTML = response.getResult();
  52. if (sHTML && sHTML.length > 0) {
  53. // Status is complete and we have HTML which means a match was found.
  54. // Call the original callback function so the report HTML and state get updated.
  55. callbackFunc();
  56. setTimeout(GUtil.generateCallback(this.processResponse,[true], this),100);
  57. }
  58. else {
  59. // No HTML returned so a match wasn't found on the server, don't call the original 'complete'
  60. // callback since we don't want to get rid of the report page that's currently being displayed
  61. setTimeout(GUtil.generateCallback(this.processResponse,[false], this),100);
  62. }
  63. }
  64. else {
  65. callbackFunc();
  66. }
  67. };
  68. /**
  69. * Server returns a page where matches are found or empty page if no matches are found.
  70. * CognosViewer processResponse* functions already have taken care about the returned page.
  71. *
  72. * In this action, two things are to be done.
  73. * 1) update local state
  74. * 2) perform local search to highlight
  75. *
  76. */
  77. FindNextOnServerAction.prototype.processResponse = function(found) {
  78. this.setConfigAndState();
  79. if (!this.findState) {
  80. return false;
  81. }
  82. this.findState.findOnServerDone();
  83. if (found) {
  84. this.clearPreviousResult(false);
  85. if ( this.findAndShow()) {
  86. if (this.findState.isRepeating()) {
  87. var callback= this.findConfig.getFindActionCompleteCallback();
  88. callback();
  89. }
  90. }
  91. } else {
  92. var callback = this.findState.foundMatchesInReport() ?
  93. this.findConfig.getFindActionCompleteCallback() :
  94. this.findConfig.getNoMatchFoundCallback() ;
  95. callback();
  96. };
  97. return true;
  98. }