Port to new django version - not yet fully working
- location field makes problems
This commit is contained in:
@@ -40,14 +40,14 @@
|
||||
theObject.placeMarker( l );
|
||||
theObject.saveToInputField();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.placeMarker = function( location )
|
||||
{
|
||||
this.marker.setPosition( location );
|
||||
this.map.setCenter( location );
|
||||
this.map.panTo( location );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.geocode = function(address, cb)
|
||||
@@ -60,7 +60,7 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.geocode_reverse = function( cb)
|
||||
{
|
||||
@@ -71,13 +71,13 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.saveToInputField = function()
|
||||
{
|
||||
var p = this.marker.getPosition();
|
||||
coordinate_field.value = p.lat().toFixed(6) + "," + p.lng().toFixed(6) + "," + this.map.getZoom() ;
|
||||
}
|
||||
};
|
||||
|
||||
this.loadFromInputField = function()
|
||||
{
|
||||
@@ -95,7 +95,7 @@
|
||||
this.placeMarker( init_position );
|
||||
this.map.setZoom( 16 );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// --------------------------- Constructor -------------------------------------
|
||||
@@ -118,7 +118,7 @@
|
||||
});
|
||||
|
||||
theObject.loadFromInputField();
|
||||
}
|
||||
};
|
||||
|
||||
this.init();
|
||||
}
|
||||
@@ -169,7 +169,7 @@
|
||||
$dialogElement[0].map.placeMarkerUsingAddressString( $dialogLocationField.val() );
|
||||
|
||||
$dialogLocationField.on("keypress", function(e) {
|
||||
if ( e.keyCode == 13 ) { // enter
|
||||
if ( e.keyCode === 13 ) { // enter
|
||||
$dialogElement[0].map.placeMarkerUsingAddressString( $dialogLocationField.val() );
|
||||
return false;
|
||||
}
|
||||
@@ -184,7 +184,5 @@
|
||||
|
||||
$dialogElement.dialog('open');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
from django.conf.urls.defaults import patterns
|
||||
|
||||
import os
|
||||
from django.urls import re_path
|
||||
from django.views.static import serve
|
||||
|
||||
app_dir = os.path.dirname(__file__)
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
(r'^media/(.*)$', 'django.views.static.serve', {
|
||||
'document_root': '%s/media' % app_dir}),
|
||||
)
|
||||
urlpatterns = [
|
||||
re_path(r'^media/(.*)$', serve, {'document_root': '%s/media' % app_dir}),
|
||||
]
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
from django.forms import widgets
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from django.conf import settings
|
||||
import os
|
||||
|
||||
|
||||
class LocationWidget(widgets.TextInput):
|
||||
def __init__(self, attrs=None, based_field=None, zoom=None, width=610, height = 480, **kwargs):
|
||||
def __init__(self, attrs=None, based_field=None, zoom=None, width=610, height=480, **kwargs):
|
||||
self.based_field = based_field
|
||||
self.zoom = zoom
|
||||
self.width = width
|
||||
self.height = height
|
||||
super(LocationWidget, self).__init__(attrs)
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
|
||||
if value is not None and len(value)>0:
|
||||
def render(self, name, value, attrs=None, renderer=None):
|
||||
|
||||
if value is not None and len(value) > 0:
|
||||
lat, lng, zoom = value.split(',')
|
||||
|
||||
|
||||
value = '%s,%s,%d' % (
|
||||
float(lat),
|
||||
float(lng),
|
||||
@@ -25,7 +26,7 @@ class LocationWidget(widgets.TextInput):
|
||||
value = ''
|
||||
|
||||
based_field = "#id_" + self.based_field.name
|
||||
|
||||
|
||||
attrs = attrs or {}
|
||||
attrs['readonly'] = "readonly"
|
||||
attrs['data-location-widget'] = name
|
||||
@@ -35,25 +36,23 @@ class LocationWidget(widgets.TextInput):
|
||||
attrs['data-dialog-id'] = "#map_dialog_" + name
|
||||
text_input = super(LocationWidget, self).render(name, value, attrs)
|
||||
|
||||
|
||||
path = os.path.abspath(os.path.dirname(__file__))
|
||||
with open( path + "/media/form.html" , 'r') as content_file:
|
||||
with open(path + "/media/form.html", 'r') as content_file:
|
||||
html = content_file.read()
|
||||
|
||||
return mark_safe(text_input + html % {'name': name, 'width': self.width, 'height': self.height })
|
||||
return mark_safe(text_input + html % {'name': name, 'width': self.width, 'height': self.height})
|
||||
|
||||
class Media:
|
||||
css = {
|
||||
'all' : ('/location_field/media/form.css', )
|
||||
css = {
|
||||
'all': ('/location_field/media/form.css',)
|
||||
}
|
||||
# Use schemaless URL so it works with both, http and https websites
|
||||
js = (
|
||||
'//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', # jquery
|
||||
'//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js',
|
||||
#'//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', # jquery
|
||||
#'//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js',
|
||||
'/static/js/jquery-ui-1.10.0.custom.min.js',
|
||||
#'//maps.google.com/maps/api/js?sensor=false&language=de&key={}'.format(settings.GOOGLE_MAPS_API_KEY),
|
||||
'//maps.google.com/maps/api/js?sensor=false&language=de',
|
||||
'/static/js/bindWithDelay.js',
|
||||
'/location_field/media/form.js',
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user