diff options
Diffstat (limited to 'chimere/widgets.py')
| -rw-r--r-- | chimere/widgets.py | 120 |
1 files changed, 62 insertions, 58 deletions
diff --git a/chimere/widgets.py b/chimere/widgets.py index d12f2e6..b12ea97 100644 --- a/chimere/widgets.py +++ b/chimere/widgets.py @@ -32,14 +32,14 @@ def getMapJS(area_name=''): '''Variable initialization for drawing the map ''' # projection, center and bounds definitions - js = u"var epsg_display_projection = new OpenLayers.Projection('EPSG:%d')\ -;\n" % settings.CHIMERE_EPSG_DISPLAY_PROJECTION + js = u"var epsg_display_projection = new OpenLayers.Projection('EPSG:%d')"\ + u";\n" % settings.CHIMERE_EPSG_DISPLAY_PROJECTION js += u"OpenLayers.ImgPath = '%schimere/img/';\n" % settings.STATIC_URL js += u"var epsg_projection = new OpenLayers.Projection('EPSG:%d');\n" % \ - settings.CHIMERE_EPSG_PROJECTION - js += u"var centerLonLat = new OpenLayers.LonLat(%f,\ -%f).transform(epsg_display_projection, epsg_projection);\n" % \ - settings.CHIMERE_DEFAULT_CENTER + settings.CHIMERE_EPSG_PROJECTION + js += u"var centerLonLat = new OpenLayers.LonLat(%f,"\ + u"%f).transform(epsg_display_projection, epsg_projection);\n" % \ + settings.CHIMERE_DEFAULT_CENTER js += u"var media_path = '%s';\n" % settings.STATIC_URL js += u"var map_layer = %s;\n" % settings.CHIMERE_MAP_LAYER js += u"var restricted_extent;\n" @@ -48,12 +48,11 @@ def getMapJS(area_name=''): js += u"var area_name='%s';\n" % area_name if settings.CHIMERE_RESTRICTED_EXTENT: restricted_extent_str = [str(coord) \ - for coord in settings.CHIMERE_RESTRICTED_EXTENT] + for coord in settings.CHIMERE_RESTRICTED_EXTENT] js += u"restricted_extent = new OpenLayers.Bounds(%s);\n" %\ ", ".join(restricted_extent_str) - js = u"""<script type="text/javascript"><!-- -%s// !--></script> -""" % js + js = u"<script type='text/javascript'><!--\n"\ + u"%s// !--></script>\n" % js return js class TextareaWidget(forms.Textarea): @@ -70,10 +69,12 @@ class PointChooserWidget(forms.TextInput): """ class Media: css = { - "all": settings.OSM_CSS_URLS + ["%schimere/css/forms.css" % settings.STATIC_URL,] + "all": settings.OSM_CSS_URLS + \ + ["%schimere/css/forms.css" % settings.STATIC_URL,] } - js = settings.OSM_JS_URLS + ["%schimere/js/edit_map.js" % settings.STATIC_URL, - "%schimere/js/base.js" % settings.STATIC_URL,] + js = settings.OSM_JS_URLS + \ + ["%schimere/js/edit_map.js" % settings.STATIC_URL, + "%schimere/js/base.js" % settings.STATIC_URL,] def render(self, name, value, attrs=None, area_name=''): ''' @@ -94,28 +95,29 @@ class PointChooserWidget(forms.TextInput): else: value = None tpl = getMapJS(area_name) - tpl += u'<script src="%schimere/js/edit_map.js"></script>\n' % settings.STATIC_URL - tpl += u"""<div id='map_edit'></div> -<div id='live_lonlat'> -<p><label for='live_latitude'>%s</label>\ -<input type='texte' name='live_latitude' id='live_latitude' size='8' \ -disabled='true' value='%f'/></p> -<p><label for='live_longitude'>%s</label><input type='texte' \ -name='live_longitude' id='live_longitude' size='8' disabled='true' \ -value='%f'/></p> -</div> -<input type='hidden' name='%s' id='id_%s' value="%s"/> -""" % (_("Latitude"), value_y, _("Longitude"), value_x, name, name, val) + tpl += u'<script src="%schimere/js/edit_map.js"></script>\n' % \ + settings.STATIC_URL + tpl += u"<div id='map_edit'></div>"\ + u"<div id='live_lonlat'>"\ + u" <p><label for='live_latitude'>%s</label>"\ + u" <input type='texte' name='live_latitude' id='live_latitude' "\ + u"size='8' disabled='true' value='%f'/></p>"\ + u"<p><label for='live_longitude'>%s</label><input type='texte' "\ + u"name='live_longitude' id='live_longitude' size='8' "\ + u"disabled='true' value='%f'/></p>"\ + u"</div>"\ + u"<input type='hidden' name='%s' id='id_%s' value='%s'/>" % ( + _("Latitude"), value_y, _("Longitude"), value_x, name, name, + val) tpl += "<script type='text/javascript'><!--\n" tpl += "init();\n" if value: - tpl += '''var mylonlat = new OpenLayers.LonLat(%f,%f); -putMarker(mylonlat.transform(epsg_display_projection, - map.getProjectionObject()).clone(), true); -''' % (value_x, value_y) - tpl += """// --></script> -<hr class='spacer'/> -""" + tpl += u'var mylonlat = new OpenLayers.LonLat(%f,%f);\n'\ + u'putMarker(mylonlat.transform(epsg_display_projection,\n'\ + u' map.getProjectionObject()).clone(), true);\n' % ( + value_x, value_y) + tpl += "// --></script>\n"\ + u"<hr class='spacer'/>\n" return mark_safe(tpl) class PointField(models.PointField): @@ -137,11 +139,12 @@ class RouteChooserWidget(forms.TextInput): Manage the edition of route on a map """ class Media: - css = { - "all": settings.OSM_CSS_URLS + ["%schimere/css/forms.css" % settings.STATIC_URL,] + css = {"all": settings.OSM_CSS_URLS + \ + ["%schimere/css/forms.css" % settings.STATIC_URL,] } - js = ["%schimere/js/edit_route_map.js" % settings.STATIC_URL, - "%schimere/js/base.js" % settings.STATIC_URL,] + settings.OSM_JS_URLS + js = settings.OSM_JS_URLS + \ + ["%schimere/js/edit_route_map.js" % settings.STATIC_URL, + "%schimere/js/base.js" % settings.STATIC_URL,] def render(self, name, value, attrs=None, area_name='', routefile_id=None): ''' @@ -150,28 +153,29 @@ class RouteChooserWidget(forms.TextInput): tpl = getMapJS(area_name) help_create = '' if not value: - help_create = """<h3>%s</h3> -<p>%s</p> -<p>%s</p> -<p>%s</p> -<p>%s</p> -<p>%s</p>""" % (_(u"Creation mode"), -_(u"To start drawing the route click on the toggle button: \"Draw\"."), -_(u"Then click on the map to begin the drawing."), -_(u"You can add points by clicking again."), -_(u"To finish the drawing double click. When the drawing is finished you can \ -edit it."), -_(u"While creating to undo a drawing click again on the toggle button \"Stop \ -drawing\".")) - help_modify = """<h3>%s</h3> -<p>%s</p> -<p>%s</p> -<p>%s</p>""" % (_(u"Modification mode"), -_(u"To move a point click on it and drag it to the desired position."), -_(u"To delete a point move the mouse cursor over it and press the \"d\" or \ -\"Del\" key."), -_(u"To add a point click in the middle of a segment and drag the new point to \ -the desired position")) + help_create = u"<h3>%s</h3>\n"\ + u"<p>%s</p>\n"\ + u"<p>%s</p>\n"\ + u"<p>%s</p>\n"\ + u"<p>%s</p>\n"\ + u"<p>%s</p>\n" % (_(u"Creation mode"), + _(u"To start drawing the route click on the toggle button: "\ + u"\"Draw\"."), + _(u"Then click on the map to begin the drawing."), + _(u"You can add points by clicking again."), + _(u"To finish the drawing double click. When the drawing is "\ + u"finished you can edit it."), + _(u"While creating to undo a drawing click again on the toggle "\ + u"button \"Stop drawing\".")) + help_modify = u"<h3>%s</h3>\n"\ + u"<p>%s</p>\n"\ + u"<p>%s</p>\n"\ + u"<p>%s</p>\n" % (_(u"Modification mode"), + _(u"To move a point click on it and drag it to the desired position."), + _(u"To delete a point move the mouse cursor over it and press the "\ + u"\"d\" or \"Del\" key."), + _(u"To add a point click in the middle of a segment and drag the new "\ + u"point to the desired position")) tpl += u'<script src="%sedit_route_map.js"></script>\n' % \ settings.STATIC_URL if not value: |
