comparison app/view/form/Ortszuordnung.js @ 1289:bfdc00c24baf

Ortszuordnung for messprogramm and probe using same form
author Maximilian Krambach <mkrambach@intevation.de>
date Wed, 01 Feb 2017 14:52:51 +0100
parents 08085b7d1d0b
children d17501b967f2
comparison
equal deleted inserted replaced
1288:08085b7d1d0b 1289:bfdc00c24baf
11 */ 11 */
12 Ext.define('Lada.view.form.Ortszuordnung', { 12 Ext.define('Lada.view.form.Ortszuordnung', {
13 extend: 'Ext.form.Panel', 13 extend: 'Ext.form.Panel',
14 alias: 'widget.ortszuordnungform', 14 alias: 'widget.ortszuordnungform',
15 15
16 model: 'Lada.model.Ortszuordnung',
17
18 requires: [ 16 requires: [
19 'Lada.view.form.OrtInfo', 17 'Lada.view.form.OrtInfo',
20 'Lada.view.widget.Verwaltungseinheit', 18 'Lada.view.widget.Verwaltungseinheit',
21 'Lada.view.widget.Staat' 19 'Lada.view.widget.Staat'
22 ], 20 ],
23 21
24 layout: 'fit', 22 layout: 'fit',
25 margin: '5, 5, 0, 5', 23 margin: '5, 5, 0, 5',
26 border: 0, 24 border: 0,
27 25
26 /**
27 * @cfg: the type of the record to be passed. Should be either 'probe' or 'mpr'.
28 * Variable naming of these differ slightly (see function initComponent and the
29 * two lada.data.model.ortszuordnung* )
30 */
31 type: null,
32
28 record: null, 33 record: null,
29 34
30 trackResetOnLoad: true, 35 trackResetOnLoad: true,
31 36
32 initComponent: function() { 37 initComponent: function() {
33 var i18n = Lada.getApplication().bundle; 38 var i18n = Lada.getApplication().bundle;
34 var me = this; 39 var me = this;
40 if (this.type == 'probe') {
41 this.ortIdName = 'ortId';
42 this.typName = 'ortszuordnungTyp';
43 } else if (this.type == 'mpr') {
44 this.ortIdName = 'ort';
45 this.typName = 'ortsTyp';
46 }
35 this.items = [{ 47 this.items = [{
36 xtype: 'fieldset', 48 xtype: 'fieldset',
37 title: i18n.getMsg('ortszuordnung.form.fset.title'), 49 title: i18n.getMsg('ortszuordnung.form.fset.title'),
38 layout: 'fit', 50 layout: 'fit',
39 items: [{ 51 items: [{
89 labelWidth: 125, 101 labelWidth: 125,
90 maxLength: 1, 102 maxLength: 1,
91 allowBlank: false, 103 allowBlank: false,
92 regex: /[UEZA]{1}/, 104 regex: /[UEZA]{1}/,
93 activeError: 'U, E, Z oder A eingeben', 105 activeError: 'U, E, Z oder A eingeben',
94 name: 'ortszuordnungTyp', 106 name: this.typName,
95 fieldLabel: i18n.getMsg('ortszuordnung.form.field.ortszuordnungtyp'), 107 fieldLabel: i18n.getMsg('ortszuordnung.form.field.ortszuordnungtyp'),
96 108 listeners: {
109 change: me.changed
110 }
97 }, { 111 }, {
98 // this field is hidden because the user doesn't 112 // this field is hidden because the user doesn't
99 // need to know the internal ortID 113 // need to know the internal ortID
100 xtype: 'textfield', 114 xtype: 'textfield',
101 // fieldLabel: i18n.getMsg('orte.ortid'), 115 // fieldLabel: i18n.getMsg('orte.ortid'),
102 allowBlank: false, 116 allowBlank: false,
103 regex: /^[0-9]{1,45}$/, 117 regex: /^[0-9]{1,45}$/,
104 submitValue: true, 118 submitValue: true,
105 hidden: true, 119 hidden: true,
106 name: 'ortId', 120 name: this.ortIdName,
107 listeners: { 121 listeners: {
108 change: me.changedOrt 122 change: me.changed
109 } 123 }
110 }] 124 }]
111 }, 125 },
112 Ext.create('Lada.view.form.OrtInfo', { 126 Ext.create('Lada.view.form.OrtInfo')
113 record: me.record
114 })
115 ] 127 ]
116 }] 128 }]
117 }] 129 }]
118 }]; 130 }];
119 this.callParent(arguments); 131 this.callParent(arguments);
126 this.setReadOnly(false); 138 this.setReadOnly(false);
127 } 139 }
128 else { 140 else {
129 this.setReadOnly(true); 141 this.setReadOnly(true);
130 } 142 }
131 var ortId = this.getRecord().get('ortId');
132 this.refreshOrt(ortId);
133 },
134
135 refreshOrt: function(ortId) {
136 var orteStore = Ext.StoreManager.get('orte');
137 var ort = orteStore.getById(ortId);
138 if (!ort) {
139 return;
140 }
141 var verwStore = Ext.StoreManager.get('verwaltungseinheiten');
142 var verw = verwStore.getById(ort.get('gemId'));
143 var staatStore = Ext.StoreManager.get('staaten');
144 var staat = staatStore.getById(ort.get('staatId'));
145 var ortinfo = this.down('ortinfo')
146 ortinfo.loadRecord(ort);
147 ortinfo.getForm().setValues({
148 gemeinde: verw.get('bezeichnung'),
149 staat: staat.get('staatIso'),
150 lon: ort.get('longitude'),
151 lat: ort.get('latitude')
152 });
153 }, 143 },
154 144
155 /** 145 /**
156 * setOrt can be called from a CallbackFunction, ie select from a grid. 146 * setOrt can be called from a CallbackFunction, ie select from a grid.
157 * it will set the ortId of this record 147 * it will set the ortId of this record
158 */ 148 */
159 setOrt: function(row, selRecord, index, opts) { 149 setOrt: function(row, selRecord, index, opts) {
160 var newOrtId = selRecord.get('id'); 150 var newOrtId = selRecord.get('id');
161 var r = this.getRecord();
162 if (newOrtId) { 151 if (newOrtId) {
163 if (newOrtId != r.get('ortId')) { 152 if (this.type == 'probe') {
164 r.set('ortId', newOrtId);
165 this.getForm().setValues({ortId: newOrtId}); 153 this.getForm().setValues({ortId: newOrtId});
166 this.refreshOrt(newOrtId); 154 } else {
155 this.getForm().setValues({ort: newOrtId});
167 } 156 }
168 } 157 this.setOrtInfo(selRecord);
158 }
159 },
160
161 setOrtInfo: function(ortrecord) {
162 var verwStore = Ext.StoreManager.get('verwaltungseinheiten');
163 var verw = verwStore.getById(ortrecord.get('gemId'));
164 var staatStore = Ext.StoreManager.get('staaten');
165 var staat = staatStore.getById(ortrecord.get('staatId'));
166 var ortinfo = this.down('ortinfo');
167 ortinfo.loadRecord(ortrecord);
168 ortinfo.getForm().setValues({
169 gemeinde: verw.get('bezeichnung'),
170 staat: staat.get('staatIso'),
171 lon: ortrecord.get('longitude'),
172 lat: ortrecord.get('latitude')
173 });
169 }, 174 },
170 175
171 setMessages: function(errors, warnings) { 176 setMessages: function(errors, warnings) {
172 var key; 177 var key;
173 var element; 178 var element;
207 this.down('tfield[name=ortszusatztext]').clearWarningOrError(); 212 this.down('tfield[name=ortszusatztext]').clearWarningOrError();
208 }, 213 },
209 214
210 setReadOnly: function(value) { 215 setReadOnly: function(value) {
211 this.down('tfield[name=ortszusatztext]').setReadOnly(value); 216 this.down('tfield[name=ortszusatztext]').setReadOnly(value);
212 this.down('textfield[name=ortszuordnungTyp]').setReadOnly(value); 217 var fieldId = 'textfield[name=' + this.typName +']';
218 this.down(fieldId).setReadOnly(value);
213 }, 219 },
214 220
215 /** 221 /**
216 * Helper to trigger the forms' validity check on change of ortID 222 * Helper to trigger the forms' validity check
217 */ 223 */
218 changedOrt: function() { 224 changed: function(newValue, oldValue) {
219 var controller = Lada.app.getController( 225 var controller = Lada.app.getController(
220 'Lada.controller.form.Ortszuordnung'); 226 'Lada.controller.form.Ortszuordnung');
221 var form = this.up('form').getForm(); 227 var form = this.up('form').getForm();
228 var fields = form.getFields().items;
222 controller.validityChange(form, form.isValid()); 229 controller.validityChange(form, form.isValid());
223
224 } 230 }
225 }); 231 });
226 232

http://lada.wald.intevation.org