Skip to content
Browse files

Got the location list working and added Location Types

  • Loading branch information...
1 parent f608e07 commit 339b7d6824fa7ab0d50686710630f64bbc40ef6b Mark Ransom committed Feb 29, 2012
View
1 .gitignore
@@ -1,6 +1,7 @@
*.pyc
*.vim
*.swp
+*.swo
*.py~
*.html~
*.txt~
View
10 store_locator/admin.py
@@ -1,8 +1,8 @@
from django.contrib import admin, messages
from django.conf.urls.defaults import patterns, url
-from models import Location
+from models import Location, LocationType
from django.conf import settings
-from store_locator.views import get_lat_long
+from store_locator.views import get_lat_long, get_locations
class LocationAdmin(admin.ModelAdmin):
list_display = ('id','name','address','phone', 'url')
@@ -11,7 +11,7 @@ class LocationAdmin(admin.ModelAdmin):
fieldsets = (
(None, {
- 'fields': ('name',)
+ 'fields': ('name','location_type',)
}),
('Address', {
'fields': ('address', ('latitude', 'longitude'))
@@ -26,9 +26,11 @@ class Media:
def get_urls(self):
old_urls = super(LocationAdmin, self).get_urls()
new_urls = patterns('',
- url(r'^get_lat_long/$', get_lat_long)
+ url(r'^get_lat_long/$', get_lat_long, name='get_lat_long_url'),
+ url(r'^get_locations/$', get_locations, name='get_locations_url'),
)
return new_urls + old_urls
admin.site.register(Location, LocationAdmin)
+admin.site.register(LocationType)
View
10 store_locator/cms_plugins.py
@@ -3,7 +3,7 @@
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.core.urlresolvers import reverse
-from store_locator.models import StoreLocator
+from store_locator.models import StoreLocator, DISTANCE_CHOICES, LocationType
class StoreLocatorPlugin(CMSPluginBase):
"""Subclass of Text plugin, includes 'topic' & 'css' fields"""
@@ -13,13 +13,15 @@ class StoreLocatorPlugin(CMSPluginBase):
render_template = "store_locator/store_locator_map.html"
def render(self, context, instance, placeholder):
- get_lat_long_url = reverse('store_locator.views.get_lat_long')
- get_locations_url = reverse('store_locator.views.get_locations')
-
+ get_lat_long_url = reverse('admin:get_lat_long_url')
+ get_locations_url = reverse('admin:get_locations_url')
+ location_types = LocationType.objects.all()
context.update({
'get_lat_long_url': get_lat_long_url,
'get_locations_url': get_locations_url,
'instance': instance,
+ 'distance_choices': DISTANCE_CHOICES,
+ 'location_types': location_types,
})
return context
View
73 ...migrations/0004_auto__del_field_storelocator_distance__add_field_storelocator_default_.py
@@ -0,0 +1,73 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Deleting field 'StoreLocator.distance'
+ db.delete_column('cmsplugin_storelocator', 'distance')
+
+ # Adding field 'StoreLocator.default_distance'
+ db.add_column('cmsplugin_storelocator', 'default_distance', self.gf('django.db.models.fields.CharField')(default='10', max_length=50), keep_default=False)
+
+ # Adding field 'StoreLocator.start_location'
+ db.add_column('cmsplugin_storelocator', 'start_location', self.gf('django.db.models.fields.CharField')(default='', max_length=200, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Adding field 'StoreLocator.distance'
+ db.add_column('cmsplugin_storelocator', 'distance', self.gf('django.db.models.fields.IntegerField')(default=25), keep_default=False)
+
+ # Deleting field 'StoreLocator.default_distance'
+ db.delete_column('cmsplugin_storelocator', 'default_distance')
+
+ # Deleting field 'StoreLocator.start_location'
+ db.delete_column('cmsplugin_storelocator', 'start_location')
+
+
+ models = {
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+ 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ 'cms.placeholder': {
+ 'Meta': {'object_name': 'Placeholder'},
+ 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'store_locator.location': {
+ 'Meta': {'object_name': 'Location'},
+ 'address': ('django.db.models.fields.TextField', [], {'max_length': '255'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
+ 'longitude': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+ },
+ 'store_locator.storelocator': {
+ 'Meta': {'object_name': 'StoreLocator', 'db_table': "'cmsplugin_storelocator'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'default_distance': ('django.db.models.fields.CharField', [], {'default': "'10'", 'max_length': '50'}),
+ 'start_location': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['store_locator']
View
81 ...migrations/0005_auto__del_field_storelocator_start_location__add_field_storelocator_ad.py
@@ -0,0 +1,81 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Deleting field 'StoreLocator.start_location'
+ db.delete_column('cmsplugin_storelocator', 'start_location')
+
+ # Adding field 'StoreLocator.address'
+ db.add_column('cmsplugin_storelocator', 'address', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+ # Adding field 'StoreLocator.latitude'
+ db.add_column('cmsplugin_storelocator', 'latitude', self.gf('django.db.models.fields.FloatField')(null=True, blank=True), keep_default=False)
+
+ # Adding field 'StoreLocator.longitude'
+ db.add_column('cmsplugin_storelocator', 'longitude', self.gf('django.db.models.fields.FloatField')(null=True, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Adding field 'StoreLocator.start_location'
+ db.add_column('cmsplugin_storelocator', 'start_location', self.gf('django.db.models.fields.CharField')(default='', max_length=200, blank=True), keep_default=False)
+
+ # Deleting field 'StoreLocator.address'
+ db.delete_column('cmsplugin_storelocator', 'address')
+
+ # Deleting field 'StoreLocator.latitude'
+ db.delete_column('cmsplugin_storelocator', 'latitude')
+
+ # Deleting field 'StoreLocator.longitude'
+ db.delete_column('cmsplugin_storelocator', 'longitude')
+
+
+ models = {
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+ 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ 'cms.placeholder': {
+ 'Meta': {'object_name': 'Placeholder'},
+ 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'store_locator.location': {
+ 'Meta': {'object_name': 'Location'},
+ 'address': ('django.db.models.fields.TextField', [], {'max_length': '255'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
+ 'longitude': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+ },
+ 'store_locator.storelocator': {
+ 'Meta': {'object_name': 'StoreLocator', 'db_table': "'cmsplugin_storelocator'", '_ormbases': ['cms.CMSPlugin']},
+ 'address': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'default_distance': ('django.db.models.fields.CharField', [], {'default': "'10'", 'max_length': '50'}),
+ 'latitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+ 'longitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['store_locator']
View
79 ...migrations/0006_auto__del_field_storelocator_longitude__del_field_storelocator_address.py
@@ -0,0 +1,79 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Deleting field 'StoreLocator.longitude'
+ db.delete_column('cmsplugin_storelocator', 'longitude')
+
+ # Deleting field 'StoreLocator.address'
+ db.delete_column('cmsplugin_storelocator', 'address')
+
+ # Deleting field 'StoreLocator.latitude'
+ db.delete_column('cmsplugin_storelocator', 'latitude')
+
+ # Adding field 'StoreLocator.starting_location'
+ db.add_column('cmsplugin_storelocator', 'starting_location', self.gf('django.db.models.fields.CharField')(default='', max_length=255), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Adding field 'StoreLocator.longitude'
+ db.add_column('cmsplugin_storelocator', 'longitude', self.gf('django.db.models.fields.FloatField')(null=True, blank=True), keep_default=False)
+
+ # Adding field 'StoreLocator.address'
+ db.add_column('cmsplugin_storelocator', 'address', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+ # Adding field 'StoreLocator.latitude'
+ db.add_column('cmsplugin_storelocator', 'latitude', self.gf('django.db.models.fields.FloatField')(null=True, blank=True), keep_default=False)
+
+ # Deleting field 'StoreLocator.starting_location'
+ db.delete_column('cmsplugin_storelocator', 'starting_location')
+
+
+ models = {
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+ 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ 'cms.placeholder': {
+ 'Meta': {'object_name': 'Placeholder'},
+ 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'store_locator.location': {
+ 'Meta': {'object_name': 'Location'},
+ 'address': ('django.db.models.fields.TextField', [], {'max_length': '255'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
+ 'longitude': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+ },
+ 'store_locator.storelocator': {
+ 'Meta': {'object_name': 'StoreLocator', 'db_table': "'cmsplugin_storelocator'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'default_distance': ('django.db.models.fields.CharField', [], {'default': "'10'", 'max_length': '50'}),
+ 'starting_location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ }
+ }
+
+ complete_apps = ['store_locator']
View
77 store_locator/migrations/0007_auto__add_locationtype__add_field_location_location_type.py
@@ -0,0 +1,77 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding model 'LocationType'
+ db.create_table('store_locator_locationtype', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ))
+ db.send_create_signal('store_locator', ['LocationType'])
+
+ # Adding field 'Location.location_type'
+ db.add_column('store_locator_location', 'location_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['store_locator.LocationType'], null=True, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'LocationType'
+ db.delete_table('store_locator_locationtype')
+
+ # Deleting field 'Location.location_type'
+ db.delete_column('store_locator_location', 'location_type_id')
+
+
+ models = {
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+ 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ 'cms.placeholder': {
+ 'Meta': {'object_name': 'Placeholder'},
+ 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'store_locator.location': {
+ 'Meta': {'object_name': 'Location'},
+ 'address': ('django.db.models.fields.TextField', [], {'max_length': '255'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
+ 'location_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['store_locator.LocationType']", 'null': 'True', 'blank': 'True'}),
+ 'longitude': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+ },
+ 'store_locator.locationtype': {
+ 'Meta': {'object_name': 'LocationType'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ 'store_locator.storelocator': {
+ 'Meta': {'object_name': 'StoreLocator', 'db_table': "'cmsplugin_storelocator'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'default_distance': ('django.db.models.fields.CharField', [], {'default': "'10'", 'max_length': '50'}),
+ 'starting_location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ }
+ }
+
+ complete_apps = ['store_locator']
View
24 store_locator/models.py
@@ -49,7 +49,14 @@ def GetDistance(self, source_latitude, source_longitude, target_location):
return dist
+class LocationType(models.Model):
+ name = models.CharField(max_length=255)
+
+ def __unicode__(self):
+ return self.name
+
class Location(models.Model):
+ location_type = models.ForeignKey(LocationType, blank=True, null=True)
name = models.CharField(max_length=255)
address = models.TextField(max_length=255, blank=False)
latitude = models.FloatField(blank=False, null=True)
@@ -69,7 +76,18 @@ def __unicode__(self):
def get_single_line_address(self):
return self.address.replace('\n', ', ')
-
+
+DISTANCE_CHOICES = (
+ ('1', '1 Miles'),
+ ('5', '5 Miles'),
+ ('10', '10 Miles'),
+ ('15', '15 Miles'),
+ ('25', '25 Miles'),
+ ('50', '50 Miles'),
+ ('100', '100 Miles'),
+)
+
class StoreLocator(CMSPlugin):
- distance = models.IntegerField(default=25)
-
+ default_distance = models.CharField(max_length=50, default='10', choices=DISTANCE_CHOICES)
+ starting_location = models.CharField(max_length=255, help_text="A city or address to center the map on.")
+
View
9 store_locator/static/store_locator/js/store_locator_admin.js
@@ -1,8 +1,15 @@
$j = django.jQuery
+try {
+ get_lat_long_url = get_lat_long_url + '?q=';
+}
+catch(err) {
+ get_lat_long_url = window.location.href + '../get_lat_long/?q=';
+}
+
function get_lat_long() {
var address = $j(this).val();
- $j.get(window.location.href + "../get_lat_long/?q=" + address, function(data, code) {
+ $j.get(get_lat_long_url + address, function(data, code) {
$j("input#id_latitude").val(data.split(",")[2]);
$j("input#id_longitude").val(data.split(",")[3]);
});
View
80 store_locator/static/store_locator/js/store_locator_map.js
@@ -7,16 +7,22 @@ var zoom_list = {
"50" : 9,
"100" : 8,
}
+
var markers = new Array;
var latlng = new google.maps.LatLng(39.0997265,-94.5785667);
var myOptions = {
- zoom: 10,
+ zoom: zoom_list[starting_zoom],
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var infoWindow = new google.maps.InfoWindow();
var search_value = '';
+
+$(document).ready(function() {
+ location_search();
+});
+
document.map = map;
function clear_markers() {
for (i in markers) {
@@ -26,8 +32,11 @@ function clear_markers() {
}
function location_search() {
- clear_markers();
search_value = $("#locations_search_field").val();
+ if (search_value.trim() == '') {
+ search_value = starting_location;
+ }
+ clear_markers();
var distance = $("#distance_field").val();
var new_zoom = zoom_list[distance];
$.get(get_lat_long_url + "?q=" + search_value, function(data) {
@@ -41,26 +50,89 @@ function location_search() {
marker.setMap(map);
markers.push(marker);*/
map.setCenter(new google.maps.LatLng(latitude, longitude));
- $.getJSON(get_locations_url + "?lat=" + latitude + "&long=" + longitude + "&distance=" + distance, function(data) {
+ var search_params = {
+
+ "lat" : latitude,
+ "long" : longitude,
+ "distance" : distance,
+ "location_type" : $(".location_type:checked").val()
+ }
+ var search_url = get_locations_url;
+ $.getJSON(search_url, search_params, function(data) {
+ $(".location_list").children().remove();
$.each(data, function() {
location_info = this;
var location_marker = new google.maps.Marker({
position: new google.maps.LatLng(location_info.latitude, location_info.longitude),
title: location_info.name,
});
location_marker.setMap(map);
+ location_marker.location_id = location_info.id;
markers.push(location_marker);
google.maps.event.addListener(location_marker, "click", get_location_marker_click_listener(location_info, location_marker));
+ render_location(location_info);
});
});
});
}
+function render_location(location_info) {
+ var location_item = $("<li>");
+ var location_name = $("<a>", {
+ 'href': '#',
+ 'class': 'location_name',
+ html: location_info.name
+ });
+ $(location_name).click(function() {
+ var marker = markers.filter(function(marker) {
+ if (marker.location_id == location_info.id) {
+ return marker;
+ }
+ })[0];
+ google.maps.event.trigger(marker, "click");
+ return false;
+ });
+ $(location_item).append(location_name);
+ $(location_item).append(add_location_info_item(location_info, 'address'));
+ $(location_item).append(add_location_info_item(location_info, 'phone', 'Phone'));
+ if (location_info.url) {
+ var website = $("<a>", {html: location_info.url, "href": location_info.url});
+ $(location_item).append("<br />");
+ var location_website_item = $("<span>",{
+ 'class': 'location_url',
+ html: "Website: "
+ });
+ $(location_website_item).append(website);
+ $(location_item).append(location_website_item);
+ }
+ $(location_item).append(add_location_info_item(location_info, 'description', 'Description'));
+ $(".location_list").append(location_item);
+}
+
+function add_location_info_item(location_info, item_name, item_label) {
+ if (location_info[item_name] != '') {
+ var return_info = $("<span>");
+ $(return_info).append("<br />");
+ if (item_label) {
+ $(return_info).append($("<span>",{
+ 'class': 'location_' + item_name + '_label',
+ html: item_label + ": "
+ }));
+ }
+ $(return_info).append($("<span>",{
+ 'class': 'location_' + item_name,
+ html: location_info[item_name].replace(/\r/g, "<br />")
+ }));
+ return return_info;
+ }
+ console.log(location_info[item_name]);
+}
+
function get_location_marker_click_listener(location_info, location_marker) {
return function() {
content = "<strong>" + location_info.name + "</strong><br>" +
location_info.address.replace(/\n/g, '<br />') + "<br>" +
- "<a href='http://maps.google.com/maps?saddr=" + search_value + "&daddr=" + location_info.address + "'>Directions</a>";
+ "<a href='http://maps.google.com/maps?saddr=" + search_value + "&daddr=" + location_info.address.replace(/\r/g, ", ") + "'>Directions</a>";
if (location_info.url != '') {
content += "<br><strong>Website:</strong> <a href='" + location_info.url + "'>" + location_info.url + "</a>";
}
View
28 store_locator/templates/store_locator/store_locator_map.html
@@ -5,22 +5,34 @@
<form>
<input type="text" id="locations_search_field" />
<select id="distance_field">
- <option value="1">1 Mile</option>
- <option value="5">5 Miles</option>
- <option value="10">10 Miles</option>
- <option value="15">15 Miles</option>
- <option value="25" selected="selected">25 Miles</option>
- <option value="50">50 Miles</option>
- <option value="100">100 Miles</option>
+ {% for distance in distance_choices %}
+ <option value="{{ distance.0 }}" {% if instance.default_distance == distance.0 %}selected="selected"{% endif %}>{{ distance.1 }}</option>
+ {% endfor %}
</select>
<input type="submit" onClick="location_search(); return false;" value="Search" />
+ <ul class="location_types_list">
+ {% for type in location_types %}
+ <li>
+ <input name="location_type_{{ instance.id }}" type="radio" class="location_type" id="type_{{ type.id }}" value="{{ type.id }}">
+ <label for="type_{{ type.id }}">{{ type.name }}</label>
+ </li>
+ {% endfor %}
+ <li>
+ <input name="location_type_{{ instance.id }}" checked="checked" type="radio" class="location_type" id="type_all" value="">
+ <label for="type_all">All</label>
+ </li>
+ </ul>
</form>
</div>
<div id="map_canvas" lass="locations_map" style="width:600px; height:400px"></div>
+<ul class="location_list">
-<script type="text/javascript" src="{{ STATIC_URL }}store_locator/js/store_locator_map.js"></script>
+</ul>
<script type="text/javascript">
var get_lat_long_url = "{{ get_lat_long_url }}";
var get_locations_url = "{{ get_locations_url }}";
+ var starting_location = "{{ instance.starting_location }}";
+ var starting_zoom = {{ instance.default_distance }};
</script>
+<script type="text/javascript" src="{{ STATIC_URL }}store_locator/js/store_locator_map.js"></script>
View
6 store_locator/views.py
@@ -20,13 +20,17 @@ def get_locations(request):
latitude = float(request.GET.get('lat'))
longitude = float(request.GET.get('long'))
distance = int(request.GET.get('distance', 25))
+ location_type = request.GET.get('location_type', '0')
except:
return HttpResponse('[]')
-
+
locations = Location.objects.near(latitude, longitude, distance)
+ if location_type:
+ locations = [l for l in locations if str(l.location_type_id) == location_type]
json_locations = []
for location in locations:
location_dict = {}
+ location_dict['id'] = location.id
location_dict['name'] = location.name
location_dict['address'] = location.address
location_dict['latitude'] = location.latitude

0 comments on commit 339b7d6

Please sign in to comment.
Something went wrong with that request. Please try again.