Mercurial > lada > lada-client
comparison app/controller/form/Location.js @ 638:d21048cbdbb3
Added controllers for map and location form and handle new locations.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 17 Mar 2015 14:33:13 +0100 |
parents | |
children | d6ef146e1a9f |
comparison
equal
deleted
inserted
replaced
637:8acb3123b46c | 638:d21048cbdbb3 |
---|---|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | |
6 * the documentation coming with IMIS-Labordaten-Application for details. | |
7 */ | |
8 | |
9 Ext.define('Lada.controller.form.Location', { | |
10 extend: 'Ext.app.Controller', | |
11 | |
12 init: function() { | |
13 this.control({ | |
14 'locationform button[action=save]': { | |
15 click: this.save | |
16 }, | |
17 'locationform button[action=discard]': { | |
18 click: this.discard | |
19 }, | |
20 'locationform': { | |
21 dirtychange: this.dirtyForm | |
22 }, | |
23 'locationform numberfield[name=latitude]': { | |
24 change: this.updateFeatureLatitude | |
25 }, | |
26 'locationform numberfield[name=longitude]': { | |
27 change: this.updateFeatureLongitude, | |
28 } | |
29 }); | |
30 }, | |
31 | |
32 save: function(button) { | |
33 var formPanel = button.up('form'); | |
34 var data = formPanel.getForm().getFieldValues(true); | |
35 for (var key in data) { | |
36 formPanel.getForm().getRecord().set(key, data[key]); | |
37 } | |
38 formPanel.getForm().getRecord().save({ | |
39 success: function(record, response) { | |
40 var json = Ext.decode(response.response.responseText); | |
41 if (json) { | |
42 button.setDisabled(true); | |
43 button.up('toolbar').down('button[action=discard]') | |
44 .setDisabled(true); | |
45 formPanel.clearMessages(); | |
46 formPanel.setRecord(record); | |
47 formPanel.setMessages(json.errors, json.warnings); | |
48 button.up('window').down('map').locationRecord = null; | |
49 var orte = button.up('window').down('ortform combobox'); | |
50 orte.store.reload({ | |
51 callback: function() { | |
52 orte.setValue(record.data.id); | |
53 } | |
54 }); | |
55 } | |
56 }, | |
57 failure: function(record, response) { | |
58 button.setDisabled(true); | |
59 button.up('toolbar').down('button[action=discard]') | |
60 .setDisabled(true); | |
61 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); | |
62 var json = response.request.scope.reader.jsonData; | |
63 if (json) { | |
64 formPanel.setMessages(json.errors, json.warnings); | |
65 } | |
66 } | |
67 }); | |
68 }, | |
69 | |
70 discard: function(button) { | |
71 var formPanel = button.up('form'); | |
72 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); | |
73 button.up('window').down('map').locationRecord = null; | |
74 }, | |
75 | |
76 dirtyForm: function(form, dirty) { | |
77 if (dirty) { | |
78 form.owner.down('button[action=save]').setDisabled(false); | |
79 form.owner.down('button[action=discard]').setDisabled(false); | |
80 } | |
81 else { | |
82 form.owner.down('button[action=save]').setDisabled(true); | |
83 form.owner.down('button[action=discard]').setDisabled(true); | |
84 } | |
85 }, | |
86 | |
87 updateFeatureLatitude: function(field, nValue) { | |
88 var layer = field.up('window').down('map').selectControl.layer; | |
89 var newLocation = field.up('window').down('map').locationRecord; | |
90 if (layer && layer.selectedFeatures[0] && newLocation) { | |
91 var feature = layer.getFeatureById(layer.selectedFeatures[0].id); | |
92 feature.move(new OpenLayers.LonLat(feature.geometry.x, nValue)); | |
93 layer.refresh(); | |
94 } | |
95 }, | |
96 | |
97 updateFeatureLongitude: function(field, nValue) { | |
98 var layer = field.up('window').down('map').selectControl.layer; | |
99 var newLocation = field.up('window').down('map').locationRecord; | |
100 if (layer && layer.selectedFeatures[0] && newLocation) { | |
101 var feature = layer.getFeatureById(layer.selectedFeatures[0].id); | |
102 feature.move(new OpenLayers.LonLat(nValue, feature.geometry.y)); | |
103 layer.refresh(); | |
104 } | |
105 } | |
106 }); |