Mercurial > lada > lada-client
comparison app/view/window/MessprogrammOrt.js @ 797:b8fd43021c29
Added a Window to alter Orte of a Messprogramm
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Wed, 20 May 2015 16:48:03 +0200 |
parents | |
children | 097d4edc2f00 |
comparison
equal
deleted
inserted
replaced
796:7267bae1d43f | 797:b8fd43021c29 |
---|---|
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 * Window to add a Ort to a Messprogramm | |
11 */ | |
12 Ext.define('Lada.view.window.MessprogrammOrt', { | |
13 extend: 'Ext.window.Window', | |
14 alias: 'widget.messprogrammort', | |
15 | |
16 requires: [ | |
17 'Lada.model.Ort', | |
18 'Lada.view.panel.Map', | |
19 'Lada.view.widget.Location', | |
20 'Lada.view.form.Location' | |
21 ], | |
22 | |
23 collapsible: true, | |
24 maximizable: true, | |
25 autoshow: true, | |
26 layout: 'border', | |
27 constrain: true, | |
28 | |
29 parentWindow: null, | |
30 record: null, | |
31 | |
32 initComponent: function() { | |
33 var i18n = Lada.getApplication().bundle; | |
34 | |
35 this.title = i18n.getMsg('messprogrammort.window.title'); | |
36 this.buttons = [{ | |
37 text: i18n.getMsg('apply'), | |
38 scope: this, | |
39 handler: this.apply | |
40 }, { | |
41 text: i18n.getMsg('cancel'), | |
42 scope: this, | |
43 handler: function() { | |
44 this.close() | |
45 this.parentWindow.down('messprogrammform') | |
46 .ortWindow = null; | |
47 } | |
48 }]; | |
49 this.width = 900; | |
50 this.height = 515; | |
51 this.bodyStyle = {background: '#fff'}; | |
52 | |
53 // add listeners to change the window appearence when it becomes inactive | |
54 this.on({ | |
55 activate: function(){ | |
56 this.getEl().removeCls('window-inactive'); | |
57 }, | |
58 deactivate: function(){ | |
59 this.getEl().addCls('window-inactive'); | |
60 } | |
61 }); | |
62 | |
63 this.items = [{ | |
64 region: 'west', | |
65 border: 0, | |
66 layout: 'vbox', | |
67 items: [{ | |
68 xtype: 'fieldset', | |
69 title: i18n.getMsg('ortId'), | |
70 margin: 5, | |
71 items: [{ | |
72 border: 0, | |
73 margin: '0, 0, 10, 0', | |
74 items: [{ | |
75 xtype: 'location', | |
76 fieldLabel: i18n.getMsg('ortId'), | |
77 labelWidth: 80, | |
78 width: 280, | |
79 forceSelection: true, | |
80 name: 'ortId', | |
81 listeners: {//Update MapPanel etc... | |
82 select: this.updateDetails | |
83 } | |
84 }] | |
85 }] | |
86 }, { | |
87 xtype: 'locationform', | |
88 margin: 5, | |
89 recordId: this.record.get('ortId') | |
90 }] | |
91 }, { | |
92 xtype: 'fset', | |
93 bodyStyle: { | |
94 background: '#fff' | |
95 }, | |
96 layout: 'border', | |
97 name: 'mapfield', | |
98 title: 'Karte', | |
99 region: 'center', | |
100 padding: '5, 5', | |
101 margin: 5, | |
102 items: [{ | |
103 xtype: 'map', | |
104 region: 'center', | |
105 layout: 'border', | |
106 record: this.record.get('ortId') ? this.record : null, | |
107 bodyStyle: { | |
108 background: '#fff' | |
109 }, | |
110 name: 'map', | |
111 listeners: { //A listener which listens to the mappanels featureselected event | |
112 featureselected: this.selectedFeature | |
113 } | |
114 }] | |
115 }]; | |
116 this.callParent(arguments); | |
117 }, | |
118 | |
119 initData: function() { | |
120 //Only do this if an OrtId exists... | |
121 var ortId = this.record.get('ortId'); | |
122 | |
123 if (ortId) { | |
124 Ext.ClassManager.get('Lada.model.Ort').load(ortId, { | |
125 failure: function(record, action) { | |
126 // TODO | |
127 }, | |
128 success: function(record, response) { | |
129 var me = this; | |
130 if (record.get('treeModified') < record.get('parentModified')) { | |
131 Ext.Msg.show({ | |
132 title: 'Messprogramm nicht aktuell!', | |
133 msg: 'Das zugehörige Messprogramm wurde verändert.\nMöchten Sie zu dem Messprogramm zurückkehren und neu laden?\nOhne das erneute Laden des Messprogrammes wird das Speichern des Ortes nicht möglich sein.', | |
134 buttons: Ext.Msg.OKCANCEL, | |
135 icon: Ext.Msg.WARNING, | |
136 closable: false, | |
137 fn: function(button) { | |
138 if (button === 'ok') { | |
139 me.close(); | |
140 me.parentWindow.initData(); | |
141 me.parentWindow.down('messprogrammform') | |
142 .ortWindow = null; | |
143 } | |
144 else { | |
145 me.record.set('treeModified', me.probe.get('treeModified')); | |
146 } | |
147 } | |
148 }); | |
149 } | |
150 this.record = record; | |
151 }, | |
152 scope: this | |
153 }); | |
154 } | |
155 }, | |
156 | |
157 /** | |
158 * @private | |
159 * Override to display and update the map view in the panel. | |
160 */ | |
161 afterRender: function(){ | |
162 this.superclass.afterRender.apply(this, arguments); | |
163 var map = this.down('map'); | |
164 if (this.record.get('ortId')) { | |
165 map.selectFeature(this.record.get('ortId')); | |
166 } | |
167 else { | |
168 map.map.zoomToMaxExtent(); | |
169 } | |
170 }, | |
171 | |
172 /** | |
173 * This function is used by the MapPanel, when a Feature was selected | |
174 */ | |
175 selectedFeature: function(context, args) { | |
176 var feature = args[0]; | |
177 if (feature.attributes.id && | |
178 feature.attributes.id !== '') { | |
179 var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id); | |
180 context.up('window').down('locationform').setRecord(record); | |
181 context.up('window').down('locationform').setReadOnly(true); | |
182 context.up('window').down('location').down('combobox').setValue(record.id); | |
183 } | |
184 else { | |
185 context.up('window').down('locationform').setRecord(this.locationRecord); | |
186 context.up('window').down('locationform').setReadOnly(false); | |
187 } | |
188 }, | |
189 | |
190 /** | |
191 * updateDetails is used when a value is selected within the location combobox | |
192 * When this function is called, the map element within the window | |
193 * which is embedding this form is updated. | |
194 * | |
195 * Mostly the same as in Lada.controlle.form.Ort | |
196 */ | |
197 updateDetails: function(combobox, record) { | |
198 var win = combobox.up('window'); | |
199 var details = win.down('locationform'); | |
200 //var id = record[0].get('id'); // We are interested in the cbox... | |
201 var id = combobox.getValue(); | |
202 | |
203 if (details) { | |
204 var toLoad = Ext.data.StoreManager.get('locations').getById(id); | |
205 win.down('locationform').setRecord(toLoad); | |
206 win.down('map').selectFeature(id); | |
207 } | |
208 }, | |
209 | |
210 /** | |
211 * Write the selected ortId into the record, and update the MessprogrammWindow. | |
212 */ | |
213 apply: function(button) { | |
214 var win = button.up('window'); | |
215 var ortId = win.down('location').down('combobox').value; | |
216 if (this.parentWindow) { | |
217 this.parentWindow.down('messprogrammform').down('location') | |
218 .down('combobox').setValue(ortId); | |
219 } | |
220 | |
221 this.parentWindow.down('messprogrammform') | |
222 .ortWindow = null; | |
223 this.close(); | |
224 }, | |
225 setMessages: function(errors, warnings) { | |
226 //todo this is a stub | |
227 }, | |
228 | |
229 clearMessages: function() { | |
230 //todo this is a stub | |
231 } | |
232 }); | |
233 |