30 |
30 |
31 __docformat__ = 'restructuredtext' |
31 __docformat__ = 'restructuredtext' |
32 |
32 |
33 |
33 |
34 @adapter_config(name=getIfName(IGeoArea), |
34 @adapter_config(name=getIfName(IGeoArea), |
35 context=(Interface, IFormLayer, IForm, IGeoAreaWidget), provides=IObjectFactory) |
35 context=(Interface, IFormLayer, IForm, IGeoAreaWidget), |
36 class GeoAreaObjectFactory(object): |
36 provides=IObjectFactory) |
|
37 def geo_area_object_factory(*args, **kwargs): |
37 """GeoArea object factory""" |
38 """GeoArea object factory""" |
38 |
39 return GeoArea |
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 GeoArea() |
|
47 |
40 |
48 |
41 |
49 @widgettemplate_config(mode='input', template='templates/geoarea-input.pt', layer=IFormLayer) |
42 @widgettemplate_config(mode='input', |
|
43 template='templates/geoarea-input.pt', layer=IFormLayer) |
50 @implementer_only(IGeoAreaWidget) |
44 @implementer_only(IGeoAreaWidget) |
51 class GeoAreaWidget(ObjectWidget): |
45 class GeoAreaWidget(ObjectWidget): |
52 """GeoArea widget""" |
46 """GeoArea widget""" |
53 |
47 |
54 def updateWidgets(self, setErrors=True): |
48 def updateWidgets(self, setErrors=True): |
55 super(GeoAreaWidget, self).updateWidgets() |
49 super(GeoAreaWidget, self).updateWidgets() |
56 widgets = self.widgets |
50 widgets = self.widgets |
57 x1 = widgets['x1'] |
51 x1 = widgets['x1'] |
58 x1.input_css_class = 'col-md-2' |
52 x1.input_css_class = 'col-md-2' |
59 x1.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'} |
53 x1.object_data = { |
|
54 'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate' |
|
55 } |
60 alsoProvides(x1, IObjectData) |
56 alsoProvides(x1, IObjectData) |
61 x2 = widgets['x2'] |
57 x2 = widgets['x2'] |
62 x2.input_css_class = 'col-md-2' |
58 x2.input_css_class = 'col-md-2' |
63 x2.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'} |
59 x2.object_data = { |
|
60 'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate' |
|
61 } |
64 alsoProvides(x2, IObjectData) |
62 alsoProvides(x2, IObjectData) |
65 y1 = widgets['y1'] |
63 y1 = widgets['y1'] |
66 y1.input_css_class = 'col-md-2' |
64 y1.input_css_class = 'col-md-2' |
67 y1.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'} |
65 y1.object_data = { |
|
66 'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate' |
|
67 } |
68 alsoProvides(y1, IObjectData) |
68 alsoProvides(y1, IObjectData) |
69 y2 = widgets['y2'] |
69 y2 = widgets['y2'] |
70 y2.input_css_class = 'col-md-2' |
70 y2.input_css_class = 'col-md-2' |
71 y2.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'} |
71 y2.object_data = { |
|
72 'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate' |
|
73 } |
72 alsoProvides(y2, IObjectData) |
74 alsoProvides(y2, IObjectData) |
73 projection = widgets['projection'] |
75 projection = widgets['projection'] |
74 projection.object_data = { |
76 projection.object_data = { |
75 'ams-events-handlers': { |
77 'ams-events-handlers': { |
76 'change.select2': 'PyAMS_GIS.area.changedProjection' |
78 'change.select2': 'PyAMS_GIS.area.changedProjection' |
80 |
82 |
81 @property |
83 @property |
82 def wgs_coordinates(self): |
84 def wgs_coordinates(self): |
83 value = self.field.get(self.field.interface(self.context)) |
85 value = self.field.get(self.field.interface(self.context)) |
84 if not value: |
86 if not value: |
85 return json.dumps({'x1': None, |
87 return json.dumps({ |
86 'y1': None, |
88 'x1': None, |
87 'x2': None, |
89 'y1': None, |
88 'y2': None}) |
90 'x2': None, |
|
91 'y2': None |
|
92 }) |
89 else: |
93 else: |
90 point1, point2 = value.wgs_coordinates |
94 point1, point2 = value.wgs_coordinates |
91 return json.dumps({'x1': float(point1[0]), |
95 return json.dumps({ |
92 'y1': float(point1[1]), |
96 'x1': float(point1[0]), |
93 'x2': float(point2[0]), |
97 'y1': float(point1[1]), |
94 'y2': float(point2[1])}) |
98 'x2': float(point2[0]), |
|
99 'y2': float(point2[1]) |
|
100 }) |
95 |
101 |
96 |
102 |
97 @adapter_config(context=(IGeoAreaField, IFormLayer), provides=IFieldWidget) |
103 @adapter_config(context=(IGeoAreaField, IFormLayer), |
|
104 provides=IFieldWidget) |
98 def GeoAreaFieldWidget(field, request): |
105 def GeoAreaFieldWidget(field, request): |
99 """GeoArea field widget factory""" |
106 """GeoArea field widget factory""" |
100 return FieldWidget(field, GeoAreaWidget(request)) |
107 return FieldWidget(field, GeoAreaWidget(request)) |