comparison app/view/form/Ortserstellung.js @ 1279:291df0037835

Ortszuordnung window: create, change and display (wip)
author Maximilian Krambach <mkrambach@intevation.de>
date Wed, 18 Jan 2017 11:41:50 +0100
parents
children faecbb446a04
comparison
equal deleted inserted replaced
1278:cb9609380056 1279:291df0037835
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 /**
10 * Form to create a new Messpunkt
11 * TODO: layout, saving, model
12 */
13 Ext.define('Lada.view.form.Ortserstellung', {
14 extend: 'Ext.form.Panel',
15 alias: 'widget.ortserstellungsform',
16
17 model: 'Lada.model.Ortszuordnung',//TODO correct model needed
18 requires: [
19 'Lada.view.widget.Verwaltungseinheit',
20 'Lada.view.widget.Staat'
21 ],
22
23 width: 900,
24 height: 700,
25 bodyStyle: {background: '#fff'},
26 layout: 'vbox',
27 scrollable: true,
28 margin: '5, 5, 0, 5',
29 border: 0,
30 floating: true,
31 closable: true,
32
33 /**
34 * Preset values
35 */
36 presets: null,
37
38 initComponent: function() {
39 var i18n = Lada.getApplication().bundle;
40 var me = this;
41 this.items = [{ //TODO: layout and input types
42 title: 'Neuen Messpunkt anlegen',
43 dockedItems : [{
44 xtype: 'toolbar',
45 dock: 'bottom',
46 border: '0, 1, 1, 1',
47 style: {
48 borderBottom: '1px solid #b5b8c8 !important',
49 borderLeft: '1px solid #b5b8c8 !important',
50 borderRight: '1px solid #b5b8c8 !important'
51 },
52 items: ['->', {
53 text: i18n.getMsg('save'),
54 disabled: true,
55 action: 'save',
56 handler: me.saveOrt
57 }, {
58 text: i18n.getMsg('close'),
59 action: 'close',
60 handler: function() {
61 me.close();
62 }
63 }]
64 }],
65 items : [{
66 xtype: 'netzbetreiber',
67 editable: false,
68 readOnly: true,
69 submitValue: true,
70 fieldLabel: i18n.getMsg('netzbetreiberId'),
71 margin : '0, 5, 5, 5',
72 labelWidth: 80,
73 // value: XXX
74 // TODO: get netzbetreiber of current user
75 }, {
76 xtype: 'checkbox',
77 name: 'aktiv',
78 fieldLabel: 'aktiv:',
79 value: me.presets.aktiv? me.presets.aktiv:null
80 }, {
81 xtype: 'displayfield',
82 value: 'D',
83 labelWidth: 125,
84 maxLength: 1,
85 name: 'messpunktart',
86 fieldLabel: 'Art des Messpunktes:'
87 },{
88 xtype: 'displayfield',
89 labelWidth: 125,
90 maxLength: 100,
91 name: 'OrtID',
92 fieldLabel: 'Ort/Messpunkt-ID:',
93 // TODO: needed? We can't set it, and it is not yet given
94 // for a new messpunkt
95 editable: false
96 }, {
97 xtype: 'staat',
98 labelWidth: 100,
99 fieldLabel: i18n.getMsg('staat'),
100 name: 'staatId',
101 width: 160,
102 listeners: {
103 change: {
104 fn: function() { me.checkCommitEnabled() }
105 }
106 }
107 }, {
108 xtype: 'verwaltungseinheit',
109 labelWidth: 125,
110 fieldLabel: i18n.getMsg('orte.gemeinde'),
111 name: 'gemeinde',
112 listeners: {
113 change: {
114 fn: function() { me.checkCommitEnabled() }
115 }
116 }
117 }, {
118 xtype: 'displayfield',
119 labelWidth: 125,
120 fieldLabel: i18n.getMsg('orte.kda'),
121 name: 'kdaId',
122 listeners: {
123 change: {
124 fn: function() { me.checkCommitEnabled() }
125 }
126 }
127 }, {
128 xtype: 'displayfield',
129 labelWidth: 125,
130 fieldLabel: i18n.getMsg('orte.koordx'),
131 name: 'koordXExtern',
132 listeners: {
133 change: {
134 fn: function() { me.checkCommitEnabled() }
135 }
136 }
137 }, {
138 xtype: 'displayfield',
139 labelWidth: 125,
140 fieldLabel: i18n.getMsg('orte.koordy'),
141 name: 'koordYExtern',
142 listeners: {
143 change: {
144 fn: function() { me.checkCommitEnabled() }
145 }
146 }
147 }, {
148 xtype: 'displayfield',
149 labelWidth: 125,
150 fieldLabel: 'Höhe:',
151 name: 'hoehe', //TODO: hohe_ueber_NN?
152 }, {
153 xtype: 'displayfield',
154 labelWidth: 125,
155 maxLength: 100,
156 name: 'kurztext',
157 fieldLabel: 'Kurztext:'
158 },{
159 xtype: 'displayfield',
160 labelWidth: 125,
161 fieldLabel: i18n.getMsg('orte.langtext'),
162 name: 'langtext'
163 },{
164 xtype: 'displayfield',
165 labelWidth: 125,
166 fieldLabel: 'Berichtstext:',
167 name: 'berichtstext'
168 }]
169 }];
170 //TODO:
171 // 'Anlage:'?
172 // zone
173 // sektor
174 // zustaendigkeit
175 // Messregime (mpArt)
176 // 'Prog.-Punkt:', ?
177 // nutsCode
178 // Ortszusatz-ID (ozId)
179 me.callParent(arguments);
180 this.prefillForm();
181 },
182
183 /**
184 * checks Messpunktart and if the Messpunkt can be committed.
185 * Disables the save button if false
186 */
187 // TODO messpunktart is not yet finally defined
188 checkCommitEnabled: function() {
189 var savebutton = this.down('toolbar').down('button[action=save]');
190 var form = this.getForm();
191 if (this.checkCoordinates()) {
192 form.findField('messpunktart').setValue('D');
193 savebutton.setDisabled(false);
194 } else if (form.findField('gemeinde').getValue()) {
195 form.findField('messpunktart').setValue('V');
196 savebutton.setDisabled(false);
197 } else if (form.findField('staatId')) {
198 form.findField('messpunktart').setValue('S');
199 savebutton.setDisabled(false);
200 } else {
201 form.findField('messpunktart').setValue('D');
202 savebutton.setDisabled(true);
203 }
204 },
205
206 /**
207 * Validates the coordinate fields kdaId, koordXExtern, koordYExtern
208 */
209 checkCoordinates: function() {
210 var x = this.getForm().findField('koordXExtern').getValue();
211 var y = this.getForm().findField('koordYExtern').getValue();
212 var kda = this.getForm().findField('kdaId').getValue();
213 if (x && y && kda) {
214 if (kda === 4){
215 if (x > -180 && x < 180
216 && y > -90 && y < 90) {
217 return true;
218 } else {
219 // TODO: WGS84 (degrees- decimal), coordinates invalid
220 return false;
221 }
222 } else if (kda === 5){
223 if (x >= 1000000 && x < 61000000 &&
224 y > -10000000 && y < 10000000) {
225 return true;
226 } else {
227 // TODO: UTM, coordinates invalid
228 return false;
229 }
230 } else {
231 // TODO KDA not supported
232 return false;
233 }
234 } else {
235 // TODO: not all fields filled in
236 return false;
237 }
238 },
239
240 saveOrt: function(){
241 // TODO not yet implemented
242 alert("save!");
243 },
244
245 /**
246 * Fill the form with values passed by presets.
247 // TODO Find a shorter way of setting all these
248 */
249 prefillForm: function() {
250 var form = this.getForm();
251 if (this.presets.aktiv) {
252 form.findField('aktiv').setValue(this.presets.aktiv);
253 }
254 if (this.presets.staatId) {
255 // TODO: staatID != staatISO
256 form.findField('staatId').setValue(me.presets.staatId);
257 }
258 if (this.presets.gemeinde) {
259 // TODO: ortId != gemeinde
260 form.findField('gemeinde').setValue(this.presets.gemeinde);
261 }
262 if (this.presets.kdaId) {
263 form.findField('kdaId').setValue(this.presets.kdaId);
264 }
265 if (this.presets.koordXExtern) {
266 form.findField('koordXExtern').setValue(this.presets.koordXExtern);
267 }
268 if (this.presets.koordYExtern) {
269 form.findField('koordYExtern').setValue(this.presets.koordYExtern);
270 }
271 if (this.presets.hoehe) {
272 // TODO hohe_ueber_NN?
273 form.findField('hoehe').setValue(me.presets.hoehe);
274 }
275 if (this.presets.kurztext) {
276 form.findField('kurztext').setValue(this.presets.kurztext);
277 }
278 if (this.presets.langtext) {
279 form.findField('langtext').setValue(this.presets.langtext);
280 }
281 if (this.presets.berichtstext) {
282 form.findField('berichtstext').setValue(this.presets.berichtstext);
283 }
284 }
285 });
286

http://lada.wald.intevation.org