summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-09-21 12:31:09 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-09-21 12:31:09 +0200
commit792fed91a5c0c218ede19b01d5d818730193a6b2 (patch)
tree27e0699f444dc75cbebd7334ccbe87725d78e253
parent1f3bcebdafa399d7c7c35f4d5a1904b5bfdf040a (diff)
downloadChimère-792fed91a5c0c218ede19b01d5d818730193a6b2.tar.bz2
Chimère-792fed91a5c0c218ede19b01d5d818730193a6b2.zip
JS: edit route - refactoring for form and template edition
-rw-r--r--chimere/static/chimere/js/jquery.chimere.js7
-rw-r--r--chimere/templates/chimere/blocks/edit_widget.html (renamed from chimere/templates/chimere/blocks/polygon_edit.html)2
-rw-r--r--chimere/templates/chimere/edit.html5
-rw-r--r--chimere/templates/chimere/edit_marker.html11
-rw-r--r--chimere/templates/chimere/edit_route.html89
-rw-r--r--chimere/views.py209
-rw-r--r--chimere/widgets.py164
7 files changed, 118 insertions, 369 deletions
diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js
index 5787d10..329d6ba 100644
--- a/chimere/static/chimere/js/jquery.chimere.js
+++ b/chimere/static/chimere/js/jquery.chimere.js
@@ -2282,8 +2282,9 @@ function transform(obj) {
return;
},
updateInput: function(){
- if (settings.edition_type == 'linestring'){
- methods.updateRoutingInput();
+ if (settings.edition_type == 'route'){
+ // methods.updateRoutingInput();
+ methods.updateGenInput('route');
}
if (settings.edition_type == 'polygon'){
methods.updateGenInput('polygon');
@@ -2318,6 +2319,7 @@ function transform(obj) {
var input_id = '#';
if (settings.edition_type == 'marker') input_id += settings.input_id;
if (settings.edition_type == 'polygon') input_id += 'id_polygon';
+ if (settings.edition_type == 'route') input_id += 'id_route';
if (!features.length) {
jQuery(input_id).val('');
@@ -2356,6 +2358,7 @@ function transform(obj) {
}
},
initFeature: function(wkt_geometry){
+ if (!wkt_geometry || wkt_geometry == 'None') return;
feature = settings.WKT.readFeature(wkt_geometry, {
dataProjection: EPSG_DISPLAY_PROJECTION,
featureProjection: EPSG_PROJECTION});
diff --git a/chimere/templates/chimere/blocks/polygon_edit.html b/chimere/templates/chimere/blocks/edit_widget.html
index 59fe07e..be01569 100644
--- a/chimere/templates/chimere/blocks/polygon_edit.html
+++ b/chimere/templates/chimere/blocks/edit_widget.html
@@ -13,7 +13,7 @@
chimere_init_options["map_layers"] = [{map_layers}];
chimere_init_options['dynamic_categories'] = false;
chimere_init_options['edition'] = true;
- chimere_init_options['edition_type'] = 'polygon';
+ chimere_init_options['edition_type'] = '{edition_type}';
chimere_init_options["checked_categories"] = [];
{% if default_area %} chimere_init_options['selected_map_layer'] = {{default_area}};{% endif %}
</script>
diff --git a/chimere/templates/chimere/edit.html b/chimere/templates/chimere/edit.html
index ab5bb4b..869510a 100644
--- a/chimere/templates/chimere/edit.html
+++ b/chimere/templates/chimere/edit.html
@@ -22,16 +22,13 @@
{% endif %}</fieldset>
{% if is_modification and is_superuser %}<div class='warning'><p>{% trans "You are logged as an administrator. Your modifications will be taking into account immediately." %}</p></div>{% endif %}
<fieldset class='edit'>
- {% block legend %}<legend>{% if is_modification %}{% trans "Modify a point of interest" %}{% else %}{% trans "Add a point of interest" %}{% endif %}</legend>{% endblock %}
+ {% block legend %}{% endblock %}
<form enctype="multipart/form-data" method='post' action='.'>
{% csrf_token %}
<div class='rightWrapper'>
<div class='rightform'>
<div class="fieldWrapper full">
{% block geometry %}
- <label for="id_point">{% trans "Point"%} *</label>
- {%if form.point.errors %}<ul class="errorlist"><li>{% trans "Select a location for this new site" %}</li></ul>{%endif%}
- {{point_widget}}
{% endblock %}
</div>
</div>
diff --git a/chimere/templates/chimere/edit_marker.html b/chimere/templates/chimere/edit_marker.html
new file mode 100644
index 0000000..c3e4fa2
--- /dev/null
+++ b/chimere/templates/chimere/edit_marker.html
@@ -0,0 +1,11 @@
+{% extends "chimere/edit.html" %}
+{% load i18n chimere_tags adminmedia inline_formset%}
+
+{% block legend %}<legend>{% if is_modification %}{% trans "Modify a point of interest" %}{% else %}{% trans "Add a point of interest" %}{% endif %}</legend>{% endblock %}
+
+{% block geometry %}
+<label for="id_point">{% trans "Point"%} *</label>
+{%if form.point.errors %}<ul class="errorlist"><li>{% trans "Select a location for this new site" %}</li></ul>{%endif%}
+{{point_widget}}
+{% endblock %}
+
diff --git a/chimere/templates/chimere/edit_route.html b/chimere/templates/chimere/edit_route.html
index 10f4d5e..7012b57 100644
--- a/chimere/templates/chimere/edit_route.html
+++ b/chimere/templates/chimere/edit_route.html
@@ -1,83 +1,12 @@
-{% extends "chimere/base.html" %}
-{% load i18n adminmedia chimere_tags inline_formset %}
-{% block extra_head %}
- {{ form.media }}
- {{ block.super }}
- {% head_chimere %}
- {% if dated %}
- <!--script type="text/javascript" src="{{extra_url}}media/js/core.js"></script-->
- <script type="text/javascript" src="{{ STATIC_URL }}chimere/js/utils.js"></script>
- <script type="text/javascript">
- window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";
- </script>
- {% endif %}
-{% endblock %}
-
-{% block content %}
- {{ block.super }}
- {% if submited %}{% submited %}{% endif %}
- {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
- {% if is_modification and is_superuser %}<div class='warning'><p>{% trans "You are logged as an administrator. Your modifications will be taking into account immediately." %}</p></div>{% endif %}
- <fieldset class='edit'>
- <legend>{% if is_modification %}{% trans "Modify a route" %}{% else %}{% trans "Add a route" %}{% endif %}</legend>
- <form enctype="multipart/form-data" method='post' action='.'>
- {% csrf_token %}
- <div class='rightWrapper'>
- <div class='rightform'>
- <div class="fieldWrapper">
- <label for="id_route">{% trans "Route"%} *</label>
- {%if form.point.errors %}<ul class="errorlist"><li>{% trans "Select a location for this new site" %}</li></ul>{%endif%}
- {{route_widget}}
- </div>
- </div>
- </div>
- <div class='leftform'>
- <p>* {% trans "indicates a mandatory field" %}</p>
- <div class="fieldWrapper">
- <label for="id_name">{% trans "Name"%} *</label>
- {{ form.name.errors }}
- {{ form.name }}
- </div>
- <div class="fieldWrapper">
- <label for="id_subcategory">{% trans "Categories" %} *</label>
- {{ form.categories.errors }}
- {{ form.categories }}
- </div>
- <div class="fieldWrapper">
- <label for="id_description">{% trans "Description" %} *</label>
- {{ form.description.errors }}
- {{ form.description }}
- </div>
- {% if dated %}
- <div class="fieldWrapper">
- <label for="id_start_date">{% trans "Start date" %}</label>
- {{ form.start_date.errors }}
- {{ form.start_date }}
- <p class="help">{{ form.start_date.help_text }}</p>
- </div>
- <div class="fieldWrapper">
- <label for="id_end_date">{% trans "End date" %}</label>
- {{ form.end_date.errors }}
- {{ form.end_date }}
- <p class="help">{{ form.end_date.help_text }}</p>
- </div>
- {% endif %}
- </div>
- <div class='bottomform'>
- {%for field in form%}{%for property in properties%}{%ifequal field.name property%}
- <div class="fieldWrapper">
- <label for="id_{{field.name}}">{% trans field.label %}</label>
- {{ field.errors }}
- {{ field }}
- </div>
- {%endifequal%}{%endfor%}{%endfor%}
+{% extends "chimere/edit.html" %}
+{% load i18n chimere_tags adminmedia inline_formset%}
- {% inline_formset "Multimedia files" formset_multi %}
- {% inline_formset "Picture files" formset_picture %}
+{% block legend %}
+<legend>{% if is_modification %}{% trans "Modify a route" %}{% else %}{% trans "Add a route" %}{% endif %}</legend>
+{% endblock %}
- <p><input type='submit' onclick='saveExtent();' value="{% trans 'Propose'%}"/></p>
- </div>
- </form>
- </fieldset>
- </div>
+{% block geometry %}
+<label for="id_route">{% trans "Route"%} *</label>
+{%if form.route.errors %}<ul class="errorlist"><li>{% trans "Draw the associated route" %}</li></ul>{%endif%}
+{{route_widget}}
{% endblock %}
diff --git a/chimere/views.py b/chimere/views.py
index 12ae9bd..8de3b1d 100644
--- a/chimere/views.py
+++ b/chimere/views.py
@@ -350,59 +350,6 @@ def action_do_redirect(action_name, available_actions):
redir = subaction.url
return redir
-get_edit_marker = get_edit_page('chimere:editmarker', Marker, MarkerForm)
-
-
-def editMarker(request, area_name="", item_id=None, submited=False):
- """
- Edition page
- """
- response, values, sub_categories = get_edit_marker(request, area_name,
- item_id, ['M', 'B'])
- if response:
- return response
- item_id, init_item, response_dct, form, formset_multi, formset_picture = \
- values
-
- # verify action is available
- current_actions = actions(response_dct['area_name'])
- redir = action_do_redirect('edit-marker', current_actions)
- if redir:
- return redirect(redir)
-
- # get the "manualy" declared_fields. Ie: properties
- querys = PropertyModel.getAvailable(area_name=area_name)
- declared_fields, filtered_properties = [], []
- for query in querys:
- declared_fields += query.all()
- filtered_properties += query.filter(
- subcategories__id__isnull=False).all()
- point_value = init_item.point if init_item else None
- if request.POST and request.POST.get('point'):
- point_value = request.POST.get('point')
- response_dct.update({
- 'actions': current_actions,
- 'action_selected': ('contribute', 'edit-marker'),
- 'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,
- 'form': form,
- 'formset_multi': formset_multi,
- 'formset_picture': formset_picture,
- 'dated': settings.CHIMERE_DAYS_BEFORE_EVENT,
- 'extra_head': form.media,
- 'marker_id': item_id,
- 'sub_categories': sub_categories,
- 'point_widget': PointChooserWidget().render(
- 'point', point_value, area_name=response_dct['area_name']),
- 'properties': declared_fields,
- 'filtered_properties': filtered_properties,
- 'submited': submited
- })
- # manualy populate the custom widget
- if 'subcategory' in form.data and form.data['subcategory']:
- response_dct['current_category'] = int(form.data['subcategory'])
- return render_to_response('chimere/edit.html', response_dct,
- context_instance=RequestContext(request))
-
def uploadFile(request, category_id='', area_name=''):
response_dct, redir = get_base_response(request, area_name)
@@ -472,108 +419,72 @@ def processRouteFile(request, area_name='', file_id=None):
else:
return HttpResponse(status=400)
+get_edit_marker = get_edit_page('chimere:editmarker', Marker, MarkerForm)
get_edit_route = get_edit_page('chimere:editroute', Route, RouteForm)
+get_edit_polygon = get_edit_page('chimere:editpolygon', Polygon, PolygonForm)
-def editRoute(request, area_name="", item_id=None, submited=False):
- """
- Route edition page
- """
- response, values, sub_categories = get_edit_route(request, area_name,
- item_id, ['R', 'B'])
- if response:
- return response
- item_id, init_item, response_dct, form, formset_multi, formset_picture = \
- values
-
- # verify action is available
- current_actions = actions(response_dct['area_name'])
- redir = action_do_redirect('edit-route', current_actions)
- if redir:
- return redirect(redir)
-
- # get the "manualy" declared_fields. Ie: properties
- declared_fields = form.declared_fields.keys()
- if 'description' in declared_fields:
- declared_fields.pop(declared_fields.index('description'))
- route_value = init_item.route if init_item else None
- if request.POST and request.POST.get('route'):
- route_value = request.POST.get('route')
- response_dct.update({
- 'actions': current_actions,
- 'action_selected': ('contribute', 'edit-route'),
- 'error_message': '',
- 'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,
- 'form': form,
- 'formset_multi': formset_multi,
- 'formset_picture': formset_picture,
- 'dated': settings.CHIMERE_DAYS_BEFORE_EVENT,
- 'extra_head': form.media,
- 'sub_categories': sub_categories,
- 'route_widget': RouteChooserWidget().render(
- 'route', route_value, area_name=response_dct['area_name'],
- routefile_id='',),
- 'properties': declared_fields,
- 'submited': submited
- })
- # manualy populate the custom widget
- if 'subcategory' in form.data and form.data['subcategory']:
- response_dct['current_category'] = int(form.data['subcategory'])
- return render_to_response('chimere/edit_route.html', response_dct,
- context_instance=RequestContext(request))
+def edit_page(get_edit, types, geom_name, widget):
+ def edit(request, area_name="", item_id=None, submited=False):
+ response, values, sub_categories = get_edit(request, area_name,
+ item_id, types)
+ if response:
+ return response
+ item_id, init_item, response_dct, form, formset_multi, formset_picture = \
+ values
-get_edit_polygon = get_edit_page('chimere:editpolygon', Polygon, PolygonForm)
+ # verify action is available
+ current_actions = actions(response_dct['area_name'])
+ redir = action_do_redirect('edit-' + geom_name, current_actions)
+ if redir:
+ return redirect(redir)
+
+ # get the "manualy" declared_fields. Ie: properties
+ querys = PropertyModel.getAvailable(area_name=area_name)
+ declared_fields, filtered_properties = [], []
+ for query in querys:
+ declared_fields += query.all()
+ filtered_properties += query.filter(
+ subcategories__id__isnull=False).all()
+ geom_attr = geom_name
+ if geom_attr == 'marker':
+ geom_attr = 'point'
+ value = getattr(init_item, geom_attr) if init_item else None
+ if request.POST and request.POST.get(geom_attr):
+ value = request.POST.get(geom_attr)
+ response_dct.update({
+ 'actions': current_actions,
+ 'action_selected': ('contribute', 'edit-' + geom_name),
+ 'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,
+ 'error_message': '',
+ 'form': form,
+ 'formset_multi': formset_multi,
+ 'formset_picture': formset_picture,
+ 'dated': settings.CHIMERE_DAYS_BEFORE_EVENT,
+ 'extra_head': form.media,
+ 'marker_id': item_id,
+ 'sub_categories': sub_categories,
+ geom_attr + '_widget': widget().render(
+ geom_attr, value, area_name=response_dct['area_name']),
+ 'properties': declared_fields,
+ 'filtered_properties': filtered_properties,
+ 'submited': submited
+ })
+ # manualy populate the custom widget
+ if 'subcategory' in form.data and form.data['subcategory']:
+ response_dct['current_category'] = int(form.data['subcategory'])
+ return render_to_response('chimere/edit_{}.html'.format(geom_name),
+ response_dct,
+ context_instance=RequestContext(request))
+ return edit
-def editPolygon(request, area_name="", item_id=None, submited=False):
- """
- Polygon edition page
- """
- response, values, sub_categories = get_edit_polygon(request, area_name,
- item_id, ['P'])
- if response:
- return response
- item_id, init_item, response_dct, form, formset_multi, formset_picture = \
- values
-
- # verify action is available
- current_actions = actions(response_dct['area_name'])
- redir = action_do_redirect('edit-polygon', current_actions)
- if redir:
- return redirect(redir)
-
- # get the "manualy" declared_fields. Ie: properties
- querys = PropertyModel.getAvailable(area_name=area_name)
- declared_fields, filtered_properties = [], []
- for query in querys:
- declared_fields += query.all()
- filtered_properties += query.filter(
- subcategories__id__isnull=False).all()
- polygon_value = init_item.polygon if init_item else None
- if request.POST and request.POST.get('polygon'):
- polygon_value = request.POST.get('polygon')
- response_dct.update({
- 'actions': current_actions,
- 'action_selected': ('contribute', 'edit-polygon'),
- 'error_message': '',
- 'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,
- 'form': form,
- 'formset_multi': formset_multi,
- 'formset_picture': formset_picture,
- 'dated': settings.CHIMERE_DAYS_BEFORE_EVENT,
- 'extra_head': form.media,
- 'sub_categories': sub_categories,
- 'polygon_widget': PolygonChooserWidget().render(
- 'polygon', polygon_value, area_name=response_dct['area_name'],),
- 'properties': declared_fields,
- 'filtered_properties': filtered_properties,
- 'submited': submited
- })
- # manualy populate the custom widget
- if 'subcategory' in form.data and form.data['subcategory']:
- response_dct['current_category'] = int(form.data['subcategory'])
- return render_to_response('chimere/edit_polygon.html', response_dct,
- context_instance=RequestContext(request))
+editMarker = edit_page(get_edit_marker, ['M', 'B'], 'marker',
+ PointChooserWidget)
+editRoute = edit_page(get_edit_route, ['R', 'B'], 'route',
+ RouteChooserWidget)
+editPolygon = edit_page(get_edit_polygon, ['P'], 'polygon',
+ PolygonChooserWidget)
def submited(request, area_name="", action=""):
diff --git a/chimere/widgets.py b/chimere/widgets.py
index 6d61965..b4bbee6 100644
--- a/chimere/widgets.py
+++ b/chimere/widgets.py
@@ -26,7 +26,6 @@ from json import JSONEncoder
from django import forms
from django.conf import settings
from django.contrib.gis.db import models
-from django.contrib.gis.geos import fromstr
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.forms.widgets import RadioInput, RadioFieldRenderer, flatatt
@@ -401,13 +400,11 @@ class PointChooserWidget(forms.TextInput):
'default_area': "true" if default_area
else "false",
}) %
- (settings.STATIC_URL,
- settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
+ (settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
settings.CHIMERE_EPSG_PROJECTION,
"[{}, {}]".format(settings.CHIMERE_DEFAULT_CENTER[0],
settings.CHIMERE_DEFAULT_CENTER[1]),
settings.CHIMERE_DEFAULT_ZOOM,
- settings.STATIC_URL,
", ".join(map_layers),
zoom
)
@@ -454,137 +451,37 @@ class RouteChooserWidget(forms.TextInput):
["%schimere/css/forms.css" % settings.STATIC_URL]
}
js = settings.MAP_JS_URLS + list(settings.JQUERY_JS_URLS) + \
- ["%schimere/js/jquery.chimere.js" % settings.STATIC_URL,
- "%schimere/js/edit_route_map.js" % settings.STATIC_URL,
- "%schimere/js/base.js" % settings.STATIC_URL]
+ ["%schimere/js/jquery.chimere.js" % settings.STATIC_URL]
- def render(self, name, value, attrs=None, area_name='', routefile_id=None):
- '''
- Render a map and latitude, longitude information field
- '''
- tpl = getMapJS(area_name)
- map_layers, default_area = get_map_layers(area_name)
+ def render(self, name, value, attrs=None, area_name='', routefile_id=None,
+ initialized=True):
+ val = ''
+ if value:
+ val = str(value)
+ map_layers, default_area, zoom = get_map_layers(area_name,
+ get_area_zoom=True)
extra_js = [extra_js for n, js, default, extra_js in map_layers
if extra_js]
- map_layers = [js for nm, js, default, ext_js in map_layers]
- js = u"""
- var resolutions;
- var zoomOffset;
-
- var extra_url = "%s";
- epsg_display_projection = 'EPSG:%s';
- var EPSG_DISPLAY_PROJECTION = epsg_display_projection;
- epsg_projection = 'EPSG:%s';
- var EPSG_PROJECTION = epsg_projection;
- centerLonLat = ol.proj.transform([%f %f],
- epsg_display_projection, epsg_projection);
- var CENTER_LONLAT = centerLonLat;
- var DEFAULT_ZOOM = %s;
- var chimere_init_options = {};
- %s
- chimere_init_options["map_layers"] = [%s];
- chimere_init_options['dynamic_categories'] = false;
- chimere_init_options['edition'] = true;
- chimere_init_options['edition_type_is_route'] = true;
- chimere_init_options["checked_categories"] = [];
- """ % (reverse("chimere:index"),
- settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
- settings.CHIMERE_EPSG_PROJECTION,
- settings.CHIMERE_DEFAULT_CENTER[0],
- settings.CHIMERE_DEFAULT_CENTER[1],
- settings.CHIMERE_DEFAULT_ZOOM,
- u"\n".join(extra_js),
- u", ".join(map_layers))
- if default_area:
- js += u"chimere_init_options['selected_map_layer'] = %d;\n" % \
- default_area
- tpl = u"<script type='text/javascript'><!--\n"\
- u"%s// !--></script>\n" % js
- # TODO: manage area
- help_create = ''
- if not value:
- 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 "
- u"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 "
- u"is finished you can edit it."),
- _(u"While creating to undo a drawing click again on the "
- u"toggle 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 "
- u"position."),
- _(u"To delete a point move the mouse cursor over it and press "
- u"the \"d\" or \"Del\" key."),
- _(u"To add a point click in the middle of a segment and drag "
- u"the new point to the desired position"))
- if not value:
- # upload a file
- tpl += u"<script type='text/javascript'><!--\n"\
- u" var error_msg = \"%s\";"\
- u"// --></script>" % \
- _(u"Give a name and set category before uploading a file.")
- tpl += u'<div id="upload"><a href="#" class="upload-button" '\
- u'onclick="uploadFile(error_msg);return false;">%s</a></div>' \
- % (_(u"Upload a route file (GPX or KML)"))
- tpl += u"\n<p id='draw-or'>%s</p>\n" % _(u"or")
- tpl += u"<div id='draw-label'><div id='draw-toggle-off' "\
- u"onclick='toggleDraw();'>\n"\
- u"<a href='#' onclick='return false;'>%s</a></div>"\
- u"</div>\n"\
- u"<hr class='spacer'/>" % (_(u"Start \"hand\" drawing"))
- style = ''
- if value:
- style = " style='display:block'"
- tpl += u"\n<div class='help-route' id='help-route-modify'%s>%s</div>"\
- u"\n<hr class='spacer'/>\n"\
- u"<input type='hidden' name='%s' id='id_%s' value=\"%s\"/>\n"\
- u"<input type='hidden' name='associated_file_id' "\
- u"id='id_associated_file_id' value=\"%s\"/>\n" % (
- style, help_modify, name, name, value, routefile_id)
- if value:
- tpl += u"\n<div id='map_edit'></div>"
- else:
- tpl += "\n<div class='help-route' id='help-route-create'>%s</div>"\
- % help_create
- tpl += \
- u"\n<div id='layerSwitcher'></div>\n<div id='map_edit'>\n"\
- u" <div class='map_button'>\n"\
- u" <a href='#' id='button-move-map' class='toggle-button "\
- u"toggle-button-active' "\
- u"onclick='toggleDrawOff();return false;'>%s</a>\n"\
- u"<a href='#' id='button-draw-map' class='toggle-button "\
- u"toggle-button-inactive' "\
- u"onclick='toggleDrawOn();return false;'>%s</a></div>\n"\
- u" </div>" % (_(u"Move on the map"), _(u"Draw"))
- tpl += u"<script type='text/javascript'><!--\n"
- if not value:
- tpl += u"jQuery('#map_edit').hide();"
- if value:
- tpl += u"jQuery('#map_edit').chimere(chimere_init_options);\n"
- val = value
- if type(value) == unicode:
- try:
- val = fromstr(value)
- except:
- pass
- if hasattr(val, 'json'):
- tpl += u"\nvar geometry='%s';\n"\
- u"jQuery('#map_edit').chimere('initFeature', geometry);"\
- % val.json
- tpl += u"\n// --></script>\n"
- return mark_safe(tpl)
+ map_layers = [js for n, js, default, ext_js in map_layers
+ if 'OpenLayers' not in js]
+ tpl = render_to_string(
+ 'chimere/blocks/edit_widget.html',
+ {'name': name, 'val': val, 'initialized': initialized,
+ 'isvalue': bool(value),
+ 'default_area': "true" if default_area else "false",
+ 'value': value
+ }
+ )
+ return mark_safe(tpl.format(
+ static_url=settings.STATIC_URL,
+ display_projection=settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
+ projection=settings.CHIMERE_EPSG_PROJECTION,
+ center=list(settings.CHIMERE_DEFAULT_CENTER),
+ zoom=zoom,
+ edition_type="route",
+ map_layers=u", ".join(map_layers),
+ extra_js=u"\n".join(extra_js),
+ ))
class RouteField(models.LineStringField):
@@ -717,7 +614,7 @@ class PolygonChooserWidget(forms.TextInput):
map_layers = [js for n, js, default, ext_js in map_layers
if 'OpenLayers' not in js]
tpl = render_to_string(
- 'chimere/blocks/polygon_edit.html',
+ 'chimere/blocks/edit_widget.html',
{'name': name, 'val': val, 'initialized': initialized,
'isvalue': bool(value),
'default_area': "true" if default_area else "false",
@@ -730,6 +627,7 @@ class PolygonChooserWidget(forms.TextInput):
projection=settings.CHIMERE_EPSG_PROJECTION,
center=list(settings.CHIMERE_DEFAULT_CENTER),
zoom=zoom,
+ edition_type="polygon",
map_layers=u", ".join(map_layers),
extra_js=u"\n".join(extra_js),
))