changeset 1295:171eacf989d8

Show error and warnings in new forms
author Maximilian Krambach <mkrambach@intevation.de>
date Thu, 02 Feb 2017 11:04:01 +0100
parents c1b7db04b39c
children 6043187c6e8d
files app/controller/form/Ortszuordnung.js app/view/form/Ortserstellung.js app/view/form/Ortszuordnung.js
diffstat 3 files changed, 47 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/form/Ortszuordnung.js	Thu Feb 02 10:34:53 2017 +0100
+++ b/app/controller/form/Ortszuordnung.js	Thu Feb 02 11:04:01 2017 +0100
@@ -91,10 +91,8 @@
                 if (json) {
                     if(Object.keys(json.errors).length > 0 ||
                         Object.keys(json.warnings).length > 0) {
-
                         formPanel.setMessages(json.errors, json.warnings);
                     }
-
                     if(json.message){
                         Ext.Msg.alert(i18n.getMsg('err.msg.save.title')
                             +' #'+json.message,
--- a/app/view/form/Ortserstellung.js	Thu Feb 02 10:34:53 2017 +0100
+++ b/app/view/form/Ortserstellung.js	Thu Feb 02 11:04:01 2017 +0100
@@ -271,6 +271,11 @@
             success: function(record, response) {
                 var newOrtId;
                 var ozw = this_panel.up().parentWindow;
+                var json = Ext.decode(response.response.responseText);
+                if (json) {
+                    this_panel.clearMessages();
+                    this_panel.setMessages(json.errors, json.warnings);
+                }
                 ozw.ortstore.load({
                     callback: function(records, operation, success) {
                         ozw.down('map').addLocations(ozw.ortstore);
@@ -286,7 +291,6 @@
                             msg: 'Ort erfolgreich angelegt!',
                             buttons: Ext.Msg.OK
                         });
-                        this_panel.close();
                     },
                     scope: this
                 });
@@ -312,5 +316,45 @@
                 }
             }
         });
-    }
+    },
+
+    setMessages: function(errors, warnings) {
+        var key;
+        var element;
+        var content;
+        var i18n = Lada.getApplication().bundle;
+        if (warnings) {
+            for (key in warnings) {
+                element = this.down('component[name=' + key + ']');
+                if (!element) {
+                    continue;
+                }
+                content = warnings[key];
+                var warnText = '';
+                for (var i = 0; i < content.length; i++) {
+                    warnText += i18n.getMsg(content[i].toString()) + '\n';
+                }
+                element.showWarnings(warnText);
+            }
+        }
+        if (errors) {
+            for (key in errors) {
+                element = this.down('component[name=' + key + ']');
+                if (!element) {
+                    continue;
+                }
+                content = errors[key];
+                var errorText = '';
+                for (var i = 0; i < content.length; i++) {
+                    errorText += i18n.getMsg(content[i].toString()) + '\n';
+                }
+                element.showErrors(errorText);
+            }
+        }
+     },
+
+    clearMessages: function() {
+        // TODO: this is a stub
+     }
+
 });
--- a/app/view/form/Ortszuordnung.js	Thu Feb 02 10:34:53 2017 +0100
+++ b/app/view/form/Ortszuordnung.js	Thu Feb 02 11:04:01 2017 +0100
@@ -208,7 +208,7 @@
                 for (var i = 0; i < content.length; i++) {
                     errorText += i18n.getMsg(content[i].toString()) + '\n';
                 }
-                element.markInvalid(errorText);
+                element.showErrors(errorText);
             }
         }
      },

http://lada.wald.intevation.org