Updated GPS widget
authorThierry Florac <thierry.florac@onf.fr>
Fri, 26 Jan 2018 16:06:19 +0100
changeset 19 31ec78bbd5d6
parent 18 8eef3d17a06f
child 20 2bbc2c65d9d3
Updated GPS widget
src/pyams_gis/widget/area.py
src/pyams_gis/widget/point.py
src/pyams_gis/widget/templates/geoarea-input.pt
src/pyams_gis/widget/templates/geopoint-input.pt
--- a/src/pyams_gis/widget/area.py	Fri Jan 26 15:59:57 2018 +0100
+++ b/src/pyams_gis/widget/area.py	Fri Jan 26 16:06:19 2018 +0100
@@ -57,20 +57,29 @@
     def updateWidgets(self, setErrors=True):
         super(GeoAreaWidget, self).updateWidgets()
         widgets = self.subform.widgets
-        widgets['x1'].input_css_class = 'col-md-2'
-        widgets['y1'].input_css_class = 'col-md-2'
-        widgets['x2'].input_css_class = 'col-md-2'
-        widgets['y2'].input_css_class = 'col-md-2'
-        widgets['x1'].object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'}
-        widgets['y1'].object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'}
-        widgets['x2'].object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'}
-        widgets['y2'].object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'}
-        widgets['projection'].object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.area.changedProjection'}}
-        alsoProvides(widgets['x1'], IObjectData)
-        alsoProvides(widgets['y1'], IObjectData)
-        alsoProvides(widgets['x2'], IObjectData)
-        alsoProvides(widgets['y2'], IObjectData)
-        alsoProvides(widgets['projection'], IObjectData)
+        x1 = widgets['x1']
+        x1.input_css_class = 'col-md-2'
+        x1.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'}
+        alsoProvides(x1, IObjectData)
+        x2 = widgets['x2']
+        x2.input_css_class = 'col-md-2'
+        x2.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'}
+        alsoProvides(x2, IObjectData)
+        y1 = widgets['y1']
+        y1.input_css_class = 'col-md-2'
+        y1.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'}
+        alsoProvides(y1, IObjectData)
+        y2 = widgets['y2']
+        y2.input_css_class = 'col-md-2'
+        y2.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'}
+        alsoProvides(y2, IObjectData)
+        projection = widgets['projection']
+        projection.object_data = {
+            'ams-events-handlers': {
+                'change.select2': 'PyAMS_GIS.area.changedProjection'
+            }
+        }
+        alsoProvides(projection, IObjectData)
 
     @property
     def wgs_coordinates(self):
--- a/src/pyams_gis/widget/point.py	Fri Jan 26 15:59:57 2018 +0100
+++ b/src/pyams_gis/widget/point.py	Fri Jan 26 16:06:19 2018 +0100
@@ -57,14 +57,21 @@
     def updateWidgets(self, setErrors=True):
         super(GeoPointWidget, self).updateWidgets(setErrors)
         widgets = self.subform.widgets
-        widgets['longitude'].input_css_class = 'col-md-2'
-        widgets['latitude'].input_css_class = 'col-md-2'
-        widgets['longitude'].object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'}
-        widgets['latitude'].object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'}
-        widgets['projection'].object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.position.changedProjection'}}
-        alsoProvides(widgets['longitude'], IObjectData)
-        alsoProvides(widgets['latitude'], IObjectData)
-        alsoProvides(widgets['projection'], IObjectData)
+        longitude = widgets['longitude']
+        longitude.label_css_class = 'control-label col-md-2'
+        longitude.input_css_class = 'col-md-2'
+        longitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'}
+        alsoProvides(longitude, IObjectData)
+        latitude = widgets['latitude']
+        latitude.label_css_class = 'control-label col-md-2'
+        latitude.input_css_class = 'col-md-2'
+        latitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'}
+        alsoProvides(latitude, IObjectData)
+        projection = widgets['projection']
+        projection.label_css_class = 'control-label col-md-2'
+        projection.input_css_class = 'col-md-10'
+        projection.object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.position.changedProjection'}}
+        alsoProvides(projection, IObjectData)
 
     @property
     def wgs_coordinates(self):
@@ -107,15 +114,24 @@
     def updateWidgets(self, setErrors=True):
         super(GeoPointZWidget, self).updateWidgets(setErrors)
         widgets = self.subform.widgets
