diff app/view/widgets/LadaForm.js @ 515:66f3c5d258e2

Added save and discard buttons to proben header fields and listen to changes to enable or disable buttons.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 16 Dec 2014 13:21:54 +0100
parents 2b5aa0e6e641
children d2e90f117c20
line wrap: on
line diff
--- a/app/view/widgets/LadaForm.js	Tue Dec 16 13:20:33 2014 +0100
+++ b/app/view/widgets/LadaForm.js	Tue Dec 16 13:21:54 2014 +0100
@@ -94,9 +94,13 @@
         }
     },
 
+    reset: function() {
+        this.loadRecord(this.model);
+        this.updateOnChange();
+    },
+
     commit: function() {
         if (this.form.isDirty() && this.form.isValid()) {
-            this.form.updateRecord(this.model);
 
             var data = this.model.getAllData();
             var baseUrl = this.model.getProxy().url;
@@ -114,11 +118,13 @@
                 callback: function(option, success, response) {
                     this.parseResponse(response);
                     if (this.success) {
+                        this.form.updateRecord(this.model);
                         this.fireEvent(
                             'savesuccess',
                             this,
                             this.model,
                             response);
+                        this.updateOnChange();
                     }
                     else {
                         this.form.markInvalid(this.errors);
@@ -257,5 +263,31 @@
             messages.insert(0, label);
         }
         this.insert(0, messages);
+    },
+
+    updateOnChange: function() {
+        console.log(this.isDirty());
+        var childs = this.query('toolbar');
+        for (var i = childs.length - 1; i >= 0; i--) {
+            if (childs[i].ownerCt.xtype === 'panel') {
+                if (this.isDirty()) {
+                    childs[i].down('button[action=discard]').enable();
+                    childs[i].down('button[action=save]').enable();
+                }
+                else {
+                    childs[i].down('button[action=discard]').disable();
+                    childs[i].down('button[action=save]').disable();
+                }
+            }
+            else {
+                var btn = childs[i].down('button[action=add]');
+                if (this.isDirty()) {
+                    btn.disable();
+                }
+                else {
+                    btn.enable();
+                }
+            }
+        }
     }
 });

http://lada.wald.intevation.org