Mercurial > lada > lada-client
annotate app/controller/form/Location.js @ 728:aadb6e1f0a70
Load the record returned by the request.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 17 Apr 2015 13:15:11 +0200 |
parents | 7f11b75e0188 |
children | 6e28ebbe1a73 |
rev | line source |
---|---|
638
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 * |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=3) |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 * the documentation coming with IMIS-Labordaten-Application for details. |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 */ |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 Ext.define('Lada.controller.form.Location', { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 extend: 'Ext.app.Controller', |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 init: function() { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 this.control({ |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 'locationform button[action=save]': { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 click: this.save |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 'locationform button[action=discard]': { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 click: this.discard |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 'locationform': { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 dirtychange: this.dirtyForm |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 'locationform numberfield[name=latitude]': { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 change: this.updateFeatureLatitude |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 'locationform numberfield[name=longitude]': { |
718
7f11b75e0188
Trailing Commas, editable: false for Umwelt und Messstelle widget
Dustin Demuth <dustin@intevation.de>
parents:
704
diff
changeset
|
27 change: this.updateFeatureLongitude |
638
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 }); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 save: function(button) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 var formPanel = button.up('form'); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 var data = formPanel.getForm().getFieldValues(true); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 for (var key in data) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 formPanel.getForm().getRecord().set(key, data[key]); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 formPanel.getForm().getRecord().save({ |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 success: function(record, response) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 var json = Ext.decode(response.response.responseText); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 if (json) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 button.setDisabled(true); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 button.up('toolbar').down('button[action=discard]') |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 .setDisabled(true); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 formPanel.clearMessages(); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 formPanel.setRecord(record); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 formPanel.setMessages(json.errors, json.warnings); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 button.up('window').down('map').locationRecord = null; |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 var orte = button.up('window').down('ortform combobox'); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 orte.store.reload({ |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 callback: function() { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 orte.setValue(record.data.id); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 }); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 failure: function(record, response) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 button.setDisabled(true); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 button.up('toolbar').down('button[action=discard]') |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 .setDisabled(true); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 var json = response.request.scope.reader.jsonData; |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 if (json) { |
695
d6ef146e1a9f
Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents:
638
diff
changeset
|
64 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ |
d6ef146e1a9f
Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents:
638
diff
changeset
|
65 formPanel.setMessages(json.errors, json.warnings); |
d6ef146e1a9f
Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents:
638
diff
changeset
|
66 } |
d6ef146e1a9f
Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents:
638
diff
changeset
|
67 |
d6ef146e1a9f
Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents:
638
diff
changeset
|
68 if(json.message){ |
704
2d454bfef426
Further Failure Messages
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
69 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') |
701
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
695
diff
changeset
|
70 +' #'+json.message, |
695
d6ef146e1a9f
Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents:
638
diff
changeset
|
71 Lada.getApplication().bundle.getMsg(json.message)); |
701
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
695
diff
changeset
|
72 } else { |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
695
diff
changeset
|
73 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
695
diff
changeset
|
74 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); |
695
d6ef146e1a9f
Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents:
638
diff
changeset
|
75 } |
701
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
695
diff
changeset
|
76 } else { |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
695
diff
changeset
|
77 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
695
diff
changeset
|
78 Lada.getApplication().bundle.getMsg('err.msg.response.body')); |
638
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 }); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 discard: function(button) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 var formPanel = button.up('form'); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 button.up('window').down('map').locationRecord = null; |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
89 |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
90 dirtyForm: function(form, dirty) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
91 if (dirty) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
92 form.owner.down('button[action=save]').setDisabled(false); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 form.owner.down('button[action=discard]').setDisabled(false); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 else { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 form.owner.down('button[action=save]').setDisabled(true); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 form.owner.down('button[action=discard]').setDisabled(true); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 updateFeatureLatitude: function(field, nValue) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
102 var layer = field.up('window').down('map').selectControl.layer; |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 var newLocation = field.up('window').down('map').locationRecord; |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 if (layer && layer.selectedFeatures[0] && newLocation) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 var feature = layer.getFeatureById(layer.selectedFeatures[0].id); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 feature.move(new OpenLayers.LonLat(feature.geometry.x, nValue)); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
107 layer.refresh(); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
109 }, |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
110 |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 updateFeatureLongitude: function(field, nValue) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 var layer = field.up('window').down('map').selectControl.layer; |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 var newLocation = field.up('window').down('map').locationRecord; |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
114 if (layer && layer.selectedFeatures[0] && newLocation) { |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
115 var feature = layer.getFeatureById(layer.selectedFeatures[0].id); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
116 feature.move(new OpenLayers.LonLat(nValue, feature.geometry.y)); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 layer.refresh(); |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
118 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
119 } |
d21048cbdbb3
Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
120 }); |