[Lada-commits] [PATCH 1 of 5] Added methods to the controllers to disable/enable buttons in the toolbar when rows are (de)selected

Wald Commits scm-commit at wald.intevation.org
Fri Dec 4 15:29:17 CET 2015


# HG changeset patch
# User Dustin Demuth <dustin at intevation.de>
# Date 1449131203 -3600
# Branch stammdatengrids
# Node ID 56470a075e6e4b8ce705c01a8ba7d9ed766cd308
# Parent  3c770fc7cf1940003293240dd6a322605943549d
Added methods to the controllers to disable/enable buttons in the toolbar when rows are (de)selected

diff -r 3c770fc7cf19 -r 56470a075e6e app/controller/grid/MessprogrammeList.js
--- 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();
diff -r 3c770fc7cf19 -r 56470a075e6e app/controller/grid/ProbeList.js
--- 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();
diff -r 3c770fc7cf19 -r 56470a075e6e app/view/grid/MessprogrammeList.js
--- 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 = [];
diff -r 3c770fc7cf19 -r 56470a075e6e app/view/grid/ProbeList.js
--- 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 = [];


More information about the Lada-commits mailing list