search.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2008, 2011.
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  11. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  12. dojo.provide("com.ibm.cognos.admin.xts.search");
  13. dojo.require("com.ibm.cognos.admin.xts.Base");
  14. dojo.require("com.ibm.cognos.admin.utils.misc");
  15. dojo.require("com.ibm.cognos.admin.utils.Menu");
  16. dojo.declare("com.ibm.cognos.admin.xts.search",com.ibm.cognos.admin.xts.Base,{
  17. constructor : function (){
  18. this.input={}; //input value from the UI
  19. this.fields = ["sfield","smethod","smodified","stype","sscope"];
  20. this.pagerParams = ["search_from","search_skip","search_to","sort_column","sort_order"];
  21. this.check={}; //list of fields and values need to be checked
  22. this.check.fields = ["stext","stype","smodified","sscope"]; //if meeting any of the checkpoints, it supposes to be specific
  23. this.check.values = ["","any","any","any"];
  24. this.menu=[];
  25. },
  26. initialize: function (){
  27. var self = this;
  28. this.inherited(arguments);
  29. // init group action button
  30. if (this.frag.parent) {
  31. var parentId = this.frag.parent.id;
  32. var divAction = dojo.byId(parentId + "search_action_disabled");
  33. var divActionDis = dojo.byId(parentId + "search_action");
  34. if (divAction && divActionDis){
  35. dojo.style(divActionDis, "display", (this.args.count > 0) ? "none" : "")
  36. dojo.style(divAction, "display", (this.args.count > 0) ? "" : "none");
  37. }
  38. }
  39. //init menu item
  40. dojo.forEach(this.args.menuModels, function(item){
  41. var captionId = item.captionId || item.id + "_caption";
  42. if (dojo.byId(self.getId(captionId))){
  43. self.menu[item.id] = (new com.ibm.cognos.admin.utils.Menu(item, self.frag.id)).getMenu();
  44. }
  45. });
  46. dojo.connect(dojo.byId(this.getId("stext")), "onkeypress", this, "_searchKeyHandler");
  47. },
  48. toggleDynamicSection: function() {
  49. com.ibm.cognos.admin.utils.misc.displayToggle(this.getId("searchCriteria"));
  50. var expand = dojo.byId(this.getId("expand"));
  51. var collapse = dojo.byId(this.getId("collapse"));
  52. if (collapse.style.display == 'none') {
  53. expand.style.display = 'none';
  54. collapse.style.display = '';
  55. } else {
  56. expand.style.display = '';
  57. collapse.style.display = 'none';
  58. }
  59. },
  60. _toggle: function(id){
  61. if (dojo.style(id, "display") == "none"){
  62. dojo.style(id, "display", "");
  63. } else {
  64. dojo.style(id, "display", "none");
  65. }
  66. },
  67. _searchKeyHandler: function(e){
  68. if (e.keyCode == dojo.keys.ENTER) {
  69. dojo.stopEvent(e);
  70. this.search();
  71. }
  72. },
  73. _isSpecific: function(){
  74. //summary
  75. // to detect if the current condition is specific enough to apply the search, at least one of the following needs to be met
  76. // 1. search key word is not empty
  77. // 2. a valid option is applied
  78. //tags
  79. // private
  80. //returns
  81. // Boolean
  82. for (var o in this.input){
  83. var i = dojo.indexOf(this.check.fields, o);
  84. if (i > -1 && this.input[o] != this.check.values[i]){
  85. return true;
  86. }
  87. }
  88. return false;
  89. },
  90. _getUrl: function(){
  91. var url = "";
  92. for (var o in this.input){
  93. url += "&" + o + "=" + this.input[o];
  94. }
  95. return url;
  96. },
  97. addInput: function(key, value){
  98. dojo.setObject(key, value, this.input);
  99. },
  100. clearInput: function(){
  101. this.input = {};
  102. },
  103. _getParams: function(){
  104. var self = this;
  105. //get search params
  106. this.addInput("stext", encodeURIComponent(dojo.byId(this.frag.id + "stext").value));
  107. this.addInput("bshowSearchCriteria", (dojo.byId(this.frag.id + "searchCriteria").style.display == "none")?"false":"true");
  108. dojo.forEach(self.fields, function(item){
  109. var elm = dojo.byId(self.frag.id + item);
  110. if (elm){
  111. self.addInput(item, elm.value);
  112. }
  113. });
  114. this.addInput("bshowNotSpecific", this._isSpecific()?"false":"true")
  115. //clean up the pager params, since every research need to reset the pager settings to initial status
  116. dojo.forEach(self.pagerParams, function(item){
  117. self.addInput(item, "");
  118. });
  119. },
  120. search: function(){
  121. this._getParams();
  122. this.frag.retrieve(this._getUrl());
  123. }
  124. });