function Brewery (opts) {
  this.name = opts.name;
  this.id = opts.id;
}

Brewery.all = [];

//TODO: Perhaps move this function to the server side (server reads our json file?).
Brewery.getAll = function() {
  $.getJSON('/data/breweries.json', function(data) {
    Brewery.loadById(data);
    localStorage.breweries = JSON.stringify(data);
  });
};

//TODO: Perhaps move this function to the server side (server reads our json file?).
Brewery.loadById = function(data) {
  Brewery.all = data.map(function(ele) {
    return new Brewery(ele);
  });
};

Brewery.requestLocationById = function(id) {
  //TODO: Refactor by passing in an id rather than iterating over Brewery.all
  Brewery.all.forEach(function(b) {
    var breweryId = b.id;
    $.get('/locations/' + breweryId, function(data) {
      console.log(data);
    });
  });
};

Brewery.requestSocialById = function(id) {
  //TODO: Refactor by passing in an id rather than iterating over Brewery.all
  Brewery.all.forEach(function(b) {
    var breweryId = b.id;
    $.get('/socialaccounts/' + breweryId, function(data) {
      console.log(data);
    });
  });
};

Brewery.getAll();
Brewery.requestLocationById();
Brewery.requestSocialById();

@@ -1,16 +1,39 @@
+(function(module) %7B%0A%0A  
 function Brewery
@@ -42,16 +42,18 @@
 opts) %7B%0A
+  
   this.n
@@ -69,16 +69,18 @@
 s.name;%0A
+  
   this.i
@@ -96,11 +96,15 @@
 id;%0A
+  
 %7D%0A%0A
+  
 Brew
@@ -118,16 +118,18 @@
  = %5B%5D;%0A%0A
+  
 //TODO: 
@@ -197,32 +197,34 @@
 ur json file?).%0A
+  
 Brewery.getAll =
@@ -237,16 +237,18 @@
 ion() %7B%0A
+  
   $.getJ
@@ -296,16 +296,18 @@
 ) %7B%0A    
+  
 Brewery.
@@ -318,24 +318,26 @@
 ById(data);%0A
+  
     localSto
@@ -375,26 +375,32 @@
 (data);%0A
+  
   %7D);%0A
+  
 %7D;%0A%0A
+  
 //TODO: 
@@ -476,16 +476,18 @@
 file?).%0A
+  
 Brewery.
@@ -514,16 +514,18 @@
 data) %7B%0A
+  
   Brewer
@@ -561,16 +561,18 @@
 ) %7B%0A    
+ 
+ 
 return n
@@ -588,26 +588,32 @@
 y(ele);%0A
+  
   %7D);%0A
+  
 %7D;%0A%0A
+  
 Brewery.
@@ -641,32 +641,34 @@
  function(id) %7B%0A
+  
   //TODO: Refact
@@ -721,32 +721,34 @@
 ver Brewery.all%0A
+  
   Brewery.all.fo
@@ -763,32 +763,34 @@
 nction(b) %7B%0A    
+ 
+ 
 var breweryId = 
@@ -787,32 +787,34 @@
 eweryId = b.id;%0A
+  
     $.get('/loca
@@ -843,32 +843,34 @@
 unction(data) %7B%0A
+  
       console.lo
@@ -878,38 +878,46 @@
 (data);%0A    
+  
 %7D);%0A
+  
   %7D);%0A
+  
 %7D;%0A%0A
+  
 Brewery.requ
@@ -947,16 +947,18 @@
 n(id) %7B%0A
+  
   //TODO
@@ -1027,16 +1027,18 @@
 ery.all%0A
+  
   Brewer
@@ -1065,24 +1065,26 @@
 on(b) %7B%0A    
+  
 var breweryI
@@ -1089,24 +1089,26 @@
 yId = b.id;%0A
+  
     $.get('/
@@ -1150,24 +1150,26 @@
 ion(data) %7B%0A
+  
       consol
@@ -1189,22 +1189,593 @@
     
+  
 %7D);%0A  
+ 
+ 
 %7D);%0A
+  
 %7D;%0A%0A
+  Brewery.loadBreweryNames = function(name) %7B%0A    Brewery.all.forEach(function(brew) %7B%0A      var breweryName = brew.name;%0A      $.get('/locations/' + breweryName, function(data) %7B%0A        console.log(data);%0A      %7D);%0A    %7D);%0A  %7D;%0A%0A  Brewery.searchFieldComplete = function() %7B%0A    console.log('autocomplete ready!');%0A    $('#brew-search-input').autocomplete(%0A      %7B%0A        source: Brewery.all.map(function(obj) %7B%0A          return obj.name;%0A        %7D),%0A        minLength: 3%0A      %7D%0A    );%0A  %7D;%0A  $('#brew-search-input').on('focus', Brewery.searchFieldComplete);%0A%0A  
 Brew
@@ -1784,24 +1784,26 @@
 y.getAll();%0A
+  
 Brewery.requ
@@ -1821,16 +1821,18 @@
 ById();%0A
+  
 Brewery.
@@ -1844,16 +1844,87 @@
 stSocialById();%0A
+  Brewery.loadBreweryNames();%0A%0A  module.Brewery = Brewery;%0A%7D(window));%0A

add jQuery UI autocomplete for searchable brewery names list