Permalink
Browse files

cache Bugzilla configuration

  • Loading branch information...
1 parent a94a6b9 commit a1afa366f6cb0805b1510a8eed87066dbc6e0d1e @harthur committed Mar 31, 2012
Showing with 61 additions and 43 deletions.
  1. +61 −43 fileit.js
View
104 fileit.js
@@ -1,47 +1,25 @@
$(document).ready(function() {
var bugzilla = bz.createClient();
+ var cachedConfig = localStorage["fileit-config"];
+ if (cachedConfig) {
+ populateAutocomplete(JSON.parse(cachedConfig));
+ }
+
bugzilla.getConfiguration({
flags: 0,
cached_ok: 1
},
function(err, config) {
- var components = [];
- for (product in config.product) {
- var comps = config.product[product].component;
- for (component in comps) {
- components.push({
- product: product,
- component: component,
- string: componentName({product: product, component: component})
- });
- }
- }
-
- var input = $(".component-search, .new-component");
- input.autocomplete({
- list: components,
- minCharacters: 2,
- timeout: 200,
- adjustWidth: 350,
- template: function(item) {
- return "<li value='" + item.string + "'><span class='product'>"
- + item.product + "</span>" + "<span class='component'>"
- + item.component + "</span></li>";
- },
- matcher: function(typed) {
- return typed;
- },
- match: function(item, matcher) {
- var words = matcher.split(/\s+/);
- return _(words).all(function(word) {
- return item.string.toLowerCase().indexOf(word.toLowerCase()) >= 0;
- });
- },
- insertText: function(item) {
- return item.string;
- }
- });
+ if (err) {
+ throw "Error getting Bugzilla configuration: " + err;
+ }
+ if (config) {
+ localStorage["fileit-config"] = JSON.stringify(config);
+ if (!cachedConfig) {
+ populateAutocomplete(config);
+ }
+ }
});
$("#file-form").submit(function(event) {
@@ -54,10 +32,50 @@ $(document).ready(function() {
});
});
- function componentName(comp) {
- return comp.product + "/" + comp.component;
- }
-
- function toComponent (name) {
- return name.split("/");
- }
+
+function populateAutocomplete(config) {
+ var components = [];
+ for (product in config.product) {
+ var comps = config.product[product].component;
+ for (component in comps) {
+ components.push({
+ product: product,
+ component: component,
+ string: componentName({product: product, component: component})
+ });
+ }
+ }
+
+ var input = $(".component-search, .new-component");
+ input.autocomplete({
+ list: components,
+ minCharacters: 2,
+ timeout: 200,
+ adjustWidth: 360,
+ template: function(item) {
+ return "<li value='" + item.string + "'><span class='product'>"
+ + item.product + "</span>" + "<span class='component'>"
+ + item.component + "</span></li>";
+ },
+ matcher: function(typed) {
+ return typed;
+ },
+ match: function(item, matcher) {
+ var words = matcher.split(/\s+/);
+ return _(words).all(function(word) {
+ return item.string.toLowerCase().indexOf(word.toLowerCase()) >= 0;
+ });
+ },
+ insertText: function(item) {
+ return item.string;
+ }
+ });
+}
+
+function componentName(comp) {
+ return comp.product + "/" + comp.component;
+}
+
+function toComponent (name) {
+ return name.split("/");
+}

0 comments on commit a1afa36

Please sign in to comment.