Mercurial > bugzilla-dashboard
annotate js/bugzilla.js @ 72:0eab9a3ff12f
replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 25 Apr 2010 18:21:34 -0700 |
parents | 51c1829956d9 |
children | d1f7c1d38abe |
rev | line source |
---|---|
0 | 1 var Bugzilla = { |
2 BASE_URL: "https://api-dev.bugzilla.mozilla.org/latest", | |
3 BASE_UI_URL: "https://bugzilla.mozilla.org", | |
4 DEFAULT_OPTIONS: { | |
5 method: "GET" | |
6 }, | |
7 getShowBugURL: function Bugzilla_getShowBugURL(id) { | |
8 return this.BASE_UI_URL + "/show_bug.cgi?id=" + id; | |
9 }, | |
10 queryString: function Bugzilla_queryString(data) { | |
11 var parts = []; | |
12 for (name in data) { | |
13 var values = data[name]; | |
14 if (!values.forEach) | |
15 values = [values]; | |
16 values.forEach( | |
17 function(value) { | |
18 parts.push(encodeURI(name) + "=" + encodeURI(value)); | |
19 }); | |
20 } | |
21 return parts.join("&"); | |
22 }, | |
23 ajax: function Bugzilla_ajax(options) { | |
24 var newOptions = {__proto__: this.DEFAULT_OPTIONS}; | |
25 for (name in options) | |
26 newOptions[name] = options[name]; | |
27 options = newOptions; | |
28 | |
29 function onLoad() { | |
30 options.success(JSON.parse(xhr.responseText)); | |
31 } | |
32 | |
69
51c1829956d9
Added mock XHR object and a simple bugzilla ajax test
Atul Varma <avarma@mozilla.com>
parents:
18
diff
changeset
|
33 var xhr = options.xhr ? options.xhr : new XMLHttpRequest(); |
0 | 34 var url = this.BASE_URL + options.url; |
35 | |
36 if (options.data) | |
37 url = url + "?" + this.queryString(options.data); | |
38 xhr.open(options.method, url); | |
39 xhr.setRequestHeader("Accept", "application/json"); | |
40 xhr.setRequestHeader("Content-Type", "application/json"); | |
41 xhr.addEventListener("load", onLoad, false); | |
42 xhr.send(null); | |
43 return xhr; | |
44 }, | |
45 getBug: function Bugzilla_getBug(id, cb) { | |
72
0eab9a3ff12f
replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
69
diff
changeset
|
46 return this.ajax({url: "/bug/" + id, |
0eab9a3ff12f
replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
69
diff
changeset
|
47 success: cb}); |
0 | 48 }, |
49 search: function Bugzilla_search(query, cb) { | |
72
0eab9a3ff12f
replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
69
diff
changeset
|
50 return this.ajax({url: "/bug", |
0eab9a3ff12f
replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
69
diff
changeset
|
51 data: query, |
0eab9a3ff12f
replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
69
diff
changeset
|
52 success: cb}); |
0 | 53 } |
54 }; |