[Commits] r795 - sandbox/elemoine/playground/geoext/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Mon May 18 06:33:56 CEST 2009


Author: elemoine
Date: 2009-05-18 06:33:56 +0200 (Mon, 18 May 2009)
New Revision: 795

Modified:
   sandbox/elemoine/playground/geoext/lib/GeoExt/widgets/Action.js
Log:
(a) avoid activating and deactivating control more than once, (b) add docs


Modified: sandbox/elemoine/playground/geoext/lib/GeoExt/widgets/Action.js
===================================================================
--- sandbox/elemoine/playground/geoext/lib/GeoExt/widgets/Action.js	2009-05-18 04:33:09 UTC (rev 794)
+++ sandbox/elemoine/playground/geoext/lib/GeoExt/widgets/Action.js	2009-05-18 04:33:56 UTC (rev 795)
@@ -12,36 +12,66 @@
  */
 Ext.namespace("GeoExt");
 
-/** api: constructor
- *  .. class:: Action
+/** api: example
+ *  Sample code to create a toolbar with an OpenLayers control into it.
+ * 
+ *  .. code-block:: javascript
  *  
- *      A record that represents an ``OpenLayers.Feature.Vector``. This record
- *      will always have at least the following fields:
+ *      var ctrl = new OpenLayers.Control.ZoomToMaxExtent();
+ *      map.addControl(ctrl);
+ *      var action = GeoExt.Action.fromControl(ctrl, {
+ *          text: "max extent"
+ *      });
  *
- *      * feature ``OpenLayers.Feature.Vector``
- *      * state ``String``
- *      * fid ``String``
- *
+ *      var toolbar = new Ext.Toolbar([action]);
  */
 
+/** api: constructor
+ *  .. class:: Action(config)
+ *  
+ *      Create a GeoExt.Action instance. A GeoExt.Action is created
+ *      to insert an OpenLayers control in a toolbar as a button or
+ *      in a menu as a menu item. A GeoExt.Action instance can be
+ *      used like a regular Ext.Action, look at the Ext.Action API
+ *      doc for more detail.
+ */
 GeoExt.Action = Ext.extend(Ext.Action, {
 
-    uHandler: null,
+    /** api: config[control]
+     *  ``OpenLayers.Control`` The OpenLayers control wrapped in this action.
+     */
+    control: null,
 
+    /** private: property[uScope]
+     *  ``Object`` The user-provided scope, used when calling uHandler,
+     *  uToggleHandler, and uCheckHandler.
+     */
     uScope: null,
 
+    /** private: property[uHandler]
+     *  ``Function`` References the function the user passes through
+     *  the "handler" property.
+     */
+    uHandler: null,
+
+    /** private: property[uToggleHandler]
+     *  ``Function`` References the function the user passes through
+     *  the "toggleHandler" property.
+     */
     uToggleHandler: null,
 
+    /** private: property[uCheckHandler]
+     *  ``Function`` References the function the user passes through
+     *  the "checkHandler" property.
+     */
     uCheckHandler: null,
 
-    control: null,
-
-    master: false,
-
+    /** private */
     constructor: function(config) {
-        // config highjack
+        
+        // store the user scope and handlers
+        this.uScope = config.scope;
         this.uHandler = config.handler;
-        this.uScope = config.scope;
         this.uToggleHandler = config.toggleHandler;
         this.uCheckHandler = config.checkHandler;
 
@@ -53,6 +83,7 @@
         // set control in the instance, the Ext.Action
         // constructor won't do it for us
         var ctrl = this.control = config.control;
+        delete config.control;
 
         // register "activate" and "deactivate" listeners
         // on the control
@@ -67,8 +98,12 @@
         arguments.callee.superclass.constructor.call(this, config);
     },
 
+    /** private: method[pHandler]
+     *  :param cmp: ``Ext.Component`` The component that triggers the handler.
+     *
+     *  The private handler.
+     */
     pHandler: function(cmp) {
-        // cmp is the component that triggers this action
         var ctrl = this.control;
         if(ctrl &&
            ctrl.type == OpenLayers.Control.TYPE_BUTTON) {
@@ -79,6 +114,12 @@
         }
     },
 
+    /** private: method[pTogleHandler]
+     *  :param cmp: ``Ext.Component`` The component that triggers the toggle handler.
+     *  :param state: ``Boolean`` The state of the toggle.
+     *
+     *  The private toggle handler.
+     */
     pToggleHandler: function(cmp, state) {
         this.changeControlState(state);
         if(this.uToggleHandler) {
@@ -86,6 +127,12 @@
         }
     },
 
+    /** private: method[pCheckHandler]
+     *  :param cmp: ``Ext.Component`` The component that triggers the check handler.
+     *  :param state: ``Boolean`` The state of the toggle.
+     *
+     *  The private check handler.
+     */
     pCheckHandler: function(cmp, state) {
         this.changeControlState(state);
         if(this.uCheckHandler) {
@@ -93,44 +140,62 @@
         }
     },
 
+    /** private: method[changeControlState]
+     *  :param state: ``Boolean`` The state of the toggle.
+     *
+     *  Change the control state depending on the state boolean.
+     */
     changeControlState: function(state) {
-        //this.master = true;
         if(state) {
-            this.control.activate();
+            if(!this._activating) {
+                this._activating = true;
+                this.control.activate();
+                this._activating = false;
+            }
         } else {
-            this.control.deactivate();
+            if(!this._deactivating) {
+                this._deactivating = true;
+                this.control.deactivate();
+                this._deactivating = false;
+            }
         }
-        //this.master = false;
     },
 
+    /** private: method[onCtrlActivate]
+     *  
+     *  Called when this action's control is activated.
+     */
     onCtrlActivate: function() {
-        //if(!this.master) {
-            var ctrl = this.control;
-            if(ctrl.type == OpenLayers.Control.TYPE_BUTTON) {
-                this.enable();
-            } else {
-                // deal with buttons
-                this.safeCallEach("toggle", [true]);
-                // deal with check items
-                this.safeCallEach("setChecked", [true]);
-            }
-        //}
+        var ctrl = this.control;
+        if(ctrl.type == OpenLayers.Control.TYPE_BUTTON) {
+            this.enable();
+        } else {
+            // deal with buttons
+            this.safeCallEach("toggle", [true]);
+            // deal with check items
+            this.safeCallEach("setChecked", [true]);
+        }
     },
 
+    /** private: method[onCtrlDeactivate]
+     *  
+     *  Called when this action's control is deactivated.
+     */
     onCtrlDeactivate: function() {
-        //if(!this.master) {
-            var ctrl = this.control;
-            if(ctrl.type == OpenLayers.Control.TYPE_BUTTON) {
-                this.disable();
-            } else {
-                // deal with buttons
-                this.safeCallEach("toggle", [false]);
-                // deal with check items
-                this.safeCallEach("setChecked", [false]);
-            }
-        //}
+        var ctrl = this.control;
+        if(ctrl.type == OpenLayers.Control.TYPE_BUTTON) {
+            this.disable();
+        } else {
+            // deal with buttons
+            this.safeCallEach("toggle", [false]);
+            // deal with check items
+            this.safeCallEach("setChecked", [false]);
+        }
     },
 
+    /** private: method[safeCallEach]
+     *
+     */
     safeCallEach: function(fnName, args) {
         var cs = this.items;
         for(var i = 0, len = cs.length; i < len; i++){



More information about the Commits mailing list