diff app/view/grid/Messung.js @ 823:5ed0e6273888

Only enable delete button in grids when an entry was selected
author Dustin Demuth <dustin@intevation.de>
date Fri, 29 May 2015 14:03:18 +0200
parents ee8cce4b4522
children 07dfcdf5b41f
line wrap: on
line diff
--- a/app/view/grid/Messung.js	Fri May 29 14:02:21 2015 +0200
+++ b/app/view/grid/Messung.js	Fri May 29 14:03:18 2015 +0200
@@ -25,6 +25,8 @@
 
     warnings: null,
     errors: null,
+    readOnly: true,
+    allowDeselect: true,
 
     initComponent: function() {
         this.dockedItems = [{
@@ -121,8 +123,19 @@
                 return '<div id="' + id + '">Lade...</div>';
             }
         }];
+        this.listeners = {
+           select: {
+               fn: this.activateRemoveButton,
+               scope: this
+            },
+            deselect: {
+                fn: this.deactivateRemoveButton,
+                scope: this
+            }
+        };
         this.initData();
         this.callParent(arguments);
+        this.setReadOnly(true); //Grid is always initialised as RO
     },
 
     initData: function() {
@@ -212,8 +225,29 @@
             if (this.getPlugin('rowedit')){
                 this.getPlugin('rowedit').enable();
             }
-            this.down('button[action=delete]').enable();
+            //this.down('button[action=delete]').enable();
+            //always disabled, unless a row was selected
             this.down('button[action=add]').enable();
         }
+    },
+    /**
+     * Activate the Remove Button
+     */
+    activateRemoveButton: function(selection, record) {
+        var grid = this;
+        //only enable the remove buttone, when the grid is editable.
+        if (! grid.readOnly) {
+            grid.down('button[action=delete]').enable();
+        }
+    },
+    /**
+     * Activate the Remove Button
+     */
+    deactivateRemoveButton: function(selection, record) {
+        var grid = this;
+        //only enable the remove buttone, when the grid is editable.
+        if (! grid.readOnly) {
+            grid.down('button[action=delete]').disable();
+        }
     }
 });

http://lada.wald.intevation.org