annotate app/controller/form/Location.js @ 695:d6ef146e1a9f

Added simple handling for Failure-Messages
author Dustin Demuth <dustin@intevation.de>
date Thu, 26 Mar 2015 16:24:13 +0100
parents d21048cbdbb3
children f0bc5387abcc
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]': {
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 change: this.updateFeatureLongitude,
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){
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 638
diff changeset
69 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('errmsgtitle')
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 638
diff changeset
70 +' '+json.message,
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 638
diff changeset
71 Lada.getApplication().bundle.getMsg(json.message));
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 638
diff changeset
72 }
638
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 }
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 }
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 });
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 },
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 discard: function(button) {
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 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
80 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
81 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
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 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
85 if (dirty) {
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 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
87 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
88 }
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 else {
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 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
91 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
92 }
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 },
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 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
96 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
97 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
98 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
99 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
100 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
101 layer.refresh();
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 }
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 },
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 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
106 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
107 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
108 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
109 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
110 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
111 layer.refresh();
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 }
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 }
d21048cbdbb3 Added controllers for map and location form and handle new locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 });

http://lada.wald.intevation.org