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

commits at geoext.org commits at geoext.org
Tue Jun 2 00:37:37 CEST 2009


Author: tschaub
Date: 2009-06-02 00:37:37 +0200 (Tue, 02 Jun 2009)
New Revision: 938

Modified:
   core/trunk/geoext/examples/popup.js
   core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js
   core/trunk/geoext/lib/GeoExt/widgets/Popup.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/Popup.html
Log:
Adding addToMapPanel and removeFromMapPanel hooks for components to do any specific processing before being added to or removed from the map panel container.  This changes popup use so you write panel.add(popup) instead of popup.addToMapPanel(panel).  r=elemoine (closes #45)

Modified: core/trunk/geoext/examples/popup.js
===================================================================
--- core/trunk/geoext/examples/popup.js	2009-06-01 22:01:47 UTC (rev 937)
+++ core/trunk/geoext/examples/popup.js	2009-06-01 22:37:37 UTC (rev 938)
@@ -36,7 +36,7 @@
                 }
             }
         });
-        popup.addToMapPanel(mapPanel);
+        mapPanel.add(popup);
     }
 
     // create popup on "featureselected"

Modified: core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js	2009-06-01 22:01:47 UTC (rev 937)
+++ core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js	2009-06-01 22:37:37 UTC (rev 938)
@@ -188,6 +188,26 @@
         this.updateMapSize();
     },
     
+    /** private: method[onBeforeAdd]
+     *  Private method called before a component is added to the panel.
+     */
+    onBeforeAdd: function(item) {
+        if(typeof item.addToMapPanel === "function") {
+            item.addToMapPanel(this);
+        }
+        GeoExt.MapPanel.superclass.onBeforeAdd.apply(this, arguments);
+    },
+    
+    /** private: method[remove]
+     *  Private method called when a component is removed from the panel.
+     */
+    remove: function(item, autoDestroy) {
+        if(typeof item.removeFromMapPanel === "function") {
+            item.removeFromMapPanel(this);
+        }
+        GeoExt.MapPanel.superclass.remove.apply(this, arguments);
+    },
+
     /** private: method[beforeDestroy]
      *  Private method called during the destroy sequence.
      */

Modified: core/trunk/geoext/lib/GeoExt/widgets/Popup.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/Popup.js	2009-06-01 22:01:47 UTC (rev 937)
+++ core/trunk/geoext/lib/GeoExt/widgets/Popup.js	2009-06-01 22:37:37 UTC (rev 938)
@@ -146,34 +146,36 @@
         GeoExt.Popup.superclass.initTools.call(this);
     },
 
-    /** api: method[addToMapPanel]
+    /** private: method[addToMapPanel]
      *  :param mapPanel: :class:`MapPanel` The panel to which this popup should
      *      be added.
      *  
      *  Adds this popup to a :class:`MapPanel`.  Assumes that the
      *  MapPanel's map is already initialized and that the
-     *  Popup's feature is on the map.
+     *  Popup's feature is on the map.  This method is called by the MapPanel's
+     *  add method.
      */
     addToMapPanel: function(mapPanel) {
         this.mapPanel = mapPanel;
         this.map = this.mapPanel.map;
-
-        mapPanel.add(this);
-        mapPanel.doLayout();
-
-        this.position();
-
-        /* Anchoring */
-        if(this.anchored) {
-            this.anchorPopup();
-        }
-
-        this.show();
-
-        /* Panning */
-        if(this.panIn) {
-            this.panIntoView();
-        }
+        
+        mapPanel.on({
+            "add": {
+                fn: function() {
+                    mapPanel.doLayout();
+                    this.position();
+                    if(this.anchored) {
+                        this.anchorPopup();
+                    }
+                    this.show();
+                    if(this.panIn) {
+                        this.panIntoView();
+                    }
+                },
+                single: true,
+                scope: this
+            }
+        });
     },
 
     /** api: method[setSize]
@@ -249,7 +251,6 @@
      *  MapPanel and adds it to the page body.
      */
     unanchorPopup: function() {
-        this.unbindFromMapPanel();
 
         //make the window draggable
         this.draggable = true;
@@ -284,10 +285,11 @@
         }
     },
 
-    /** private: method[unbindFromMapPanel]
+    /** private: method[removeFromMapPanel]
      *  Utility method for unbinding events that call for popup repositioning.
+     *  Called from the panel during panel.remove(popup).
      */
-    unbindFromMapPanel: function() {
+    removeFromMapPanel: function() {
         if(this.map && this.map.events) {
             //stop position with feature
             this.map.events.un({
@@ -296,9 +298,12 @@
             });
         }
 
-        this.un("resize", this.position);
-        this.un("collapse", this.position);
-        this.un("expand", this.position);
+        this.un("resize", this.position, this);
+        this.un("collapse", this.position, this);
+        this.un("expand", this.position, this);
+
+        delete this.mapPanel;
+        delete this.map;
     },
 
     /** private: method[panIntoView]
@@ -354,7 +359,7 @@
      *  Cleanup events before destroying the popup.
      */
     beforeDestroy: function() {
-        this.unbindFromMapPanel();
+        this.removeFromMapPanel();
         GeoExt.Popup.superclass.beforeDestroy.call(this);
     }
 });

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/Popup.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/Popup.html	2009-06-01 22:01:47 UTC (rev 937)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/Popup.html	2009-06-01 22:37:37 UTC (rev 938)
@@ -63,7 +63,7 @@
 
             var pop = popup(context.feature);
 
-            pop.addToMapPanel(context.mapPanel);
+            context.mapPanel.add(pop);
 
             t.ok(context.mapPanel.el.child("div." + pop.popupCls),"Map panel contains popup");
             
@@ -77,7 +77,7 @@
 
             var pop = popup(context.feature);
 
-            pop.addToMapPanel(context.mapPanel);
+            context.mapPanel.add(pop);
 
             pop.on({
                 'move' : function(c,x,y){
@@ -108,7 +108,7 @@
 
             var pop = popup(context.feature, context.mapPanel);
 
-            pop.addToMapPanel(context.mapPanel);
+            context.mapPanel.add(pop);
         
             pop.collapse();
 
@@ -145,31 +145,25 @@
 
         }
 
-        function test_Popup_beforeDestroy(t){
+        function test_Popup_destroy(t){
 
-            t.plan(0);
+            t.plan(1);
 
             var context = setupContext();
             var pop = popup(context.feature);
-            pop.addToMapPanel(context.mapPanel);
-
+            context.mapPanel.add(pop);
+            
+            var called = false;
             pop.on({
-                'move' : function(c,x,y){
-                    t.ok(false,"Move event fired improperly on " + action); //should happen twice, on call to position()
-                },
-                scope : this
+                move: function() {
+                    called = true;
+                }
             });
+            pop.destroy();
 
-            pop.beforeDestroy();
-
-            var action = "map move";
             context.map.events.triggerEvent("move");
-
-            action = "popup expand"
-            pop.expand();
             
-            action = "popup collapse";
-            pop.collapse();
+            t.ok(!called, "pop is not moved after it is destroyed");
             
             tearDown(context);
         }



More information about the Commits mailing list