Mercurial > lada > lada-client
comparison app/view/form/Ortserstellung.js @ 1337:7194964183f4
Ortserstellung controller separated from form
author | Maximilian Krambach <mkrambach@intevation.de> |
---|---|
date | Fri, 03 Feb 2017 17:44:41 +0100 |
parents | b9f0bb189c25 |
children | 1a2cd9bef6d7 |
comparison
equal
deleted
inserted
replaced
1336:f879c806f880 | 1337:7194964183f4 |
---|---|
63 }, { | 63 }, { |
64 xtype: 'verwaltungseinheit', | 64 xtype: 'verwaltungseinheit', |
65 labelWidth: 125, | 65 labelWidth: 125, |
66 fieldLabel: i18n.getMsg('orte.verwaltungseinheit'), | 66 fieldLabel: i18n.getMsg('orte.verwaltungseinheit'), |
67 forceSelection: true, | 67 forceSelection: true, |
68 name: 'gemId', | 68 name: 'gemId' |
69 listeners: { | |
70 change: { | |
71 fn: function() { me.checkCommitEnabled() } | |
72 } | |
73 } | |
74 }, { | 69 }, { |
75 xtype: 'koordinatenart', | 70 xtype: 'koordinatenart', |
76 labelWidth: 125, | 71 labelWidth: 125, |
77 fieldLabel: i18n.getMsg('orte.kda'), | 72 fieldLabel: i18n.getMsg('orte.kda'), |
78 allowDecimals: false, | 73 name: 'kdaId' |
79 maxLength: 1, | |
80 name: 'kdaId', | |
81 listeners: { | |
82 change: { | |
83 fn: function() { me.checkCommitEnabled() } | |
84 } | |
85 } | |
86 }, { | 74 }, { |
87 xtype: 'numfield', | 75 xtype: 'numfield', |
88 labelWidth: 125, | 76 labelWidth: 125, |
89 fieldLabel: i18n.getMsg('orte.koordx'), | 77 fieldLabel: i18n.getMsg('orte.koordx'), |
90 name: 'koordXExtern', | 78 name: 'koordXExtern', |
91 allowDecimals: true, | 79 allowDecimals: true, |
92 decimalPrecision: 5, | 80 decimalPrecision: 5, |
93 maxLength: 22, | 81 maxLength: 22 |
94 listeners: { | |
95 change: { | |
96 fn: function() { me.checkCommitEnabled() } | |
97 } | |
98 } | |
99 }, { | 82 }, { |
100 xtype: 'numfield', | 83 xtype: 'numfield', |
101 labelWidth: 125, | 84 labelWidth: 125, |
102 fieldLabel: i18n.getMsg('orte.koordy'), | 85 fieldLabel: i18n.getMsg('orte.koordy'), |
103 name: 'koordYExtern', | 86 name: 'koordYExtern', |
104 allowDecimals: true, | 87 allowDecimals: true, |
105 decimalPrecision: 5, | 88 decimalPrecision: 5, |
106 maxLength: 22, | 89 maxLength: 22 |
107 listeners: { | |
108 change: { | |
109 fn: function() { me.checkCommitEnabled() } | |
110 } | |
111 } | |
112 }, { | 90 }, { |
113 xtype: 'numfield', | 91 xtype: 'numfield', |
114 labelWidth: 125, | 92 labelWidth: 125, |
115 fieldLabel: i18n.getMsg('orte.hoeheLand'), | 93 fieldLabel: i18n.getMsg('orte.hoeheLand'), |
116 name: 'hoeheLand', | 94 name: 'hoeheLand', |
202 }, { | 180 }, { |
203 text: i18n.getMsg('discard'), | 181 text: i18n.getMsg('discard'), |
204 qtip: 'Ă„nderungen verwerfen', | 182 qtip: 'Ă„nderungen verwerfen', |
205 icon: 'resources/img/dialog-cancel.png', | 183 icon: 'resources/img/dialog-cancel.png', |
206 action: 'revert', | 184 action: 'revert', |
185 disabled: true | |
207 }] | 186 }] |
208 }]; | 187 }]; |
209 | |
210 this.callParent(arguments); | 188 this.callParent(arguments); |
211 this.getForm().loadRecord(this.record); | 189 this.getForm().loadRecord(this.record); |
212 }, | 190 var controller = Lada.app.getController('Lada.controller.form.Ortserstellung') |
213 | 191 controller.checkCommitEnabled(this); |
214 /** | |
215 * checks if the Messpunkt can be committed. | |
216 * Disables the save button if false | |
217 */ | |
218 checkCommitEnabled: function() { | |
219 var savebutton = this.down('toolbar').down('button[action=save]'); | |
220 var form = this.getForm(); | |
221 if (form.isDirty()) { | |
222 if (form.findField('kdaId').getValue() || | |
223 form.findField('koordYExtern').getValue() || | |
224 form.findField('koordXExtern').getValue()) { | |
225 if (this.checkCoordinates()) { | |
226 savebutton.setDisabled(false); | |
227 } else { | |
228 savebutton.setDisabled(true); | |
229 } | |
230 } else if (form.findField('gemId').getValue() || | |
231 form.findField('staatId').getValue() >= 0 ) { | |
232 savebutton.setDisabled(false); | |
233 } else { | |
234 savebutton.setDisabled(true); | |
235 } | |
236 } else { | |
237 savebutton.setDisabled(true); | |
238 } | |
239 }, | |
240 | |
241 /** | |
242 * Validates the coordinate fields kdaId, koordXExtern, koordYExtern | |
243 */ | |
244 checkCoordinates: function() { | |
245 var x = this.getForm().findField('koordXExtern').getValue(); | |
246 var y = this.getForm().findField('koordYExtern').getValue(); | |
247 var kda = this.getForm().findField('kdaId').getValue(); | |
248 if (x && y && kda) { | |
249 if (kda === 4){ | |
250 if (x > -180 && x < 180 | |
251 && y > -90 && y < 90) { | |
252 return true; | |
253 } else { | |
254 // TODO: WGS84 (degrees- decimal), coordinates invalid | |
255 return false; | |
256 } | |
257 } else if (kda === 5){ | |
258 if (x >= 1000000 && x < 61000000 && | |
259 y > -10000000 && y < 10000000) { | |
260 return true; | |
261 } else { | |
262 // TODO: UTM, coordinates invalid | |
263 return false; | |
264 } | |
265 } else { | |
266 // TODO KDA not supported | |
267 return false; | |
268 } | |
269 } else { | |
270 // TODO: not all fields filled in | |
271 return false; | |
272 } | |
273 }, | |
274 | |
275 saveOrt: function() { | |
276 var this_panel = this.up('panel'); | |
277 var me = this; | |
278 var form = this_panel.getForm(); | |
279 var record = form.getRecord(); | |
280 var data = form.getFieldValues(true); | |
281 for (var key in data) { | |
282 record.set(key, data[key]); | |
283 } | |
284 record.set('id', null); | |
285 record.set('netzbetreiberId', Lada.netzbetreiber[0]); | |
286 record.save({ | |
287 success: function(newrecord, response) { | |
288 form.loadRecord(newrecord); | |
289 this_panel.down('verwaltungseinheit').store.load( | |
290 { id:newrecord.get('gemId') }); | |
291 console.log(this_panel.down('verwaltungseinheit')); | |
292 this_panel.down('staat').store.load( | |
293 { id : newrecord.get('staat') }); | |
294 me.setDisabled(true); | |
295 me.hide(); | |
296 var ozw = this_panel.up().parentWindow; | |
297 var json = Ext.decode(response.response.responseText); | |
298 if (json) { | |
299 this_panel.clearMessages(); | |
300 this_panel.setMessages(json.errors, json.warnings); | |
301 } | |
302 ozw.ortstore.load({ | |
303 callback: function(records, operation, success) { | |
304 ozw.down('map').addLocations(ozw.ortstore); | |
305 var osg = ozw.down('ortstammdatengrid'); | |
306 osg.setStore(ozw.ortstore); | |
307 var id = Ext.decode(response.response.responseText).data.id; | |
308 var record = osg.store.getById(id); | |
309 var selmod = osg.getView().getSelectionModel(); | |
310 selmod.select(record); | |
311 var resulttext; | |
312 if (json) { | |
313 if (json.message == '201') { | |
314 resulttext = 'Dieser Ort existiert bereits!'; | |
315 } | |
316 if (json.message == '200') { | |
317 resulttext = 'Ort erfolgreich angelegt!'; | |
318 } | |
319 } | |
320 Ext.Msg.show({ | |
321 title: Lada.getApplication().bundle.getMsg('success'), | |
322 autoScroll: true, | |
323 msg: resulttext, | |
324 buttons: Ext.Msg.OK | |
325 }); | |
326 }, | |
327 scope: this | |
328 }); | |
329 | |
330 }, | |
331 failure: function(record, response) { | |
332 var json = Ext.decode(response.response.responseText); | |
333 if (json) { | |
334 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ | |
335 formPanel.setMessages(json.errors, json.warnings); | |
336 } | |
337 if(json.message){ | |
338 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') | |
339 +' #'+json.message, | |
340 Lada.getApplication().bundle.getMsg(json.message)); | |
341 } else { | |
342 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), | |
343 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); | |
344 } | |
345 } else { | |
346 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), | |
347 Lada.getApplication().bundle.getMsg('err.msg.response.body')); | |
348 } | |
349 me.setDisabled(true); | |
350 } | |
351 }); | |
352 }, | 192 }, |
353 | 193 |
354 setMessages: function(errors, warnings) { | 194 setMessages: function(errors, warnings) { |
355 var key; | 195 var key; |
356 var element; | 196 var element; |
387 }, | 227 }, |
388 | 228 |
389 clearMessages: function() { | 229 clearMessages: function() { |
390 // TODO: this is a stub | 230 // TODO: this is a stub |
391 } | 231 } |
392 | |
393 }); | 232 }); |