Mercurial > lada > lada-client
comparison app/controller/form/Messprogramm.js @ 757:b8502964f5c3
Added missing files. Added MmtMockup
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Wed, 06 May 2015 14:15:37 +0200 |
parents | |
children | b7484c7da2d4 |
comparison
equal
deleted
inserted
replaced
756:f2db1ae1d012 | 757:b8502964f5c3 |
---|---|
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 * A Controller for a Probe form | |
11 */ | |
12 Ext.define('Lada.controller.form.Messprogramm', { | |
13 extend: 'Ext.app.Controller', | |
14 | |
15 /** | |
16 * Initialize the Controller | |
17 */ | |
18 init: function() { | |
19 this.control({ | |
20 'messprogrammform button[action=save]': { | |
21 click: this.save | |
22 }, | |
23 'messprogrammform button[action=discard]': { | |
24 click: this.discard | |
25 }, | |
26 'messprogrammform': { | |
27 dirtychange: this.dirtyForm | |
28 }, | |
29 'messprogrammform [xtype="numberfield"]': { | |
30 change: this.synchronizeSlider, | |
31 blur: this.checkPeriod | |
32 }, | |
33 'messprogrammform probenintervall combobox': { | |
34 select: this.updateIntervalls | |
35 } | |
36 }); | |
37 }, | |
38 /** | |
39 * When the Probenintervall was changed, update the Sliders | |
40 * and the the numberfield. | |
41 */ | |
42 updateIntervalls: function(field, records) { | |
43 console.log('update Intervalls'); | |
44 var form = field.up('messprogrammform'); | |
45 var record = form.getRecord(); | |
46 form.populateIntervall(record, field.getValue()); | |
47 }, | |
48 | |
49 /** | |
50 * When the Slider was used, | |
51 * update the Value of the Teilintervallfields | |
52 */ | |
53 synchronizeFields: function(slider, newValue, thumb) { | |
54 console.log('Synchronize Fields'); | |
55 var formPanel = slider.up('form'); | |
56 if (thumb.index == 0) { | |
57 formPanel.getForm() | |
58 .findField('teilintervallVon') | |
59 .setValue(newValue); | |
60 } | |
61 else if (thumb.index == 1) { | |
62 formPanel.getForm() | |
63 .findField('teilintervallBis') | |
64 .setValue(newValue); | |
65 } | |
66 | |
67 }, | |
68 | |
69 /** | |
70 * When the IntervallFields were used, | |
71 * update the Slider | |
72 */ | |
73 synchronizeSlider: function(field, newValue, oldValue) { | |
74 console.log('Synchronize Slider'); | |
75 var formPanel = field.up('form'); | |
76 if (field.name == 'teilintervallVon') { | |
77 formPanel.down('probenintervallslider') | |
78 .setValue(0, newValue, false); | |
79 } | |
80 else if (field.name == 'teilintervallBis') { | |
81 formPanel.down('probenintervallslider') | |
82 .setValue(1, newValue, false); | |
83 } | |
84 | |
85 }, | |
86 /** | |
87 * The save function saves the content of the Location form. | |
88 * On success it will reload the Store, | |
89 * on failure, it will display an Errormessage | |
90 */ | |
91 save: function(button) { | |
92 var formPanel = button.up('form'); | |
93 var data = formPanel.getForm().getFieldValues(true); | |
94 for (var key in data) { | |
95 formPanel.getForm().getRecord().set(key, data[key]); | |
96 } | |
97 formPanel.getForm().getRecord().save({ | |
98 success: function(record, response) { | |
99 var json = Ext.decode(response.response.responseText); | |
100 if (json) { | |
101 button.setDisabled(true); | |
102 button.up('toolbar').down('button[action=discard]') | |
103 .setDisabled(true); | |
104 formPanel.clearMessages(); | |
105 formPanel.setRecord(record); | |
106 formPanel.setMessages(json.errors, json.warnings); | |
107 if (response.action === 'create' && json.success) { | |
108 button.up('window').close(); | |
109 var win = Ext.create('Lada.view.window.MessprogrammEdit', { | |
110 record: record | |
111 }); | |
112 win.show(); | |
113 win.initData(); | |
114 } | |
115 } | |
116 }, | |
117 failure: function(record, response) { | |
118 button.setDisabled(true); | |
119 button.up('toolbar').down('button[action=discard]') | |
120 .setDisabled(true); | |
121 var rec = formPanel.getForm().getRecord(); | |
122 rec.dirty = false; | |
123 formPanel.getForm().loadRecord(record); | |
124 var json = response.request.scope.reader.jsonData; | |
125 if (json) { | |
126 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ | |
127 formPanel.setMessages(json.errors, json.warnings); | |
128 } | |
129 | |
130 if(json.message){ | |
131 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') | |
132 +' #'+json.message, | |
133 Lada.getApplication().bundle.getMsg(json.message)); | |
134 } else { | |
135 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), | |
136 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); | |
137 } | |
138 formPanel.clearMessages(); | |
139 //formPanel.setRecord(record); | |
140 formPanel.setMessages(json.errors, json.warnings); | |
141 } else { | |
142 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), | |
143 Lada.getApplication().bundle.getMsg('err.msg.response.body')); | |
144 } | |
145 | |
146 } | |
147 }); | |
148 }, | |
149 | |
150 /** | |
151 * The discard function resets the Location form | |
152 * to its original state. | |
153 */ | |
154 discard: function(button) { | |
155 var formPanel = button.up('form'); | |
156 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); | |
157 formPanel.getForm().owner.populateIntervall( | |
158 formPanel.getForm().getRecord()); | |
159 }, | |
160 | |
161 /** | |
162 * The dirtyForm function enables or disables the save and discard | |
163 * button which are present in the toolbar of the form. | |
164 * The Buttons are only active if the content of the form was altered | |
165 * (the form is dirty). | |
166 */ | |
167 dirtyForm: function(form, dirty) { | |
168 if (dirty) { | |
169 form.owner.down('button[action=save]').setDisabled(false); | |
170 form.owner.down('button[action=discard]').setDisabled(false); | |
171 } | |
172 else { | |
173 form.owner.down('button[action=save]').setDisabled(true); | |
174 form.owner.down('button[action=discard]').setDisabled(true); | |
175 } | |
176 }, | |
177 | |
178 /** | |
179 * checkPeriod() is called when a fields defining an intervall | |
180 * were modified | |
181 * The function validates if the start is smaller than end. | |
182 */ | |
183 checkPeriod: function(field) { | |
184 | |
185 // This field might be a field within a Period. | |
186 // Search for Partner field (period: end/start) and validate | |
187 // End Before Start validation | |
188 if (field.period) { | |
189 var partners = new Array(); | |
190 partners[0] = field.up('fieldset').down('numberfield[period=start]').getValue() | |
191 partners[1] = field.up('fieldset').down('numberfield[period=end]').getValue() | |
192 if (partners[0] && partners[1] && partners[0] > partners [1]) { | |
193 var msg = Lada.getApplication().bundle.getMsg('662'); | |
194 field.up('fieldset').showWarningOrError(true, msg, false, ''); | |
195 } else { | |
196 field.up('fieldset').clearMessages(); | |
197 } | |
198 } | |
199 } | |
200 }); |