Mercurial > lada > lada-client
comparison app/view/form/Ortserstellung.js @ 1284:faecbb446a04
Ortserstellung: new Messpunkt from map, clone or form
functional, still needs error handling and layout
author | Maximilian Krambach <mkrambach@intevation.de> |
---|---|
date | Tue, 24 Jan 2017 12:58:26 +0100 |
parents | 291df0037835 |
children | 08085b7d1d0b |
comparison
equal
deleted
inserted
replaced
1283:9d298c82575f | 1284:faecbb446a04 |
---|---|
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 /** | 9 /** |
10 * Form to create a new Messpunkt | 10 * Form to create a new Messpunkt |
11 * TODO: layout, saving, model | 11 * TODO: layout |
12 */ | 12 */ |
13 Ext.define('Lada.view.form.Ortserstellung', { | 13 Ext.define('Lada.view.form.Ortserstellung', { |
14 extend: 'Ext.form.Panel', | 14 extend: 'Ext.form.Panel', |
15 alias: 'widget.ortserstellungsform', | 15 alias: 'widget.ortserstellungsform', |
16 | |
17 model: 'Lada.model.Ortszuordnung',//TODO correct model needed | |
18 requires: [ | 16 requires: [ |
19 'Lada.view.widget.Verwaltungseinheit', | 17 'Lada.view.widget.Verwaltungseinheit', |
20 'Lada.view.widget.Staat' | 18 'Lada.view.widget.Staat' |
21 ], | 19 ], |
22 | 20 model: null, |
23 width: 900, | 21 |
24 height: 700, | 22 record: null, |
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 | 23 |
38 initComponent: function() { | 24 initComponent: function() { |
39 var i18n = Lada.getApplication().bundle; | 25 var i18n = Lada.getApplication().bundle; |
40 var me = this; | 26 var me = this; |
41 this.items = [{ //TODO: layout and input types | 27 this.items = [{ |
42 title: 'Neuen Messpunkt anlegen', | 28 xtype: 'netzbetreiber', |
43 dockedItems : [{ | 29 editable: false, |
44 xtype: 'toolbar', | 30 readOnly: true, |
45 dock: 'bottom', | 31 submitValue: true, |
46 border: '0, 1, 1, 1', | 32 fieldLabel: i18n.getMsg('netzbetreiberId'), |
47 style: { | 33 margin : '0, 5, 5, 5', |
48 borderBottom: '1px solid #b5b8c8 !important', | 34 labelWidth: 80, |
49 borderLeft: '1px solid #b5b8c8 !important', | 35 width: 150, |
50 borderRight: '1px solid #b5b8c8 !important' | 36 value: Lada.netzbetreiber |
51 }, | 37 }, { |
52 items: ['->', { | 38 xtype: 'checkbox', |
53 text: i18n.getMsg('save'), | 39 name: 'aktiv', |
54 disabled: true, | 40 fieldLabel: 'aktiv:' |
55 action: 'save', | 41 }, { |
56 handler: me.saveOrt | 42 xtype: 'displayfield', |
57 }, { | 43 align: 'right', |
58 text: i18n.getMsg('close'), | 44 value: 'D', |
59 action: 'close', | 45 labelWidth: 125, |
60 handler: function() { | 46 maxLength: 1, |
47 name: 'messpunktart', | |
48 fieldLabel: 'Art des Messpunktes:' | |
49 },{ | |
50 xtype: 'staat', | |
51 labelWidth: 125, | |
52 fieldLabel: i18n.getMsg('staat'), | |
53 name: 'staatId', | |
54 listeners: { | |
55 change: { | |
56 fn: function() { me.checkCommitEnabled() } | |
57 } | |
58 } | |
59 }, { | |
60 xtype: 'verwaltungseinheit', | |
61 labelWidth: 125, | |
62 fieldLabel: i18n.getMsg('orte.gemeinde'), | |
63 name: 'gemId', | |
64 listeners: { | |
65 change: { | |
66 fn: function() { me.checkCommitEnabled() } | |
67 } | |
68 } | |
69 }, { | |
70 xtype: 'numfield', | |
71 labelWidth: 125, | |
72 fieldLabel: i18n.getMsg('orte.kda'), | |
73 allowDecimals: false, | |
74 maxLength: 1, | |
75 name: 'kdaId', | |
76 listeners: { | |
77 change: { | |
78 fn: function() { me.checkCommitEnabled() } | |
79 } | |
80 } | |
81 }, { | |
82 xtype: 'numfield', | |
83 labelWidth: 125, | |
84 fieldLabel: i18n.getMsg('orte.koordx'), | |
85 name: 'koordXExtern', | |
86 allowDecimals: true, | |
87 decimalPrecision: 5, | |
88 maxLength: 10, | |
89 listeners: { | |
90 change: { | |
91 fn: function() { me.checkCommitEnabled() } | |
92 } | |
93 } | |
94 }, { | |
95 xtype: 'numfield', | |
96 labelWidth: 125, | |
97 fieldLabel: i18n.getMsg('orte.koordy'), | |
98 name: 'koordYExtern', | |
99 allowDecimals: true, | |
100 decimalPrecision: 5, | |
101 maxLength: 10, | |
102 listeners: { | |
103 change: { | |
104 fn: function() { me.checkCommitEnabled() } | |
105 } | |
106 } | |
107 }, { | |
108 xtype: 'numfield', | |
109 labelWidth: 125, | |
110 fieldLabel: 'Höhe:', | |
111 name: 'hoeheLand', | |
112 maxLength: 10, | |
113 allowDecimals: true | |
114 }, { | |
115 xtype: 'tfield', | |
116 labelWidth: 125, | |
117 maxLength: 100, | |
118 name: 'kurztext', | |
119 fieldLabel: i18n.getMsg('orte.kurztext'), | |
120 },{ | |
121 xtype: 'tfield', | |
122 labelWidth: 125, | |
123 fieldLabel: i18n.getMsg('orte.langtext'), | |
124 name: 'langtext' | |
125 },{ | |
126 xtype: 'tfield', | |
127 labelWidth: 125, | |
128 fieldLabel: 'Berichtstext:', | |
129 name: 'berichtstext' | |
130 }]; | |
131 this.dockedItems = [{ | |
132 xtype: 'toolbar', | |
133 dock: 'bottom', | |
134 border: '0, 1, 1, 1', | |
135 style: { | |
136 borderBottom: '1px solid #b5b8c8 !important', | |
137 borderLeft: '1px solid #b5b8c8 !important', | |
138 borderRight: '1px solid #b5b8c8 !important' | |
139 }, | |
140 items: ['->', { | |
141 text: i18n.getMsg('save'), | |
142 action: 'save', | |
143 handler: me.saveOrt, | |
144 disabled: true | |
145 }, { | |
146 text: i18n.getMsg('close'), | |
147 action: 'close', | |
148 handler: function() { | |
61 me.close(); | 149 me.close(); |
62 } | 150 } |
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 }] | 151 }] |
169 }]; | 152 }]; |
153 | |
170 //TODO: | 154 //TODO: |
171 // 'Anlage:'? | 155 // 'Anlage:'? |
172 // zone | 156 // zone |
173 // sektor | 157 // sektor |
174 // zustaendigkeit | 158 // zustaendigkeit |
175 // Messregime (mpArt) | 159 // Messregime (mpArt) |
176 // 'Prog.-Punkt:', ? | 160 // 'Prog.-Punkt:', ? |
177 // nutsCode | 161 // nutsCode |
178 // Ortszusatz-ID (ozId) | 162 // Ortszusatz-ID (ozId) |
179 me.callParent(arguments); | 163 this.callParent(arguments); |
180 this.prefillForm(); | 164 this.getForm().loadRecord(this.record); |
181 }, | 165 }, |
182 | 166 |
183 /** | 167 /** |
184 * checks Messpunktart and if the Messpunkt can be committed. | 168 * checks Messpunktart and if the Messpunkt can be committed. |
185 * Disables the save button if false | 169 * Disables the save button if false |
186 */ | 170 */ |
187 // TODO messpunktart is not yet finally defined | 171 // TODO messpunktart is not yet finally defined |
188 checkCommitEnabled: function() { | 172 checkCommitEnabled: function() { |
189 var savebutton = this.down('toolbar').down('button[action=save]'); | 173 var savebutton = this.down('toolbar').down('button[action=save]'); |
190 var form = this.getForm(); | 174 var form = this.getForm(); |
191 if (this.checkCoordinates()) { | 175 if (this.getForm().findField('kdaId').getValue() || |
192 form.findField('messpunktart').setValue('D'); | 176 this.getForm().findField('koordYExtern').getValue() || |
193 savebutton.setDisabled(false); | 177 this.getForm().findField('koordXExtern').getValue()) { |
194 } else if (form.findField('gemeinde').getValue()) { | 178 if (this.checkCoordinates()) { |
179 form.findField('messpunktart').setValue('D'); | |
180 savebutton.setDisabled(false); | |
181 } else { | |
182 savebutton.setDisabled(true); | |
183 } | |
184 } else if (form.findField('gemId').getValue()) { | |
195 form.findField('messpunktart').setValue('V'); | 185 form.findField('messpunktart').setValue('V'); |
196 savebutton.setDisabled(false); | 186 savebutton.setDisabled(false); |
197 } else if (form.findField('staatId')) { | 187 } else if (form.findField('staatId').getValue()) { |
198 form.findField('messpunktart').setValue('S'); | 188 form.findField('messpunktart').setValue('S'); |
199 savebutton.setDisabled(false); | 189 savebutton.setDisabled(false); |
200 } else { | 190 } else { |
201 form.findField('messpunktart').setValue('D'); | 191 form.findField('messpunktart').setValue('D'); |
202 savebutton.setDisabled(true); | 192 savebutton.setDisabled(true); |
235 // TODO: not all fields filled in | 225 // TODO: not all fields filled in |
236 return false; | 226 return false; |
237 } | 227 } |
238 }, | 228 }, |
239 | 229 |
240 saveOrt: function(){ | 230 saveOrt: function() { |
241 // TODO not yet implemented | 231 var this_panel = this.up('panel'); |
242 alert("save!"); | 232 var form = this_panel.getForm(); |
243 }, | 233 var data = form.getFieldValues(true); |
244 | 234 for (var key in data) { |
245 /** | 235 form.getRecord().set(key, data[key]); |
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 } | 236 } |
254 if (this.presets.staatId) { | 237 this_panel.record.set('letzteAenderung', 0); |
255 // TODO: staatID != staatISO | 238 this_panel.record.set('id', null); |
256 form.findField('staatId').setValue(me.presets.staatId); | 239 this_panel.record.set('ortId', null); |
257 } | 240 this_panel.record.set('netzbetreiberId', Lada.netzbetreiber[0]); |
258 if (this.presets.gemeinde) { | 241 console.log(this_panel.record); |
259 // TODO: ortId != gemeinde | 242 this_panel.record.save({ |
260 form.findField('gemeinde').setValue(this.presets.gemeinde); | 243 success: function(record, response) { |
261 } | 244 console.log(response); |
262 if (this.presets.kdaId) { | 245 var newOrtId; |
263 form.findField('kdaId').setValue(this.presets.kdaId); | 246 Ext.Msg.show({ |
264 } | 247 title: Lada.getApplication().bundle.getMsg('success'), |
265 if (this.presets.koordXExtern) { | 248 autoScroll: true, |
266 form.findField('koordXExtern').setValue(this.presets.koordXExtern); | 249 msg: 'Ort erfolgreich angelegt!', |
267 } | 250 buttons: Ext.Msg.OK |
268 if (this.presets.koordYExtern) { | 251 }); |
269 form.findField('koordYExtern').setValue(this.presets.koordYExtern); | 252 var ozw = this_panel.up().parentWindow; |
270 } | 253 ozw.ortstore.load({ |
271 if (this.presets.hoehe) { | 254 callback: function(records, operation, success) { |
272 // TODO hohe_ueber_NN? | 255 ozw.down('map').addLocations(ozw.ortstore); |
273 form.findField('hoehe').setValue(me.presets.hoehe); | 256 ozw.down('ortstammdatengrid').setStore(ozw.ortstore); |
274 } | 257 var id = Ext.decode(response.response.responseText).data.id; |
275 if (this.presets.kurztext) { | 258 var record = ozw.down('ortstammdatengrid').store.getById(id); |
276 form.findField('kurztext').setValue(this.presets.kurztext); | 259 var selectionmodel = ozw.down('ortstammdatengrid').getSelectionModel(); |
277 } | 260 console.log(record); |
278 if (this.presets.langtext) { | 261 selectionmodel.select(record); |
279 form.findField('langtext').setValue(this.presets.langtext); | 262 this_panel.close(); |
280 } | 263 }, |
281 if (this.presets.berichtstext) { | 264 scope: this |
282 form.findField('berichtstext').setValue(this.presets.berichtstext); | 265 }); |
283 } | 266 }, |
267 failure: function(record, response) { | |
268 console.log(response); | |
269 // TODO | |
270 // response.error.status | |
271 // response.error.statusText | |
272 // var json = Ext.decode(response.response.responseText); | |
273 // if (json) { | |
274 // if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ | |
275 // console.log(json.errors); | |
276 // console.log(json.warnings); | |
277 // formPanel.setMessages(json.errors, json.warnings); | |
278 // } | |
279 // if(json.message){ | |
280 // Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') | |
281 // +' #'+json.message, | |
282 // Lada.getApplication().bundle.getMsg(json.message)); | |
283 // } else { | |
284 // Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), | |
285 // Lada.getApplication().bundle.getMsg('err.msg.generic.body')); | |
286 // } | |
287 // } else { | |
288 // Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), | |
289 // Lada.getApplication().bundle.getMsg('err.msg.response.body')); | |
290 } | |
291 }); | |
284 } | 292 } |
285 }); | 293 }); |
286 |