ViewerFindState.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. function ViewerFindState() {
  13. //PUBLIC API - Do not change. Start
  14. this.keyword = null;
  15. this.caseSensitive = false;
  16. this.wrapAroundSearch = true;
  17. //PUBLIC API - Do not change. End
  18. this.matches = null;
  19. this.focus_index = -1;
  20. this.matchesFoundInReport = false;
  21. this.matchesFoundOnServer = false;
  22. this.pageFirstMatchFound = -1; //used to detect repeating/looping pages
  23. this.matchesUpdateCount = 0;
  24. this.currentPageNo = -1;
  25. this.currentPageHasNext = false;
  26. this.currentPageHasPrev = false;
  27. this.findingOnServerInProgress = false;
  28. this.searchedOnServer = false;
  29. }
  30. ViewerFindState.prototype.setState = function(state) {
  31. applyJSONProperties(this, state);
  32. };
  33. /**
  34. * return page number to search from on server
  35. */
  36. ViewerFindState.prototype.getPageNoForFindNext = function() {
  37. if (!this.isSinglePageReport()) {
  38. this.currentPageNo++;
  39. }
  40. return this.currentPageNo;
  41. }
  42. /**
  43. * returns true if more pages to search exist
  44. */
  45. ViewerFindState.prototype.checkServerForNextMatch = function() {
  46. if (this.isSinglePageReport() ) {
  47. return false;
  48. }
  49. if (this.searchedOnServer && (!this.matches || this.matches.length ==0) ) {
  50. return false; //No matches in entire report
  51. }
  52. if (this.currentPageHasNext) {
  53. return true;
  54. }
  55. if (this.currentPageHasPrev && this.wrapAroundSearch) {
  56. return true;
  57. }
  58. return false;
  59. }
  60. ViewerFindState.prototype.isSinglePageReport = function() {
  61. return (this.currentPageNo == 1 && !this.currentPageHasNext && !this.currentPageHasPrev);
  62. }
  63. /**
  64. * called by CV response handler
  65. */
  66. ViewerFindState.prototype.findOnServerInProgress = function() {
  67. return this.findingOnServerInProgress;
  68. }
  69. /**
  70. * Sets a flag for CV response handler to key off server response for FindNext on server
  71. */
  72. ViewerFindState.prototype.findOnServerStarted = function() {
  73. this.findingOnServerInProgress = true;
  74. this.matchesFoundOnServer = false;
  75. this.searchedOnServer = true;
  76. }
  77. /**
  78. * Rests a flag for CV response handler to key off server response for FindNext on server
  79. */
  80. ViewerFindState.prototype.findOnServerDone = function() {
  81. this.findingOnServerInProgress = false
  82. }
  83. ViewerFindState.prototype.foundMatchesInReport = function() {
  84. return this.matchesFoundInReport;
  85. }
  86. /**
  87. * update current page info: matches, page no, has next page and has previous page
  88. */
  89. ViewerFindState.prototype.updatePageInfo = function(matches, currentPage, hasNextPage, hasPrevPage) {
  90. this.currentPageNo = currentPage;
  91. this.currentPageHasPrev = hasPrevPage;
  92. this.currentPageHasNext = hasNextPage;
  93. this.matches = matches;
  94. this.focus_index = -1;
  95. if (matches && matches.length>0) {
  96. this.matchesFoundInReport = true;
  97. this.matchesUpdateCount++;
  98. if (this.pageFirstMatchFound ==-1) {
  99. this.pageFirstMatchFound = currentPage;
  100. }
  101. }
  102. }
  103. ViewerFindState.prototype.resetPageInfo = function() {
  104. this.updatePageInfo(null, -1, false, false);
  105. }
  106. /**
  107. * returns matches
  108. */
  109. ViewerFindState.prototype.getMatches = function() {
  110. return this.matches;
  111. }
  112. /**
  113. * returns first element in matches
  114. */
  115. ViewerFindState.prototype.firstMatch = function() {
  116. if (this.matches && this.matches.length > 0 ) {
  117. this.focus_index = 0;
  118. return this.matches[this.focus_index];
  119. }
  120. return null;
  121. }
  122. /**
  123. * returns next item in matches
  124. */ViewerFindState.prototype.nextMatch = function() {
  125. if (this.matches && this.matches.length > (this.focus_index+1) ) {
  126. return this.matches[++this.focus_index];
  127. }
  128. return null;
  129. }
  130. /**
  131. * returns true if currently focused item is not the last item in matches
  132. */
  133. ViewerFindState.prototype.hasNext = function() {
  134. return (this.matches && this.matches.length > (this.focus_index+1) );
  135. }
  136. /**
  137. * returns item to be focused
  138. */
  139. ViewerFindState.prototype.getFocusedMatch = function() {
  140. if (this.matches && this.matches.length>0 && this.focus_index >=0) {
  141. return this.matches[this.focus_index];
  142. }
  143. return null;
  144. }
  145. /**
  146. * returns keyword input
  147. */
  148. ViewerFindState.prototype.getKeyword = function() {
  149. return this.keyword;
  150. }
  151. /**
  152. * returns caseSensitive input
  153. */
  154. ViewerFindState.prototype.isCaseSensitive = function() {
  155. return this.caseSensitive;
  156. }
  157. /**
  158. * returns wrapAroundSearch input
  159. */
  160. ViewerFindState.prototype.isWrapAroundSearch = function() {
  161. return this.wrapAroundSearch;
  162. }
  163. /**
  164. * returns true if current page is same as the page first match was found
  165. */
  166. ViewerFindState.prototype.isRepeating = function() {
  167. if (this.isSinglePageReport()) {
  168. return this.pageFirstMatchFound == this.currentPageNo;
  169. } else {
  170. return (this.pageFirstMatchFound == this.currentPageNo && this.matchesUpdateCount>1);
  171. }
  172. };