// Licensed Materials - Property of IBM // // IBM Cognos Products: cogadmin // // (C) Copyright IBM Corp. 2008, 2011. // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // // // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated). dojo.provide("com.ibm.cognos.admin.xts.search"); dojo.require("com.ibm.cognos.admin.xts.Base"); dojo.require("com.ibm.cognos.admin.utils.misc"); dojo.require("com.ibm.cognos.admin.utils.Menu"); dojo.declare("com.ibm.cognos.admin.xts.search",com.ibm.cognos.admin.xts.Base,{ constructor : function (){ this.input={}; //input value from the UI this.fields = ["sfield","smethod","smodified","stype","sscope"]; this.pagerParams = ["search_from","search_skip","search_to","sort_column","sort_order"]; this.check={}; //list of fields and values need to be checked this.check.fields = ["stext","stype","smodified","sscope"]; //if meeting any of the checkpoints, it supposes to be specific this.check.values = ["","any","any","any"]; this.menu=[]; }, initialize: function (){ var self = this; this.inherited(arguments); // init group action button if (this.frag.parent) { var parentId = this.frag.parent.id; var divAction = dojo.byId(parentId + "search_action_disabled"); var divActionDis = dojo.byId(parentId + "search_action"); if (divAction && divActionDis){ dojo.style(divActionDis, "display", (this.args.count > 0) ? "none" : "") dojo.style(divAction, "display", (this.args.count > 0) ? "" : "none"); } } //init menu item dojo.forEach(this.args.menuModels, function(item){ var captionId = item.captionId || item.id + "_caption"; if (dojo.byId(self.getId(captionId))){ self.menu[item.id] = (new com.ibm.cognos.admin.utils.Menu(item, self.frag.id)).getMenu(); } }); dojo.connect(dojo.byId(this.getId("stext")), "onkeypress", this, "_searchKeyHandler"); }, toggleDynamicSection: function() { com.ibm.cognos.admin.utils.misc.displayToggle(this.getId("searchCriteria")); var expand = dojo.byId(this.getId("expand")); var collapse = dojo.byId(this.getId("collapse")); if (collapse.style.display == 'none') { expand.style.display = 'none'; collapse.style.display = ''; } else { expand.style.display = ''; collapse.style.display = 'none'; } }, _toggle: function(id){ if (dojo.style(id, "display") == "none"){ dojo.style(id, "display", ""); } else { dojo.style(id, "display", "none"); } }, _searchKeyHandler: function(e){ if (e.keyCode == dojo.keys.ENTER) { dojo.stopEvent(e); this.search(); } }, _isSpecific: function(){ //summary // to detect if the current condition is specific enough to apply the search, at least one of the following needs to be met // 1. search key word is not empty // 2. a valid option is applied //tags // private //returns // Boolean for (var o in this.input){ var i = dojo.indexOf(this.check.fields, o); if (i > -1 && this.input[o] != this.check.values[i]){ return true; } } return false; }, _getUrl: function(){ var url = ""; for (var o in this.input){ url += "&" + o + "=" + this.input[o]; } return url; }, addInput: function(key, value){ dojo.setObject(key, value, this.input); }, clearInput: function(){ this.input = {}; }, _getParams: function(){ var self = this; //get search params this.addInput("stext", encodeURIComponent(dojo.byId(this.frag.id + "stext").value)); this.addInput("bshowSearchCriteria", (dojo.byId(this.frag.id + "searchCriteria").style.display == "none")?"false":"true"); dojo.forEach(self.fields, function(item){ var elm = dojo.byId(self.frag.id + item); if (elm){ self.addInput(item, elm.value); } }); this.addInput("bshowNotSpecific", this._isSpecific()?"false":"true") //clean up the pager params, since every research need to reset the pager settings to initial status dojo.forEach(self.pagerParams, function(item){ self.addInput(item, ""); }); }, search: function(){ this._getParams(); this.frag.retrieve(this._getUrl()); } });