[Lada-commits] [PATCH] Datevalidation. When editing a timeperiod in a Probeform it is validated wheter begindate is before enddate. This only happens when the blur-event is fired. ToDo: Listen to Events from the Übernehmen Button of the DateTimePicker, ToDo: Somehow the ErrorMessages are not Cleared correctly when the form is restored

Wald Commits scm-commit at wald.intevation.org
Mon Apr 13 16:22:43 CEST 2015


# HG changeset patch
# User Dustin Demuth <dustin at intevation.de>
# Date 1428934954 -7200
# Node ID f124d24c8ade2663cffed33ba18b808abcec66b6
# Parent  b400629a2575d279dc1c86275fd19153c8fcd1b1
Datevalidation. When editing a timeperiod  in a Probeform it is validated wheter begindate is before enddate. This only happens when the blur-event is fired. ToDo: Listen to Events from the Übernehmen Button of the DateTimePicker, ToDo: Somehow the ErrorMessages are not Cleared correctly when the form is restored.

diff -r b400629a2575 -r f124d24c8ade app/controller/form/Probe.js
--- a/app/controller/form/Probe.js	Wed Apr 08 17:03:59 2015 +0200
+++ b/app/controller/form/Probe.js	Mon Apr 13 16:22:34 2015 +0200
@@ -19,6 +19,9 @@
             },
             'probeform': {
                 dirtychange: this.dirtyForm
+            },
+            'probeform [xtype="datetime"] field': {
+                blur: this.checkDate
             }
         });
     },
@@ -94,5 +97,44 @@
             form.owner.down('button[action=discard]').setDisabled(true);
             form.owner.up('window').enableChildren(); // todo this might not be true in all cases
         }
+    },
+
+    checkDate: function(field) {
+        var now = Date.now();
+        var w = 0 //amount of warnings
+        var e = 0 //errors
+        var emsg = '';
+        var wmsg = '';
+
+        if (field.getValue() > now){
+            wmsg += Lada.getApplication().bundle.getMsg('661');
+            w++;
+        }
+        // This field might be a field within a DateTime-Period.
+        // Search for Partner field (period: end/start) and validate
+        // End Before Start validation
+        if (field.period) {
+            var partners = new Array();
+                partners[0] = field.up('fieldset').down('datetime[period=start]').down().getValue()
+                partners[1] = field.up('fieldset').down('datetime[period=end]').down().getValue()
+            if (partners[0] && partners[1] && partners[0] > partners [1]) {
+                var msg = Lada.getApplication().bundle.getMsg('662');
+                field.up('fieldset').showWarningOrError(true, msg, false, '');
+            } else {
+                field.up('fieldset').clearMessages();
+            }
+        }
+
+        if (w) {
+            field.up().showWarnings(wmsg);
+        }
+        if (e) {
+            field.up().showErrors(emsg);
+        }
+
+        // Clear Warnings or Errors if none Are Present
+        if (w == 0 && e == 0) {
+            field.up().clearWarningOrError();
+        }
     }
 });
diff -r b400629a2575 -r f124d24c8ade app/view/form/Probe.js
--- a/app/view/form/Probe.js	Wed Apr 08 17:03:59 2015 +0200
+++ b/app/view/form/Probe.js	Mon Apr 13 16:22:34 2015 +0200
@@ -233,8 +233,9 @@
                         align: 'stretch'
                     },
                     items: [{
-                        xtype: 'fieldset',
+                        xtype: 'fset',
                         title: 'Probenentnahme',
+                        name: 'entnahmePeriod',
                         anchor: '100%',
                         width: '50%',
                         margin: '0, 5, 5, 5',
@@ -248,18 +249,21 @@
                             labelWidth: 90,
                             anchor: '100%',
                             name: 'probeentnahmeBeginn',
-                            format: 'd.m.Y H:i'
+                            format: 'd.m.Y H:i',
+                            period: 'start'
                         }, {
                             xtype: 'datetime',
                             fieldLabel: 'Ende',
                             labelWidth: 90,
                             anchor: '100%',
                             name: 'probeentnahmeEnde',
-                            format: 'd.m.Y H:i'
+                            format: 'd.m.Y H:i',
+                            period: 'end'
                         }]
                     }, {
-                        xtype: 'fieldset',
+                        xtype: 'fset',
                         title: 'Sollzeitraum',
+                        name: 'sollzeitPeriod',
                         anchor: '100%',
                         width: '50%',
                         margin: '0, 5, 5, 5',
@@ -273,14 +277,16 @@
                             labelWidth: 90,
                             anchor: '100%',
                             name: 'solldatumBeginn',
-                            format: 'd.m.Y H:i'
+                            format: 'd.m.Y H:i',
+                            period: 'start'
                         }, {
                             xtype: 'datetime',
                             fieldLabel: 'Bis',
                             labelWidth: 90,
                             anchor: '100%',
                             name: 'solldatumEnde',
-                            format: 'd.m.Y H:i'
+                            format: 'd.m.Y H:i',
+                            period: 'end'
                         }]
                     }]
                 }]
@@ -290,6 +296,7 @@
     },
 
     setRecord: function(record) {
+        this.clearMessages();
         this.getForm().loadRecord(record);
     },
 
@@ -343,6 +350,8 @@
         this.down('datetime[name=solldatumBeginn]').clearWarningOrError();
         this.down('datetime[name=solldatumEnde]').clearWarningOrError();
         //this.down('numberfield[name=probeNehmerId]').clearWarningOrError();
