changeset 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 3c770fc7cf19
children 7f5219b8e1bf
files app/controller/grid/MessprogrammeList.js app/controller/grid/ProbeList.js app/view/grid/MessprogrammeList.js app/view/grid/ProbeList.js
diffstat 4 files changed, 76 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/grid/MessprogrammeList.js	Wed Dec 02 17:53:20 2015 +0100
+++ b/app/controller/grid/MessprogrammeList.js	Thu Dec 03 09:26:43 2015 +0100
@@ -22,7 +22,9 @@
     init: function() {
         this.control({
             'messprogrammelistgrid': {
-                itemdblclick: this.editItem
+                itemdblclick: this.editItem,
+                select: this.activateButtons,
+                deselect: this.deactivateButtons
             },
             'messprogrammelistgrid toolbar button[action=addMessprogramm]': {
                 click: this.addMessprogrammItem
@@ -103,6 +105,37 @@
         }
     },
 
+    /**
+     * 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=genProbenFromMessprogramm]').disable();
+        }
+        else {
+            grid.down('button[action=genProbenFromMessprogramm]').enable();
+        }
+    },
+
     reload: function(btn) {
         if (btn === 'yes') {
             location.reload();
--- 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();
--- a/app/view/grid/MessprogrammeList.js	Wed Dec 02 17:53:20 2015 +0100
+++ b/app/view/grid/MessprogrammeList.js	Thu Dec 03 09:26:43 2015 +0100
@@ -35,7 +35,8 @@
             }, {
                 text: i18n.getMsg('messprogramme.button.generate'),
                 icon: 'resources/img/view-time-schedule-insert.png',
-                action: 'genProbenFromMessprogramm'
+                action: 'genProbenFromMessprogramm',
+                disabled: true // disabled on startup, will be enabled by controller if necessary
             }]
         }];
         this.columns = [];
--- a/app/view/grid/ProbeList.js	Wed Dec 02 17:53:20 2015 +0100
+++ b/app/view/grid/ProbeList.js	Thu Dec 03 09:26:43 2015 +0100
@@ -41,11 +41,13 @@
             }, {
                 text: i18n.getMsg('probe.button.export'),
                 icon: 'resources/img/svn-update.png',
-                action: 'export'
+                action: 'export',
+                disabled: true //disabled on start, enabled by the controller
             }, {
                 text: i18n.getMsg('probe.button.print'),
                 icon: 'resources/img/printer.png',
-                action: 'print'
+                action: 'print',
+                disabled: true //disabled on start, enabled by the controller
             }]
         }];
         this.columns = [];

http://lada.wald.intevation.org