comparison app/controller/form/Location.js @ 742:6e28ebbe1a73

added documentation for Form and Grid controllers
author Dustin Demuth <dustin@intevation.de>
date Thu, 23 Apr 2015 16:28:04 +0200
parents 7f11b75e0188
children 2b7bcb778f0a
comparison
equal deleted inserted replaced
740:2e8da590ea0c 742:6e28ebbe1a73
4 * This file is Free Software under the GNU GPL (v>=3) 4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out 5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details. 6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */ 7 */
8 8
9 /**
10 * This is a Controller for a Location Form
11 */
9 Ext.define('Lada.controller.form.Location', { 12 Ext.define('Lada.controller.form.Location', {
10 extend: 'Ext.app.Controller', 13 extend: 'Ext.app.Controller',
11 14 /**
15 * Initialize the Controller with
16 * 5 listeners
17 */
12 init: function() { 18 init: function() {
13 this.control({ 19 this.control({
14 'locationform button[action=save]': { 20 'locationform button[action=save]': {
15 click: this.save 21 click: this.save
16 }, 22 },
27 change: this.updateFeatureLongitude 33 change: this.updateFeatureLongitude
28 } 34 }
29 }); 35 });
30 }, 36 },
31 37
38 /**
39 * The save function saves the content of the Location form.
40 * On success it will reload the Store,
41 * on failure, it will display an Errormessage
42 */
32 save: function(button) { 43 save: function(button) {
33 var formPanel = button.up('form'); 44 var formPanel = button.up('form');
34 var data = formPanel.getForm().getFieldValues(true); 45 var data = formPanel.getForm().getFieldValues(true);
35 for (var key in data) { 46 for (var key in data) {
36 formPanel.getForm().getRecord().set(key, data[key]); 47 formPanel.getForm().getRecord().set(key, data[key]);
79 } 90 }
80 } 91 }
81 }); 92 });
82 }, 93 },
83 94
95 /**
96 * The discard function resets the Location form
97 * to its original state.
98 */
84 discard: function(button) { 99 discard: function(button) {
85 var formPanel = button.up('form'); 100 var formPanel = button.up('form');
86 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); 101 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
87 button.up('window').down('map').locationRecord = null; 102 button.up('window').down('map').locationRecord = null;
88 }, 103 },
89 104
105 /**
106 * The dirtyForm function enables or disables the save and discard
107 * button which are present in the toolbar of the form.
108 * The Buttons are only active if the content of the form was altered
109 * (the form is dirty).
110 */
90 dirtyForm: function(form, dirty) { 111 dirtyForm: function(form, dirty) {
91 if (dirty) { 112 if (dirty) {
92 form.owner.down('button[action=save]').setDisabled(false); 113 form.owner.down('button[action=save]').setDisabled(false);
93 form.owner.down('button[action=discard]').setDisabled(false); 114 form.owner.down('button[action=discard]').setDisabled(false);
94 } 115 }
96 form.owner.down('button[action=save]').setDisabled(true); 117 form.owner.down('button[action=save]').setDisabled(true);
97 form.owner.down('button[action=discard]').setDisabled(true); 118 form.owner.down('button[action=discard]').setDisabled(true);
98 } 119 }
99 }, 120 },
100 121
122 /**
123 * This function updates the Latitude (heigth-value / y-value) of a feature
124 * (geospatial object). The feature can be a marker in the map
125 * @param {Ext.form.field.Field} field the Ext.field which was altered
126 * @param {} nValue the new Latitude as WGS84 in decimaldegrees
127 */
101 updateFeatureLatitude: function(field, nValue) { 128 updateFeatureLatitude: function(field, nValue) {
102 var layer = field.up('window').down('map').selectControl.layer; 129 var layer = field.up('window').down('map').selectControl.layer;
103 var newLocation = field.up('window').down('map').locationRecord; 130 var newLocation = field.up('window').down('map').locationRecord;
104 if (layer && layer.selectedFeatures[0] && newLocation) { 131 if (layer && layer.selectedFeatures[0] && newLocation) {
105 var feature = layer.getFeatureById(layer.selectedFeatures[0].id); 132 var feature = layer.getFeatureById(layer.selectedFeatures[0].id);
106 feature.move(new OpenLayers.LonLat(feature.geometry.x, nValue)); 133 feature.move(new OpenLayers.LonLat(feature.geometry.x, nValue));
107 layer.refresh(); 134 layer.refresh();
108 } 135 }
109 }, 136 },
110 137
138 /**
139 * This function updates the Longitude (right-value / x-value) of a feature
140 * (geospatial object). The feature can be a marker in the map
141 * @param {Ext.form.field.Field} field the Ext.field which was altered
142 * @param {} nValue the new Longitude as WGS84 in decimaldegrees
143 */
111 updateFeatureLongitude: function(field, nValue) { 144 updateFeatureLongitude: function(field, nValue) {
112 var layer = field.up('window').down('map').selectControl.layer; 145 var layer = field.up('window').down('map').selectControl.layer;
113 var newLocation = field.up('window').down('map').locationRecord; 146 var newLocation = field.up('window').down('map').locationRecord;
114 if (layer && layer.selectedFeatures[0] && newLocation) { 147 if (layer && layer.selectedFeatures[0] && newLocation) {
115 var feature = layer.getFeatureById(layer.selectedFeatures[0].id); 148 var feature = layer.getFeatureById(layer.selectedFeatures[0].id);

http://lada.wald.intevation.org