diff app/view/widgets/LadaForm.js @ 83:8525e3525538

Move parsing the response in a seperate function.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Tue, 11 Jun 2013 11:17:33 +0200
parents 4a82e28dfcc4
children 5ad82cff1a21
line wrap: on
line diff
--- a/app/view/widgets/LadaForm.js	Tue Jun 11 09:59:07 2013 +0200
+++ b/app/view/widgets/LadaForm.js	Tue Jun 11 11:17:33 2013 +0200
@@ -65,14 +65,12 @@
 
             this.model.save({
                 callback: function(records, operation) {
+                    this.parseResponse(operation);
                     if (operation.wasSuccessful()) {
                         console.log('Save was successfull');
                         this.fireEvent('savesuccess', this, records, operation);
                     } else {
                         console.log('Save was not successfull');
-                        this.errors = this.translateReturnCodes(operation.request.scope.reader.jsonData["errors"]);
-                        this.warnings = this.translateReturnCodes(operation.request.scope.reader.jsonData["warnings"]);
-                        this.message = Lada.getApplication().bundle.getMsg(operation.request.scope.reader.jsonData["message"]);
                         this.form.markInvalid(this.errors);
                         this.fireEvent('savefailure', this, records, operation);
                     }
@@ -87,10 +85,12 @@
 
     onModelLoadSuccess: function(record, operation) {
         this.bindModel(record);
+        this.parseResponse(operation);
         this.fireEvent('loadsuccess', this, record, operation);
     },
 
     onModelLoadFailure: function(record, operation) {
+        this.parseResponse(operation);
         this.fireEvent('loadfailure', this, record, operation);
     },
 
@@ -100,6 +100,11 @@
             translated[k] = Lada.getApplication().bundle.getMsg(codes[k]);
         }
         return translated;
+    },
+    parseResponse: function(operation) {
+        this.errors = this.translateReturnCodes(operation.request.scope.reader.jsonData["errors"]);
+        this.warnings = this.translateReturnCodes(operation.request.scope.reader.jsonData["warnings"]);
+        this.message = Lada.getApplication().bundle.getMsg(operation.request.scope.reader.jsonData["message"]);
     }
 
 });

http://lada.wald.intevation.org