From 95052864ee662a67639a3080b3ecf7a1e24ba9e3 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Thu, 24 May 2012 12:57:14 -0400 Subject: Bug 747193 - Add search field to product chooser to allow selecting product/component based on keyword search r=glob --- extensions/BMO/web/js/choose_product.js | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 extensions/BMO/web/js/choose_product.js (limited to 'extensions/BMO/web/js') diff --git a/extensions/BMO/web/js/choose_product.js b/extensions/BMO/web/js/choose_product.js new file mode 100644 index 000000000..7298a6b92 --- /dev/null +++ b/extensions/BMO/web/js/choose_product.js @@ -0,0 +1,69 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. + */ + +YAHOO.bugzilla.prodCompSearch = { + counter : 0, + format : '', + dataSource : null, + generateRequest : function (enteredText) { + YAHOO.bugzilla.prodCompSearch.counter = YAHOO.bugzilla.prodCompSearch.counter + 1; + YAHOO.util.Connect.setDefaultPostHeader('application/json', true); + var json_object = { + method : "BMO.prod_comp_search", + id : YAHOO.bugzilla.prodCompSearch.counter, + params : [ { + search : decodeURIComponent(enteredText) + } ] + }; + return YAHOO.lang.JSON.stringify(json_object); + }, + resultListFormat : function(oResultData, enteredText, sResultMatch) { + var url = "enter_bug.cgi?product=" + encodeURIComponent(oResultData[0]) + + "&component=" + encodeURIComponent(oResultData[1]); + if (YAHOO.bugzilla.prodCompSearch.format) { + url = url + "&format=" + encodeURIComponent(YAHOO.bugzilla.prodCompSearch.format); + } + return ("" + + _escapeHTML(oResultData[0]) + " :: " + + _escapeHTML(oResultData[1]) + ""); + }, + init_ds : function(){ + this.dataSource = new YAHOO.util.XHRDataSource("jsonrpc.cgi"); + this.dataSource.connTimeout = 30000; + this.dataSource.connMethodPost = true; + this.dataSource.connXhrMode = "cancelStaleRequests"; + this.dataSource.maxCacheEntries = 5; + this.dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; + this.dataSource.responseSchema = { + resultsList : "result.products", + metaFields : { error: "error", jsonRpcId: "id"}, + fields : [ "product", "component" ] + }; + }, + init : function( field, container, format) { + if( this.dataSource == null ){ + this.init_ds(); + } + this.format = format; + var prodCompSearch = new YAHOO.widget.AutoComplete(field, container, this.dataSource); + prodCompSearch.generateRequest = this.generateRequest; + prodCompSearch.formatResult = this.resultListFormat; + prodCompSearch.minQueryLength = 3; + prodCompSearch.autoHighlight = false; + prodCompSearch.queryDelay = 0.05; + prodCompSearch.useIFrame = true; + prodCompSearch.maxResultsDisplayed = 25; + prodCompSearch.suppressInputUpdate = true; + prodCompSearch.textboxFocusEvent.subscribe(function () { + var input = YAHOO.util.Dom.get(field); + if (input.value && input.value.length > 3) { + this.sendQuery(input.value); + } + }); + } +} -- cgit v1.2.3-24-g4f1b