-        widgets['longitude'].input_css_class = 'col-md-2'
-        widgets['latitude'].input_css_class = 'col-md-2'
-        widgets['altitude'].input_css_class = 'col-md-2'
-        widgets['longitude'].object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'}
-        widgets['latitude'].object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'}
-        widgets['projection'].object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.position.changedProjection'}}
-        alsoProvides(widgets['longitude'], IObjectData)
-        alsoProvides(widgets['latitude'], IObjectData)
-        alsoProvides(widgets['projection'], IObjectData)
+        longitude = widgets['longitude']
+        longitude.label_css_class = 'control-label col-md-2'
+        longitude.input_css_class = 'col-md-2'
+        longitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'}
+        alsoProvides(longitude, IObjectData)
+        latitude = widgets['latitude']
+        latitude.label_css_class = 'control-label col-md-2'
+        latitude.input_css_class = 'col-md-2'
+        latitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'}
+        alsoProvides(latitude, IObjectData)
+        projection = widgets['projection']
+        projection.label_css_class = 'control-label col-md-2'
+        latitude.input_css_class = 'col-md-10'
+        projection.object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.position.changedProjection'}}
+        alsoProvides(projection, IObjectData)
+        altitude = widgets['altitude']
+        altitude.label_css_class = 'control-label col-md-2'
+        altitude.input_css_class = 'col-md-2'
 
     @property
     def wgs_coordinates(self):
--- a/src/pyams_gis/widget/templates/geoarea-input.pt	Fri Jan 26 15:59:57 2018 +0100
+++ b/src/pyams_gis/widget/templates/geoarea-input.pt	Fri Jan 26 16:06:19 2018 +0100
@@ -2,7 +2,8 @@
 	<fieldset
 		tal:define="name python:view.name.replace('.','_')"
 		data-ams-plugins="pyams_gis"
-		tal:attributes="data-ams-plugin-pyams_gis-src extension:resource_path('pyams_gis:pyams_gis')"
+		tal:attributes="class view/fieldset_class | default;
+						data-ams-plugin-pyams_gis-src extension:resource_path('pyams_gis:pyams_gis')"
 		data-ams-plugin-pyams_gis-async="false">
 		<button class="btn pull-right" tal:attributes="href string:#modal_dialog_${name}"
 			data-ams-click-handler="PyAMS_GIS.area.clear">
@@ -30,6 +31,10 @@
 					</div>
 					<div class="ams-form">
 						<div class="modal-body">
+							<div class="map-header"
+								 tal:define="header provider:pyams_gis.map.header"
+								 tal:condition="header"
+								 tal:content="structure header"></div>
 							<div class="map" id="map_area" style="width: 100%; height: 600px;"
 								 data-map-leaflet-fieldname="fieldname"
 								 tal:attributes="id string:map_area_${name};
--- a/src/pyams_gis/widget/templates/geopoint-input.pt	Fri Jan 26 15:59:57 2018 +0100
+++ b/src/pyams_gis/widget/templates/geopoint-input.pt	Fri Jan 26 16:06:19 2018 +0100
@@ -2,7 +2,8 @@
 	<fieldset
 		tal:define="name python:view.name.replace('.','_')"
 		data-ams-plugins="pyams_gis"
-		tal:attributes="data-ams-plugin-pyams_gis-src extension:resource_path('pyams_gis:pyams_gis')"
+		tal:attributes="class view/fieldset_class | default;
+						data-ams-plugin-pyams_gis-src extension:resource_path('pyams_gis:pyams_gis');"
 		data-ams-plugin-pyams_gis-async="false">
 		<button class="btn pull-right" tal:attributes="href string:#modal_dialog_${name}"
 			data-ams-click-handler="PyAMS_GIS.position.clear">
@@ -30,13 +31,19 @@
 					</div>
 					<div class="ams-form">
 						<div class="modal-body">
+							<div class="map-header"
+								 tal:define="header provider:pyams_gis.map.header"
+								 tal:condition="header"
+								 tal:content="structure header"></div>
 							<div class="map" id="map_location" style="width: 100%; height: 600px;"
 								 data-map-leaflet-fieldname="fieldname"
 								 tal:attributes="id string:map_location_${name};
 												 data-map-leaflet-fieldname view/name;"></div>
 						</div>
 						<footer>
-							<button type="button" class="btn btn-primary close-widget" data-dismiss="modal">OK</button>
+							<button type="button" class="btn btn-primary close-widget"
+									data-dismiss="modal" data-ams-click-event="marker.closed.position"
+									tal:attributes='data-ams-click-event-options string:{"fieldname": "${view/name}"}'>OK</button>
 						</footer>
 					</div>
 				</div>