30 |
30 |
31 __docformat__ = 'restructuredtext' |
31 __docformat__ = 'restructuredtext' |
32 |
32 |
33 |
33 |
34 @adapter_config(name=getIfName(IGeoPoint), |
34 @adapter_config(name=getIfName(IGeoPoint), |
35 context=(Interface, IFormLayer, IForm, IGeoPointWidget), provides=IObjectFactory) |
35 context=(Interface, IFormLayer, IForm, IGeoPointWidget), |
36 class GeoPointObjectFactory(object): |
36 provides=IObjectFactory) |
|
37 def geo_point_object_widget_factory(*args, **kwargs): |
37 """GeoPointZ object factory""" |
38 """GeoPointZ object factory""" |
38 |
39 return GeoPoint |
39 def __init__(self, context, request, form, widget): |
|
40 self.context = context |
|
41 self.request = request |
|
42 self.form = form |
|
43 self.widget = widget |
|
44 |
|
45 def __call__(self, data): |
|
46 return GeoPoint() |
|
47 |
40 |
48 |
41 |
49 @widgettemplate_config(mode='input', template='templates/geopoint-input.pt', layer=IFormLayer) |
42 @widgettemplate_config(mode='input', |
|
43 template='templates/geopoint-input.pt', layer=IFormLayer) |
50 @implementer_only(IGeoPointWidget) |
44 @implementer_only(IGeoPointWidget) |
51 class GeoPointWidget(ObjectWidget): |
45 class GeoPointWidget(ObjectWidget): |
52 """GeoPoint widget""" |
46 """GeoPoint widget""" |
53 |
47 |
54 def updateWidgets(self, setErrors=True): |
48 def updateWidgets(self, setErrors=True): |
55 super(GeoPointWidget, self).updateWidgets(setErrors) |
49 super(GeoPointWidget, self).updateWidgets(setErrors) |
56 widgets = self.widgets |
50 widgets = self.widgets |
57 longitude = widgets['longitude'] |
51 longitude = widgets['longitude'] |
58 longitude.label_css_class = 'control-label col-md-3' |
52 longitude.label_css_class = 'control-label col-md-3' |
59 longitude.input_css_class = 'col-md-2' |
53 longitude.input_css_class = 'col-md-2' |
60 longitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'} |
54 longitude.object_data = { |
|
55 'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate' |
|
56 } |
61 alsoProvides(longitude, IObjectData) |
57 alsoProvides(longitude, IObjectData) |
62 latitude = widgets['latitude'] |
58 latitude = widgets['latitude'] |
63 latitude.label_css_class = 'control-label col-md-3' |
59 latitude.label_css_class = 'control-label col-md-3' |
64 latitude.input_css_class = 'col-md-2' |
60 latitude.input_css_class = 'col-md-2' |
65 latitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'} |
61 latitude.object_data = { |
|
62 'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate' |
|
63 } |
66 alsoProvides(latitude, IObjectData) |
64 alsoProvides(latitude, IObjectData) |
67 projection = widgets['projection'] |
65 projection = widgets['projection'] |
68 projection.label_css_class = 'control-label col-md-3' |
66 projection.label_css_class = 'control-label col-md-3' |
69 projection.input_css_class = 'col-md-9' |
67 projection.input_css_class = 'col-md-9' |
70 projection.object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.position.changedProjection'}} |
68 projection.object_data = { |
|
69 'ams-events-handlers': { |
|
70 'change.select2': 'PyAMS_GIS.position.changedProjection' |
|
71 } |
|
72 } |
71 alsoProvides(projection, IObjectData) |
73 alsoProvides(projection, IObjectData) |
72 |
74 |
73 @property |
75 @property |
74 def wgs_coordinates(self): |
76 def wgs_coordinates(self): |
75 value = self.field.get(self.field.interface(self.context)) |
77 value = self.field.get(self.field.interface(self.context)) |
76 if not value: |
78 if not value: |
77 return json.dumps({'longitude': None, |
79 return json.dumps({ |
78 'latitude': None}) |
80 'longitude': None, |
79 else: |
81 'latitude': None |
80 point = value.wgs_coordinates |
82 }) |
81 return json.dumps({'longitude': float(point[0]), |
83 # else: |
82 'latitude': float(point[1])}) |
84 point = value.wgs_coordinates |
|
85 return json.dumps({ |
|
86 'longitude': float(point[0]), |
|
87 'latitude': float(point[1]) |
|
88 }) |
83 |
89 |
84 |
90 |
85 @adapter_config(context=(IGeoPointField, IFormLayer), provides=IFieldWidget) |
91 @adapter_config(context=(IGeoPointField, IFormLayer), |
|
92 provides=IFieldWidget) |
86 def GeoPointFieldWidget(field, request): |
93 def GeoPointFieldWidget(field, request): |
87 """GeoPoint field widget factory""" |
94 """GeoPoint field widget factory""" |
88 return FieldWidget(field, GeoPointWidget(request)) |
95 return FieldWidget(field, GeoPointWidget(request)) |
89 |
96 |
90 |
97 |
91 @adapter_config(name=getIfName(IGeoPointZ), |
98 @adapter_config(name=getIfName(IGeoPointZ), |
92 context=(Interface, IFormLayer, IForm, IGeoPointZWidget), provides=IObjectFactory) |
99 context=(Interface, IFormLayer, IForm, IGeoPointZWidget), |
93 class GeoPointZObjectFactory(object): |
100 provides=IObjectFactory) |
94 """GeoPointZ object factory""" |
101 def geo_pointz_object_factory(*args, **kwargs): |
95 |
102 return GeoPointZ |
96 def __init__(self, context, request, form, widget): |
|
97 self.context = context |
|
98 self.request = request |
|
99 self.form = form |
|
100 self.widget = widget |
|
101 |
|
102 def __call__(self, data): |
|
103 return GeoPointZ() |
|
104 |
103 |
105 |
104 |
106 @widgettemplate_config(mode='input', template='templates/geopoint-input.pt', layer=IFormLayer) |
105 @widgettemplate_config(mode='input', |
|
106 template='templates/geopoint-input.pt', layer=IFormLayer) |
107 @implementer_only(IGeoPointZWidget) |
107 @implementer_only(IGeoPointZWidget) |
108 class GeoPointZWidget(ObjectWidget): |
108 class GeoPointZWidget(ObjectWidget): |
109 """GeoPointZ widget""" |
109 """GeoPointZ widget""" |
110 |
110 |
111 def updateWidgets(self, setErrors=True): |
111 def updateWidgets(self, setErrors=True): |
112 super(GeoPointZWidget, self).updateWidgets(setErrors) |
112 super(GeoPointZWidget, self).updateWidgets(setErrors) |
113 widgets = self.widgets |
113 widgets = self.widgets |
114 longitude = widgets['longitude'] |
114 longitude = widgets['longitude'] |
115 longitude.label_css_class = 'control-label col-md-3' |
115 longitude.label_css_class = 'control-label col-md-3' |
116 longitude.input_css_class = 'col-md-2' |
116 longitude.input_css_class = 'col-md-2' |
117 longitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'} |
117 longitude.object_data = { |
|
118 'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate' |
|
119 } |
118 alsoProvides(longitude, IObjectData) |
120 alsoProvides(longitude, IObjectData) |
119 latitude = widgets['latitude'] |
121 latitude = widgets['latitude'] |
120 latitude.label_css_class = 'control-label col-md-3' |
122 latitude.label_css_class = 'control-label col-md-3' |
121 latitude.input_css_class = 'col-md-2' |
123 latitude.input_css_class = 'col-md-2' |
122 latitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'} |
124 latitude.object_data = { |
|
125 'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate' |
|
126 } |
123 alsoProvides(latitude, IObjectData) |
127 alsoProvides(latitude, IObjectData) |
124 projection = widgets['projection'] |
128 projection = widgets['projection'] |
125 projection.label_css_class = 'control-label col-md-3' |
129 projection.label_css_class = 'control-label col-md-3' |
126 latitude.input_css_class = 'col-md-9' |
130 latitude.input_css_class = 'col-md-9' |
127 projection.object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.position.changedProjection'}} |
131 projection.object_data = { |
|
132 'ams-events-handlers': { |
|
133 'change.select2': 'PyAMS_GIS.position.changedProjection' |
|
134 } |
|
135 } |
128 alsoProvides(projection, IObjectData) |
136 alsoProvides(projection, IObjectData) |
129 altitude = widgets['altitude'] |
137 altitude = widgets['altitude'] |
130 altitude.label_css_class = 'control-label col-md-3' |
138 altitude.label_css_class = 'control-label col-md-3' |
131 altitude.input_css_class = 'col-md-2' |
139 altitude.input_css_class = 'col-md-2' |
132 |
140 |
133 @property |
141 @property |
134 def wgs_coordinates(self): |
142 def wgs_coordinates(self): |
135 value = self.field.get(self.field.interface(self.context)) |
143 value = self.field.get(self.field.interface(self.context)) |
136 if not value: |
144 if not value: |
137 return json.dumps({'longitude': None, |
145 return json.dumps({ |
138 'latitude': None}) |
146 'longitude': None, |
139 else: |
147 'latitude': None |
140 point = value.wgs_coordinates |
148 }) |
141 return json.dumps({'longitude': float(point[0]), |
149 # else: |
142 'latitude': float(point[1])}) |
150 point = value.wgs_coordinates |
|
151 return json.dumps({ |
|
152 'longitude': float(point[0]), |
|
153 'latitude': float(point[1]) |
|
154 }) |
143 |
155 |
144 |
156 |
145 @adapter_config(context=(IGeoPointZField, IFormLayer), provides=IFieldWidget) |
157 @adapter_config(context=(IGeoPointZField, IFormLayer), |
|
158 provides=IFieldWidget) |
146 def GeoPointZFieldWidget(field, request): |
159 def GeoPointZFieldWidget(field, request): |
147 """GeoPointZ field widget factory""" |
160 """GeoPointZ field widget factory""" |
148 return FieldWidget(field, GeoPointZWidget(request)) |
161 return FieldWidget(field, GeoPointZWidget(request)) |