+        this.down('fset[name=entnahmePeriod]').clearMessages();
+        this.down('fset[name=sollzeitPeriod]').clearMessages();
     },
 
     setReadOnly: function(value) {
diff -r b400629a2575 -r f124d24c8ade app/view/widget/base/Datetime.js
--- a/app/view/widget/base/Datetime.js	Wed Apr 08 17:03:59 2015 +0200
+++ b/app/view/widget/base/Datetime.js	Mon Apr 13 16:22:34 2015 +0200
@@ -17,7 +17,7 @@
     ],
 
     layout: 'hbox',
-
+    tooltip: null,
     border: 0,
 
     margin: '0, 0, 5, 0',
@@ -31,7 +31,8 @@
             flex: 1,
             name: this.name,
             msgTarget: 'none',
-            listeners: this.listeners
+            listeners: this.listeners,
+            period: this.period
         });
         this.items = [dateField, {
             xtype: 'image',
@@ -52,11 +53,12 @@
     },
 
     showWarnings: function(warnings) {
+        this.clearWarningOrError();
         var img = this.down('image[name=warnImg]');
-        Ext.create('Ext.tip.ToolTip', {
+        this.tooltip = (!this.tooltip) ? Ext.create('Ext.tip.ToolTip', {
             target: img.getEl(),
             html: warnings
-        });
+        }) : this.tooltip.html = warnings;
         this.down('datetimefield').invalidCls = 'x-lada-warning';
         this.down('datetimefield').markInvalid('');
         img.show();
@@ -69,13 +71,14 @@
     },
 
     showErrors: function(errors) {
+        this.clearWarningOrError();
         var img = this.down('image[name=errorImg]');
         var warnImg = this.down('image[name=warnImg]');
         warnImg.hide();
-        Ext.create('Ext.tip.ToolTip', {
+        this.tooltip = (!this.tooltip) ? Ext.create('Ext.tip.ToolTip', {
             target: img.getEl(),
             html: errors
-        });
+        }) : this.tooltip.html = errors;
         this.down('datetimefield').invalidCls = 'x-lada-error';
         this.down('datetimefield').markInvalid('');
         img.show();
@@ -88,6 +91,7 @@
     },
 
     clearWarningOrError: function() {
+        this.down('datetimefield').clearInvalid();
         this.down('image[name=errorImg]').hide();
         this.down('image[name=warnImg]').hide();
     },
diff -r b400629a2575 -r f124d24c8ade app/view/widget/base/FieldSet.js
--- a/app/view/widget/base/FieldSet.js	Wed Apr 08 17:03:59 2015 +0200
+++ b/app/view/widget/base/FieldSet.js	Mon Apr 13 16:22:34 2015 +0200
@@ -14,8 +14,10 @@
     origColor: '',
     errorText: '',
     warningText: '',
+    tooltip: null,
 
     showWarningOrError: function(warning, warningText, error, errorText) {
+        this.clearMessages(); //Clear Errors and Warning first
         var ndx = 0;
         if (this.collapsible === true) {
             ndx = 1;
@@ -39,10 +41,15 @@
                     '<img src="resources/img/emblem-important.png" width="13" height="13" />  ' +
                     this.plainTitle;
             if (errorText) {
-                Ext.create('Ext.tip.ToolTip', {
-                    target: this.getEl().dom.firstChild.firstChild.firstChild.children[ndx],
-                    html: errorText
-                });
+                if (!this.tooltip) {
+                    Ext.create('Ext.tip.ToolTip', {
+                        target: this.getEl().dom.firstChild.firstChild.firstChild.children[ndx],
+                        html: errorText
+                    });
+                }
+                else {
+                    tooltip.html = errorText;
+                }
             }
             return;
         }
@@ -53,10 +60,15 @@
                     '<img src="resources/img/dialog-warning.png" width="13" height="13" />  ' +
                     this.plainTitle;
             if (warningText) {
-                Ext.create('Ext.tip.ToolTip', {
-                    target: this.getEl().dom.firstChild.firstChild.firstChild.children[ndx],
-                    html: warningText
-                });
+                if (!this.tooltip) {
+                    Ext.create('Ext.tip.ToolTip', {
+                        target: this.getEl().dom.firstChild.firstChild.firstChild.children[ndx],
+                        html: warningText
+                    });
+                }
+                else {
+                    tooltip.html = warningText;
+                }
             }
             return;
         }
diff -r b400629a2575 -r f124d24c8ade resources/i18n/Lada_de-DE.properties
--- a/resources/i18n/Lada_de-DE.properties	Wed Apr 08 17:03:59 2015 +0200
+++ b/resources/i18n/Lada_de-DE.properties	Mon Apr 13 16:22:34 2015 +0200
@@ -14,8 +14,8 @@
 632: Werte passen nicht zusammen
 651: Punkt nicht in Polygon
 652: Werte passen nicht zusammen
-661: Datum liegt in der Zukunft
-662: Anfang nach Ende
+661: Der Zeitpunkt liegt in der Zukunft
+662: Das Ende des Zeitraumes liegt vor dem Beginn
 697: Der zugrundeliegende Datensatz wurde in der Zwischenzeit verändert
 698: Kein Zugriff
 699: Keine Berechtigung


More information about the Lada-commits mailing list