diff app/controller/form/Probe.js @ 717:f124d24c8ade

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.
author Dustin Demuth <dustin@intevation.de>
date Mon, 13 Apr 2015 16:22:34 +0200
parents f0bc5387abcc
children c2a6f7caa71b
line wrap: on
line diff
--- 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();
+        }
     }
 });

http://lada.wald.intevation.org