comparison app/view/widget/DayOfYear.js @ 1212:3e6756b0fc97

Fix and complement validation of Messprogramm from.
author Tom Gottfried <tom@intevation.de>
date Thu, 13 Oct 2016 14:42:26 +0200
parents 85b018980347
children 01f083db45b7
comparison
equal deleted inserted replaced
1211:85b018980347 1212:3e6756b0fc97
69 * for/of the record of the form. 69 * for/of the record of the form.
70 */ 70 */
71 var DOYField = Ext.create('Ext.form.field.Number', { 71 var DOYField = Ext.create('Ext.form.field.Number', {
72 name: this.name, 72 name: this.name,
73 hidden: true, 73 hidden: true,
74 allowBlank: this.allowBlank,
74 listeners: this.listeners 75 listeners: this.listeners
75 }); 76 });
76 /* Use dirtychange to avoid endless loop with change listeners on 77 /* Use dirtychange to avoid endless loop with change listeners on
77 * visible items. This one is for initialisation by the form. */ 78 * visible items. This one is for initialisation by the form. */
78 DOYField.addListener('dirtychange', me.setFields); 79 DOYField.addListener('dirtychange', me.setFields);
80 DOYField.addListener('validitychange', me.validityChange);
79 81
80 /* 82 /*
81 * Add hidden field and visible fields to let the user choose 83 * Add hidden field and visible fields to let the user choose
82 * day and month to the panel. 84 * day and month to the panel.
83 */ 85 */
164 setDOY: function() { 166 setDOY: function() {
165 var panel = this.up('panel'); 167 var panel = this.up('panel');
166 var month = panel.down('combobox').getValue(); 168 var month = panel.down('combobox').getValue();
167 var day = panel.down('numberfield[hidden=false]').getValue(); 169 var day = panel.down('numberfield[hidden=false]').getValue();
168 var maxDay = panel.down('numberfield[hidden=false]').maxValue; 170 var maxDay = panel.down('numberfield[hidden=false]').maxValue;
171 var doy = null;
169 172
170 if (month != null && day != null && day <= maxDay) { 173 if (month != null && day != null && day <= maxDay) {
171 // create a date object with arbitrary non-leap year 174 // create a date object with arbitrary non-leap year
172 var date = new Date(1970, month, day); 175 var date = new Date(1970, month, day);
173 176
174 // day of year is 0-based in ExtJS, but 1-based in the model 177 // day of year is 0-based in ExtJS, but 1-based in the model
175 var doy = Ext.Date.getDayOfYear(date) + 1; 178 doy = Ext.Date.getDayOfYear(date) + 1;
176 panel.down('numberfield[hidden]').setValue(doy); 179 }
177 } 180 panel.down('numberfield[hidden]').setValue(doy);
178 }, 181 },
179 182
180 /* 183 /*
181 * Call from listener of month selection widget to set maximum and 184 * Call from listener of month selection widget to set maximum and
182 * validate associated day value. 185 * validate associated day value.
183 */ 186 */
184 checkMaxDay: function() { 187 checkMaxDay: function() {
185 this.up('panel').down('numberfield[hidden=false]')
186 .clearInvalid();
187
188 // create a date object with arbitrary non-leap year 188 // create a date object with arbitrary non-leap year
189 var maxDay = Ext.Date.getDaysInMonth( 189 var maxDay = Ext.Date.getDaysInMonth(
190 new Date(1970, this.getValue())); 190 new Date(1970, this.getValue()));
191 this.up('panel').down('numberfield[hidden=false]') 191 this.up('panel').down('numberfield[hidden=false]')
192 .setMaxValue(maxDay); 192 .setMaxValue(maxDay);
193 193
194 var curDay = this.up('panel') 194 var curDay = this.up('panel')
195 .down('numberfield[hidden=false]').getValue(); 195 .down('numberfield[hidden=false]').getValue();
196 if (curDay > maxDay) { 196 if (curDay) {
197 if (curDay > maxDay) {
198 this.up('panel').down('numberfield[hidden=false]')
199 .setValue(maxDay);
200 }
197 this.up('panel').down('numberfield[hidden=false]') 201 this.up('panel').down('numberfield[hidden=false]')
198 .setValue(maxDay); 202 .clearInvalid();
199 } 203 }
200 }, 204 },
201 205
202 206
203 showWarnings: function(warnings) { 207 showWarnings: function(warnings) {
236 var errorText = i18n.getMsg(this.name) + ': ' + errors; 240 var errorText = i18n.getMsg(this.name) + ': ' + errors;
237 fieldset.showWarningOrError(false, '', true, errorText); 241 fieldset.showWarningOrError(false, '', true, errorText);
238 } 242 }
239 }, 243 },
240 244
245 /*
246 * When the hidden field is validated as part of a form, make the result
247 * user visible.
248 */
249 validityChange: function(field, isValid) {
250 if (!isValid) {
251 var errors = field.getActiveErrors()
252 field.up('panel').down('combobox').markInvalid(errors);
253 field.up('panel').down('numberfield[hidden=false]')
254 .markInvalid(errors);
255 } else {
256 field.up('panel').down('combobox').clearInvalid();
257 field.up('panel').down('numberfield[hidden=false]').clearInvalid();
258 }
259 },
260
241 clearWarningOrError: function() { 261 clearWarningOrError: function() {
242 this.down('image[name=errorImg]').hide(); 262 this.down('image[name=errorImg]').hide();
243 this.down('image[name=warnImg]').hide(); 263 this.down('image[name=warnImg]').hide();
244 }, 264 },
245 265

http://lada.wald.intevation.org