Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added category to place

  • Loading branch information...
commit 8976bcfc247a65329a9ff7f6ddb0da0b5bf49048 1 parent e43f47c
@pmelzer pmelzer authored
View
1  .gitignore
@@ -9,5 +9,6 @@
/static/css/*.r*.css
/geocamCover/build
/geocamUtil
+/geocamUtilWeb
/.idea
*.db
View
14 geocamCover/models.py
@@ -8,19 +8,31 @@
from django.contrib.auth.models import User
from datetime import datetime
+CATEGORIES = (
+ (0, ''),
+ (1, 'Hospital'),
+ (2, 'Gas Station'),
+ (3, 'Place of Worship'),
+)
+
class Place(models.Model):
name = models.CharField(max_length=200, blank=True)
longitude = models.FloatField(null=True)
latitude = models.FloatField(null=True)
+ category = models.IntegerField(max_length=1, choices=CATEGORIES)
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User)
+ @staticmethod
+ def get_categories():
+ return CATEGORIES
+
def __unicode__(self):
return self.name
def get_struct(self):
- return {"id": self.id, "name": self.name, "latitude": self.latitude, "longitude": self.longitude}
+ return {"id": self.id, "name": self.name, "latitude": self.latitude, "longitude": self.longitude, "category": self.category}
class Task(models.Model):
View
31 geocamCover/static/geocamCover/app.js
@@ -29,6 +29,7 @@ function Place() {
this.reports = [];
this.tasks = [];
this.marker = null;
+ this.category = null;
}
var places = [];
@@ -42,7 +43,9 @@ $(window).resize(function() {
});
$(document).ready(function () {
-
+
+ populateCategories();
+
//MOFFETT FIELD COORDINATES
var latlng = new google.maps.LatLng(37.41288, -122.052934);
$('#map_canvas').gmap({
@@ -57,6 +60,7 @@ $(document).ready(function () {
place.id = val.place.id;
place.position = latlng;
place.name = val.place.name;
+ place.category = val.place.category;
for (var t in val.tasks) {
t = val.tasks[t];
@@ -109,14 +113,16 @@ $(document).ready(function () {
var place;
if (e.target.id == "edit-place-page-form") {
place = selectedPlace;
+ place.category = $('#edit-categories-select').val();
} else if (e.target.id == "place-form-form") {
place = new Place();
place.position = clicked_position;
+ place.category = $('#categories-select').val();
}
place.name = $(this).find('.name').val();
var new_place = JSON.stringify({"place_id": place.id, "latitude": place.position.lat(),
- "longitude": place.position.lng(), "name": place.name });
+ "longitude": place.position.lng(), "name": place.name, "category": place.category });
$.post('/geocamCover/place/', new_place, function(data) {
place.id = data;
places[place.id] = place;
@@ -125,8 +131,10 @@ $(document).ready(function () {
});
$(this).find('.name').val("");
-
- hidePlaceForm();
+ $('#categories-select').val("0");
+ $('#categories-select').parent().find('.ui-btn-text').empty();
+
+ hidePlaceForm();
return false;
});
@@ -200,6 +208,18 @@ $(document).ready(function () {
});
+function populateCategories() {
+ $.getJSON('/geocamCover/categories.json', function(data) {
+ categoriesSelect = $('#categories-select');
+ editCategoriesSelect = $('#edit-categories-select');
+ $.each(data, function(key, val) {
+ var elem = '<option value="' + key + '">' + val + '</option>';
+ categoriesSelect.append(elem);
+ editCategoriesSelect.append(elem);
+ });
+ });
+}
+
function deletePlace() {
var c = confirm("Are you sure?");
@@ -322,7 +342,8 @@ function showEditPlace() {
$('#edit-place-page a').removeClass("ui-btn-active");
$("#edit-place-page h1 .name").html(selectedPlace.name.length == 0 ? "Unnamed Place" : selectedPlace.name);
$("#edit-place-page form .name").val(selectedPlace.name);
-
+ $("#edit-categories-select").val(selectedPlace.category);
+ $("#edit-categories-select").parent().find(".ui-btn-text").html($("#edit-categories-select option:selected").text());
document.location.href = "/geocamCover/#edit-place-page";
}
View
2  geocamCover/templates/geocamCover/index.html
@@ -29,6 +29,7 @@
<form id="place-form-form">
<h1>Do you want to add this as a place?</h1>
<input style='width:95%' class="name" type="text" placeholder="Place Name... (optional)"/>
+ <select id="categories-select"></select>
<input type="submit" value="Add Place"/>
<input type="button" value="Back to Map" onclick="hidePlaceForm();"/>
</form>
@@ -152,6 +153,7 @@ <h1 class='name'></h1>
<div data-role="content">
<form id="edit-place-page-form">
<input type='text' class='name' placeholder="Name"/>
+ <select id="edit-categories-select"></select>
<input type="submit" value="Update Place"/>
</form>
View
1  geocamCover/urls.py
@@ -9,6 +9,7 @@
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
+ url(r'^categories.json$', views.categories_json),
url(r'^places.json$', views.places_json),
url(r'^place/$', views.place),
url(r'^delete_item/$', views.delete_item),
View
9 geocamCover/views.py
@@ -42,6 +42,14 @@ def places_json(request):
places = json.dumps(place_hash, sort_keys=True, indent=4)
return HttpResponse(places, mimetype="application/json")
+def categories_json(request):
+ categories_enum = Place.get_categories()
+ categories_hash = {}
+ for id, category in categories_enum:
+ categories_hash[id] = category
+ categories = json.dumps(categories_hash, sort_keys=True, indent=4)
+ return HttpResponse(categories, mimetype="application/json")
+
def place(request):
if request.method == 'POST':
@@ -51,6 +59,7 @@ def place(request):
if struct['place_id'] != None:
place = Place.objects.get(id=struct['place_id'])
place.name = struct['name']
+ place.category = struct['category']
place.latitude = struct['latitude']
place.longitude = struct['longitude']
place.created_by = user
Please sign in to comment.
Something went wrong with that request. Please try again.