diff app/controller/grid/ProbeList.js @ 977:56470a075e6e stammdatengrids

Added methods to the controllers to disable/enable buttons in the toolbar when rows are (de)selected
author Dustin Demuth <dustin@intevation.de>
date Thu, 03 Dec 2015 09:26:43 +0100
parents fb99332bb48e
children f73ca04d73a7
line wrap: on
line diff
--- a/app/controller/grid/ProbeList.js	Wed Dec 02 17:53:20 2015 +0100
+++ b/app/controller/grid/ProbeList.js	Thu Dec 03 09:26:43 2015 +0100
@@ -22,7 +22,9 @@
     init: function() {
         this.control({
             'probelistgrid': {
-                itemdblclick: this.editItem
+                itemdblclick: this.editItem,
+                select: this.activateButtons,
+                deselect: this.deactivateButtons
             },
             'probelistgrid toolbar button[action=addProbe]': {
                 click: this.addProbeItem
@@ -299,6 +301,39 @@
         });
     },
 
+    /**
+     * 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) {
+            grid.down('button[action=export]').disable();
+            grid.down('button[action=print]').disable();
+        }
+        else {
+            grid.down('button[action=export]').enable();
+            grid.down('button[action=print]').enable();
+        }
+    },
+
     reload: function(btn) {
         if (btn === 'yes') {
             location.reload();

http://lada.wald.intevation.org