changeset 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 f4a9fe78404f
files app/view/form/Messprogramm.js app/view/widget/DayOfYear.js app/view/widget/base/ComboBox.js app/view/window/Messprogramm.js
diffstat 4 files changed, 50 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/app/view/form/Messprogramm.js	Tue Oct 11 17:40:37 2016 +0200
+++ b/app/view/form/Messprogramm.js	Thu Oct 13 14:42:26 2016 +0200
@@ -115,7 +115,10 @@
                                 labelWidth: 95,
                                 allowBlank: false,
                                 editable: true,
-                                hidden: true
+                                hidden: true,
+                                listeners: {
+                                    validitychange: me.mstLaborValidity
+                                }
                             }, {
                                 xtype: 'messstelle',
                                 name: 'laborMstId',
@@ -125,7 +128,10 @@
                                 labelWidth: 95,
                                 allowBlank: false,
                                 editable: true,
-                                hidden: true
+                                hidden: true,
+                                listeners: {
+                                    validitychange: me.mstLaborValidity
+                                }
                             }, {
                                 xtype: 'netzbetreiber',
                                 name: 'netzbetreiberId',
@@ -482,6 +488,17 @@
         i.setMaxValue(max-1);
     },
 
+    /*
+     * Set validity of messstellelabor field (not part of the form) based
+     * on validitychange event of hidden mstId and laborMstId
+     */
+    mstLaborValidity: function(field, isValid) {
+        if (!isValid) {
+            field.up('fieldset').down('messstellelabor')
+                .down('combobox').markInvalid('');
+        }
+    },
+
     setRecord: function(messRecord) {
         this.clearMessages();
         this.getForm().loadRecord(messRecord);
--- a/app/view/widget/DayOfYear.js	Tue Oct 11 17:40:37 2016 +0200
+++ b/app/view/widget/DayOfYear.js	Thu Oct 13 14:42:26 2016 +0200
@@ -71,11 +71,13 @@
         var DOYField = Ext.create('Ext.form.field.Number', {
             name: this.name,
             hidden: true,
+            allowBlank: this.allowBlank,
             listeners: this.listeners
         });
         /* Use dirtychange to avoid endless loop with change listeners on
          * visible items. This one is for initialisation by the form. */
         DOYField.addListener('dirtychange', me.setFields);
+        DOYField.addListener('validitychange', me.validityChange);
 
         /*
          * Add hidden field and visible fields to let the user choose
@@ -166,15 +168,16 @@
         var month = panel.down('combobox').getValue();
         var day = panel.down('numberfield[hidden=false]').getValue();
         var maxDay = panel.down('numberfield[hidden=false]').maxValue;
+        var doy = null;
 
         if (month != null && day != null && day <= maxDay) {
             // create a date object with arbitrary non-leap year
             var date = new Date(1970, month, day);
 
             // day of year is 0-based in ExtJS, but 1-based in the model
-            var doy = Ext.Date.getDayOfYear(date) + 1;
-            panel.down('numberfield[hidden]').setValue(doy);
+            doy = Ext.Date.getDayOfYear(date) + 1;
         }
+        panel.down('numberfield[hidden]').setValue(doy);
     },
 
     /*
@@ -182,9 +185,6 @@
      * validate associated day value.
      */
     checkMaxDay: function() {
-        this.up('panel').down('numberfield[hidden=false]')
-            .clearInvalid();
-
         // create a date object with arbitrary non-leap year
         var maxDay = Ext.Date.getDaysInMonth(
             new Date(1970, this.getValue()));
@@ -193,9 +193,13 @@
 
         var curDay = this.up('panel')
             .down('numberfield[hidden=false]').getValue();
-        if (curDay > maxDay) {
+        if (curDay) {
+            if (curDay > maxDay) {
+                this.up('panel').down('numberfield[hidden=false]')
+                    .setValue(maxDay);
+            }
             this.up('panel').down('numberfield[hidden=false]')
-                .setValue(maxDay);
+                .clearInvalid();
         }
     },
 
@@ -238,6 +242,22 @@
         }
     },
 
+    /*
+     * When the hidden field is validated as part of a form, make the result
+     * user visible.
+     */
+    validityChange: function(field, isValid) {
+        if (!isValid) {
+            var errors = field.getActiveErrors()
+            field.up('panel').down('combobox').markInvalid(errors);
+            field.up('panel').down('numberfield[hidden=false]')
+                .markInvalid(errors);
+        } else {
+            field.up('panel').down('combobox').clearInvalid();
+            field.up('panel').down('numberfield[hidden=false]').clearInvalid();
+        }
+    },
+
     clearWarningOrError: function() {
         this.down('image[name=errorImg]').hide();
         this.down('image[name=warnImg]').hide();
--- a/app/view/widget/base/ComboBox.js	Tue Oct 11 17:40:37 2016 +0200
+++ b/app/view/widget/base/ComboBox.js	Thu Oct 13 14:42:26 2016 +0200
@@ -69,6 +69,9 @@
             hidden: true
         }];
         this.callParent(arguments);
+        /* listeners have been passed to combobox. Thus, clear them on panel
+         * to avoid double effects of events fired on combobox and panel. */
+        this.clearListeners();
     },
 
     showWarnings: function(warnings) {
--- a/app/view/window/Messprogramm.js	Tue Oct 11 17:40:37 2016 +0200
+++ b/app/view/window/Messprogramm.js	Thu Oct 13 14:42:26 2016 +0200
@@ -176,6 +176,7 @@
             this.down('messmethodengrid').setReadOnly(true);
             this.down('messprogrammform').setRecord(record);
         }
+        this.down('messprogrammform').isValid();
     },
 
     //This was used in a Probewindow, I left it here for reference...

http://lada.wald.intevation.org