[Commits] r1486 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Tue Nov 24 17:43:14 CET 2009
Author: bbinet
Date: 2009-11-24 17:43:14 +0100 (Tue, 24 Nov 2009)
New Revision: 1486
Modified:
core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js
core/trunk/geoext/tests/lib/GeoExt/widgets/LegendPanel.html
Log:
make LegendPanel listen to the clear event of the layerstore and remove all its components, r=elemoine (closes #178)
Modified: core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js 2009-11-24 06:48:46 UTC (rev 1485)
+++ core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js 2009-11-24 16:43:14 UTC (rev 1486)
@@ -101,6 +101,7 @@
this.layerStore.on({
"add": this.onStoreAdd,
"remove": this.onStoreRemove,
+ "clear": this.onStoreClear,
"update": this.onStoreUpdate,
scope: this
});
@@ -210,6 +211,23 @@
}
},
+ /** private: method[onStoreClear]
+ * Private method called when a layer store is cleared.
+ *
+ * :param store: ``Ext.data.Store`` The store from which was cleared.
+ */
+ onStoreClear: function(store) {
+ this.removeAllLegends();
+ },
+
+ /** private: method[removeAllLegends]
+ * Remove all legends from this legend panel.
+ */
+ removeAllLegends: function() {
+ this.removeAll(true);
+ this.doLayout();
+ },
+
/** private: method[createLegendSubpanel]
* Create a legend sub panel for the layer.
*
@@ -306,11 +324,11 @@
if(this.layerStore) {
this.layerStore.un("add", this.onStoreAdd, this);
this.layerStore.un("remove", this.onStoreRemove, this);
+ this.layerStore.un("clear", this.onStoreClear, this);
this.layerStore.un("update", this.onStoreUpdate, this);
}
GeoExt.LegendPanel.superclass.onDestroy.apply(this, arguments);
}
-
});
/** api: xtype = gx_legendpanel */
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/LegendPanel.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/LegendPanel.html 2009-11-24 06:48:46 UTC (rev 1485)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/LegendPanel.html 2009-11-24 16:43:14 UTC (rev 1486)
@@ -157,6 +157,21 @@
mapPanel.destroy();
}
+ function test_clear(t) {
+ t.plan(2);
+ var mapPanel = loadMapPanel();
+ var lp = new GeoExt.LegendPanel({
+ renderTo: 'legendpanel'});
+ lp.render();
+ t.eq(lp.items.length, 1, "Same number of layers in legend panel and in layerstore");
+
+ mapPanel.layers.removeAll();
+ t.eq(lp.items.length, 0, "When layerstore is cleared, legend panel is cleared");
+
+ lp.destroy();
+ mapPanel.destroy();
+ }
+
function test_changelayername(t) {
t.plan(3);
var mapPanel = loadMapPanel();
More information about the Commits
mailing list