1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/* 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.
*/
// Product and component search to file a new bug
YUI({
base: 'js/yui3/',
combine: false
}).use("node", "json-stringify", "autocomplete", "escape",
"datasource-io", "datasource-jsonschema", "array-extras", function (Y) {
var counter = 0,
format = '',
cloned_bug_id = '',
dataSource = null,
autoComplete = null;
var resultListFormat = function(query, results) {
Y.log(results);
return Y.Array.map(results, function (result) {
var data = result.raw;
return Y.Escape.html(data.product) + " :: " +
Y.Escape.html(data.component);
});
};
var dataSource = new Y.DataSource.IO({
source: 'jsonrpc.cgi',
ioConfig: {
method: "POST",
headers: { 'Content-Type': 'application/json' }
}
});
dataSource.plug(Y.Plugin.DataSourceJSONSchema, {
schema: {
resultsListLocator : "result.products",
resultFields : [ "product", "component" ]
}
});
var input = Y.one('#prod_comp_search');
input.plug(Y.Plugin.AutoComplete, {
enableCache: true,
source: dataSource,
minQueryLength: 3,
queryDelay: 0.05,
resultFormatter: resultListFormat,
maxResultsDisplayed: 25,
suppressInputUpdate: true,
maxResults: 25,
requestTemplate: function (query) {
counter = counter + 1;
var json_object = {
version: "1.1",
method : "MyDashboard.prod_comp_search",
id : counter,
params : { search: query }
};
return Y.JSON.stringify(json_object);
},
// resultListLocator: 'response.result.products',
// resultListLocator: 'result.products'
// resultListLocator: function (response) {
// Y.log(response);
// return (response && response.data && response.data.result.products) || [];
// },
// // Makes sure an array is returned even on an error.
// if (response.error) {
// return [];
// }
//
// Y.log(response);
//
// return response.query.results;
//
// return [{
// product: "Foo",
// component: "Bar"
// }];
// var query = response.query.results.json,
// addresses;
//
// if (query.status !== 'OK') {
// return [];
// }
//
// // Grab the actual addresses from the YQL query.
// addresses = query.results;
//
// // Makes sure an array is always returned.
// return addresses.length > 0 ? addresses : [addresses];
// },
});
input.ac.on('query', function() {
Y.one("#prod_comp_throbber").removeClass('bz_default_hidden');
});
input.ac.after('results', function() {
Y.one("#prod_comp_throbber").addClass('bz_default_hidden');
});
input.ac.on('select', function (itemNode, result) {
var url = "enter_bug.cgi?product=" + encodeURIComponent(result.component) +
"&component=" + encodeURIComponent(result.product);
Y.log(url);
//autoComplete.dataReturnEvent.subscribe(function(type, args) {
// args[0].autoHighlight = args[2].length == 1;
//});
// doBeforeLoadData: function(sQuery, oResponse, oPayload) {
// Y.one("#prod_comp_throbber").addClass('bz_default_hidden');
// return true;
// }
});
// autoComplete.textboxFocusEvent.subscribe(function () {
// var input = Y.one(field);
// if (input.value && input.value.length > 3) {
// sendQuery(input.value);
// }
// });
});
|