Permalink
Browse files

front end upto list

  • Loading branch information...
1 parent 11e6756 commit af9eb9d7f237c514c1bc73b56bf1632f339455c8 @efekarakus committed Jun 3, 2012
View
@@ -0,0 +1,29 @@
+
+
+import tornado.httpserver
+import tornado.ioloop
+import tornado.options
+import tornado.web
+import simplejson
+from QueryHandler import QueryHandler
+
+class AutocompleteHandler(tornado.web.RequestHandler):
+ @tornado.web.asynchronous
+ def get(self):
+
+ print self.request.arguments
+ if not self.request.arguments or self.request.arguments=={}:
+ self.render('index.html')
+ return
+ if not 'address' in self.request.arguments.keys():
+ self.render('index.html')
+ return
+ address = self.request.arguments['address'][0]
+ data = {
+ 'address': address
+ }
+ output = QueryHandler.get_addresses(data)
+
+ self.write(output)
+ self.flush()
+ self.finish()
View
@@ -1,10 +1,30 @@
+import simplejson, urllib
class QueryHandler(object):
+ PLACES_API_KEY = 'AIzaSyCRpvPaJ4jxbZOlAY_PJeneYdHuC_cR-yk'
+
+
@classmethod
def get_map(self, json):
"""Return the Google Maps API JSON Object."""
+ print json
map_json = {
'awesome': 'sauce'
}
- return map_json
+ return map_json
+
+ @classmethod
+ def get_addresses(self, json):
+ """Return the potential autocomplete addresses."""
+ address = json['address']
+ url = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%s&types=geocode&language=en&sensor=true&key=%s' % (address, self.PLACES_API_KEY)
+ google_results = simplejson.load(urllib.urlopen(url))
+ output = {
+ 'addresses': []
+ }
+ for location in google_results['predictions']:
+ description = location['description']
+ output['addresses'].append(description)
+ # endfor location
+ return output
View
@@ -10,22 +10,23 @@ class SearchHandler(tornado.web.RequestHandler):
def get(self):
if not self.request.arguments:
self.render('index.html')
+ return
address = self.request.arguments['address'][0]
bed = self.request.arguments['bed'][0]
food = self.request.arguments['food'][0]
medical = self.request.arguments['medical'][0]
- mental_health = {
- 'option1': self.request.arguments['mental-health[option1]'][0],
- 'option2': self.request.arguments['mental-health[option2]'][0]
- }
+ mental_health = self.request.arguments['mental-health'][0]
+ substance_abuse = self.request.arguments['substance-abuse'][0]
transportation = self.request.arguments['transportation'][0]
+
data = {
'address': address,
'bed': bed,
'food': food,
'medical': medical,
'mental-health': mental_health,
+ 'substance-abuse': substance_abuse,
'transportation': transportation
}
@@ -34,4 +35,4 @@ def get(self):
self.write(output)
self.flush()
- self.finish()
+ self.finish()
View
@@ -5,6 +5,8 @@
import os.path
from SearchHandler import SearchHandler
+from AutocompleteHandler import AutocompleteHandler
+from DetailsHandler import DetailsHandler
from tornado.options import define, options
define("port", default=8888, help="run on the given port", type=int)
@@ -13,6 +15,7 @@ class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", DefaultHandler),
+ (r"/find*",AutocompleteHandler),
(r"/search*", SearchHandler)
]
settings = dict(
View
@@ -161,22 +161,47 @@ form button.submit:hover, form checkbox {
cursor: pointer;
}
-form #checkbox-label-food {
+form #checkbox-label-bed {
margin-right: .5em;
- color: #72ac26;
+ color: #2B3352;
}
-form #checkbox-label-shelter {
+form #checkbox-label-food {
margin-right: .5em;
- color: #188db8;
+ color: #2B3352;
}
form #checkbox-label-medical {
-margin-right: .5em;
-color: #7E2217;
+ margin-right: .5em;
+ color: #2B3352;
+}
+
+form #checkbox-label-mental {
+ margin-right: .5em;
+ color: #2B3352;
+}
+
+form #checkbox-label-substance {
+ margin-right: .5em;
+ color: #2B3352;
+}
+
+form #radio-label-walk {
+ margin-right: .5em;
+ color: #2B3352;
+}
+
+form #radio-label-bus {
+ margin-right: .5em;
+ color: #2B3352;
}
-form #checkbox-label-food:hover, #checkbox-label-shelter:hover {
+form #radio-label-car {
+ margin-right: .5em;
+ color: #2B3352;
+}
+
+form #checkbox-label-bed:hover, form #checkbox-label-food:hover, form #checkbox-label-medical:hover, form #checkbox-label-mental:hover, form #checkbox-label-substance:hover, form #radio-label-walk:hover, form #radio-label-bus:hover, form #radio-label-car:hover {
cursor: pointer;
}
@@ -246,6 +271,20 @@ form #checkbox-label-food:hover, #checkbox-label-shelter:hover {
margin-bottom: 15px;
}
+div.autocomplete {
+ width: 700px;
+ margin: 0 auto;
+ font: normal 130% Helvetica, Arial, sans-serif;
+}
+
+ol.autocomplete {
+ list-style: none;
+}
+
+li.autocomplete:hover {
+ background: #8dc73f;
+}
+
.location-map-container {
height: 400px;
width: 680px;
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,22 @@
+(function(){
+ console.log('got into the function');
+ $.ajax({
+ url: '/search',
+ dataType: 'json',
+ data: {
+ 'address': '3801 Tower View Court',
+ 'bed': 'yes',
+ 'food': 'no',
+ 'medical': 'no',
+ 'mental-health': {
+ 'option1': 'yes',
+ 'option2': 'no'
+ },
+ 'transportation': 'walk'
+ },
+ success: function(data) {
+ console.log(data);
+ }
+ });
+
+})();
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,24 +1,105 @@
$(document).ready(function() {
+
+ $("#accordion").accordion();
+
$('#searchBTN').click( function() {
- $.ajax({
- url: '/search',
- dataType: 'json',
- type: "GET",
- data: {
- 'address': '3801 Tower View Court',
- 'bed': 'yes',
- 'food': 'no',
- 'medical': 'no',
- 'mental-health': {
- 'option1': 'yes',
- 'option2': 'no'
- },
- 'transportation': 'walk'
- },
- success: function(data) {
- console.log(data);
- }
- });
- return false;
+ $.ajax({
+ url: '/search',
+ dataType: 'json',
+ type: "GET",
+ data: json(),
+ success: function(data) {
+ console.log(data);
+ listDisplay(data);
+ }
});
+ return false;
+ });
+
+ $('#addressbar').keyup( function(e) {
+ if (e.currentTarget.value==='') {
+ $('#autocomplete-results').html('');
+ }
+
+ window.setTimeout(function() {
+ $.ajax({
+ url: '/find',
+ dataType: 'json',
+ type: 'GET',
+ data: {
+ 'address': e.currentTarget.value
+ },
+ success: function(data) {
+ var autocomplete = $('#autocomplete-results').html('');
+ var content = "<ol class=\"autocomplete\">";
+ var index = 0;
+ for (index=0; index < data['addresses'].length; index++) {
+ content += "<li class=\"autocomplete\" onclick=\"replaceAddress(\'"+data['addresses'][index]+"\')\">"+data['addresses'][index]+"</li>";
+ }
+ content += "</ol>";
+ console.log(content);
+ autocomplete.append(content);
+ }
+ });
+ }, 200);
+
+ });
+
});
+
+var JSONobj;
+
+var json = function createJSON() {
+ var a = $('#addressbar');
+ if(!(a.val().length > 0)) {
+ alert('Please enter your address.');
+ }
+
+ var bedVal = check("#checkbox-bed");
+ var foodVal = check("#checkbox-food");
+ var medVal = check("#checkbox-medical");
+ var mentVal = check("#checkbox-mental");
+ var subVal = check("#checkbox-substance");
+
+ JSONobj = {
+ "address" : a.val(),
+ "bed" : bedVal,
+ "food" : foodVal,
+ "medical" : medVal,
+ "mental-health" : mentVal,
+ "substance-abuse" : subVal,
+ "transportation" : $('input[name=trans]:checked').val()
+ };
+ return JSONobj;
+}
+
+function check(id) {
+ var isChecked = $(id).attr('checked') ? true : false;
+ if (isChecked) {
+ return "true";
+ }
+ else {
+ return "false";
+ }
+}
+
+function listDisplay(searchResults) {
+ var selectbox = $('#accordion').html('');
+ var content = "";
+
+ content += "<h3><a href=\"#\">First header</a></h3>";
+ content += "<div>First content</div>";
+ content += "<h3><a href=\"#\">Second header</a></h3>";
+ content += "<div>Second content</div>";
+
+ selectbox.append(content);
+}
+
+
+
+function replaceAddress(address) {
+ var $ab = $('#addressbar');
+ $ab.attr('value', address);
+}
+
+
Oops, something went wrong.

0 comments on commit af9eb9d

Please sign in to comment.