diff app/controller/grid/Datensatzerzeuger.js @ 1039:77e22ad5cc84

Use user 'funktionen' attribute to set read/write status for stammdaten.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 19 Feb 2016 13:59:24 +0100
parents 15d8c64049d1
children fa422d69940c
line wrap: on
line diff
--- a/app/controller/grid/Datensatzerzeuger.js	Fri Feb 19 13:58:43 2016 +0100
+++ b/app/controller/grid/Datensatzerzeuger.js	Fri Feb 19 13:59:24 2016 +0100
@@ -21,8 +21,9 @@
             'datensatzerzeugergrid': {
                 edit: this.gridSave,
                 canceledit: this.cancelEdit,
-                select: this.activateButtons,
-                deselect: this.deactivateButtons
+                select: this.buttonToggle,
+                deselect: this.buttonToggle,
+                itemdblclick: this.edit
             },
             'datensatzerzeugergrid button[action=add]': {
                 click: this.add
@@ -33,6 +34,11 @@
         });
     },
 
+    edit: function() {
+        var grid = Ext.ComponentQuery.query('datensatzerzeugergrid')[0];
+        grid.down('button[action=delete]').disable();
+    },
+
     /**
      * This function is called when the grids roweditor saves
      * the record.
@@ -69,8 +75,11 @@
         if (!context.record.get('id') ||
             context.record.get('id') === '') {
             editor.getCmp().store.remove(context.record);
+            this.buttonToggle();
         }
-        context.grid.getSelectionModel().deselect(context.record);
+        else {
+            this.buttonToggle(context.grid.getSelectionModel(), context.record);
+        }
     },
 
     /**
@@ -122,42 +131,30 @@
         });
         grid.down('button[action=delete]').disable();
     },
-    /**
-     * Toggles the buttons in the toolbar
-     **/
-    activateButtons: function(rowModel, record) {
-        var grid = rowModel.view.up('grid');
-        this.buttonToggle(true, grid);
-    },
-
-    /**
-     * Toggles the buttons in the toolbar
-     **/
-    deactivateButtons: function(rowModel, record) {
-        var grid = rowModel.view.up('grid');
-        // Only disable buttons when nothing is selected
-        if (rowModel.selected.items == 0) {
-            this.buttonToggle(false, grid);
-        }
-    },
 
     /**
      * Enables/Disables a set of buttons
      **/
-    buttonToggle: function(enabled, grid) {
-        if (!enabled) {
+    buttonToggle: function(rowModel, record) {
+        if (!Ext.Array.contains(Lada.funktionen, 4)) {
+            return;
+        }
+        var grid = Ext.ComponentQuery.query('datensatzerzeugergrid')[0];
+        if (!record) {
+            grid.down('button[action=delete]').disable();
+        }
+        if (record.get('readonly') ||
+            rowModel.selected.items.length === 0) {
             grid.down('button[action=delete]').disable();
         }
         else {
-            if (!grid.getPlugin('rowedit').editing) {
+            if (grid.getPlugin('rowedit').editing) {
             //only enable buttons, when grid is not beeing edited
+                grid.down('button[action=delete]').disable();
+            }
+            else {
                 grid.down('button[action=delete]').enable();
             }
-            //else turn them off again!
-            else {
-                this.buttonToggle(false, grid);
-            }
         }
     }
 });
-

http://lada.wald.intevation.org