[Commits] r2521 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Thu Dec 9 20:17:10 CET 2010


Author: tschaub
Date: 2010-12-09 20:17:10 +0100 (Thu, 09 Dec 2010)
New Revision: 2521

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/Action.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html
Log:
Allowing actions to deactivate controls when disabled. r=ahocevar (closes #385)

Modified: core/trunk/geoext/lib/GeoExt/widgets/Action.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/Action.js	2010-12-08 16:52:37 UTC (rev 2520)
+++ core/trunk/geoext/lib/GeoExt/widgets/Action.js	2010-12-09 19:17:10 UTC (rev 2521)
@@ -42,6 +42,12 @@
      */
     control: null,
 
+    /** api: config[deactivateOnDisable]
+     *  ``Boolean`` Deactivate the action's control when the action is disabled.
+     *  Default is ``false``.
+     */
+    deactivateOnDisable: false,
+
     /** api: config[map]
      *  ``OpenLayers.Map`` The OpenLayers map that the control should be added
      *  to.  For controls that don't need to be added to a map or have already
@@ -91,6 +97,9 @@
         // constructor won't do it for us
         var ctrl = this.control = config.control;
         delete config.control;
+        
+        this.deactivateOnDisable = !!config.deactivateOnDisable;
+        delete config.deactivateOnDisable;
 
         // register "activate" and "deactivate" listeners
         // on the control
@@ -223,5 +232,18 @@
                     });
             }
         }
+    },
+    
+    /** private: method[setDisabled]
+     *  :param v: ``Boolean`` Disable the action's components.
+     *
+     *  Override method on super to optionally deactivate controls on disable.
+     */
+    setDisabled : function(v) {
+        if (v && this.deactivateOnDisable && this.control && this.control.active) {
+            this.control.deactivate();
+        }
+        return GeoExt.Action.superclass.setDisabled.apply(this, arguments);
     }
+
 });

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html	2010-12-08 16:52:37 UTC (rev 2520)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html	2010-12-09 19:17:10 UTC (rev 2521)
@@ -8,7 +8,7 @@
 
     <script type="text/javascript">
         function test_constructor(t) {
-            t.plan(12)
+            t.plan(12);
 
             var ctrl, scope, handler, toggleHandler, checkHandler, cfg, action;
 
@@ -434,6 +434,31 @@
             
         }
         
+        function test_deactivateOnDisable(t) {
+            t.plan(7);
+
+            var act1 = new GeoExt.Action({
+                control: new OpenLayers.Control(),
+                map: new OpenLayers.Map()
+            });
+            t.eq(act1.deactivateOnDisable, false, "false by default");            
+
+            var act2 = new GeoExt.Action({
+                control: new OpenLayers.Control({active: true}),
+                map: new OpenLayers.Map(),
+                deactivateOnDisable: true
+            });
+            t.eq(act2.deactivateOnDisable, true, "set to true");
+            t.eq(act2.control.active, true, "control active");
+            t.ok(!act2.isDisabled(), "action not yet disabled");
+            
+            act2.disable();
+            t.ok(act2.isDisabled(), "action disabled");
+            t.eq(act2.control.active, false, "control deactivated on disable");
+            act2.enable();
+            t.eq(act2.control.active, false, "enabling action does not activate control");
+        }
+        
     </script>
   <body>
     <div id="toolbar"></div>



More information about the Commits mailing list