[Commits] r1196 - apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer

commits at geoext.org commits at geoext.org
Wed Jul 1 19:30:36 CEST 2009


Author: tschaub
Date: 2009-07-01 19:30:36 +0200 (Wed, 01 Jul 2009)
New Revision: 1196

Modified:
   apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/LayerMenuItem.js
Log:
Separate adapter config from config for component being adapted.

Modified: apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/LayerMenuItem.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/LayerMenuItem.js	2009-07-01 16:08:31 UTC (rev 1195)
+++ apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/LayerMenuItem.js	2009-07-01 17:30:36 UTC (rev 1196)
@@ -9,7 +9,8 @@
  * extends = Ext.menu.Adapter
  */
 
-/** ..class:: GeoExplorer.LayerMenuItem(config)
+/** api: constructor
+ *  ..class:: LayerMenuItem(config)
  *      :param: config: the configuration for the menu item
  *
  *      A menu item for toggling a layer visibility, as used in 
@@ -17,54 +18,48 @@
  */
 
 /** api: config[layer] 
- * The :class:`GeoExt.data.LayerRecord` to be toggled.
+ *  The :class:`GeoExt.data.LayerRecord` to be toggled.
  */
+
+/** api: config[panelConfig]
+ *  A config object for the panel that is adapted to create this menu item.
+ */
+
 Ext.namespace("GeoExplorer");
 GeoExplorer.LayerMenuItem = function(config) {
-    config.layout = config.layout || 'column';
+    
+    var record = config.layerRecord;
+    var layer = record.get("layer");
 
-    this.panel = new Ext.Panel(config);
-    var layerRecord = config.layerRecord;
-
-    //var queryRadio = null;
-    //if (layerRecord.get("queryable")){
-    //    queryRadio = new Ext.form.Radio({checked: false, name: 'query'});
-    //} else {
-    //    queryRadio = new Ext.Panel();
-    //}
-
-    var visibilityField = null;
-
-    if (layerRecord.get("background")) {
-        visibilityField = new Ext.form.Radio({
-            checked: layerRecord.get("layer").getVisibility(),
-            handler: function(radio, checked) {
-                layerRecord.get('layer').setVisibility(checked);
+    // create panel to be adapted as menu item
+    var panel = new Ext.Panel(Ext.applyIf(config.panelConfig || {}, {
+        layout: "column",
+        cls: "gx-layer-menu-item",
+        defautls: {
+            border: false
+        },
+        items: [{
+            xtype: record.get("background") ? "radio" : "checkbox",
+            checked: layer.getVisibility(),
+            handler: function(el, checked) {
+                layer.setVisibility(checked);
             }
-        });
-        //need to adjust the checkboxes according to layer visiblity
-    } else {
-        visibilityField = new Ext.form.Checkbox({
-            checked: layerRecord.get("layer").getVisibility(), 
-            handler: function (checkbox, checked) {
-                layerRecord.get("layer").setVisibility(checked);
-            }
-        });
-    }
+        }, {
+            html: record.get("title")
+        }]
+    }));
 
-    this.panel.add(visibilityField);
-    //this.panel.add(queryRadio);
-    this.panel.add({html: layerRecord.get("title"), border: false});
-    this.panel.addClass("gx-layer-menu-item");
-
-    this.panel.on("render", function(panel){
-        panel.getEl().swallowEvent("click");
+    delete config.panelConfig;
+    
+    // set default config for menu item
+    Ext.applyIf(config, {
+        handler: function(item) {
+            layer.setVisibility(!layer.getVisibility());
+            panel.getEl().swallowEvent("click");
+        }
     });
 
-    GeoExplorer.LayerMenuItem.superclass.constructor.call(
-        this, 
-        this.panel, 
-        config);
+    GeoExplorer.LayerMenuItem.superclass.constructor.call(this, panel, config);
 };
 
 Ext.extend(GeoExplorer.LayerMenuItem, Ext.menu.Adapter);



More information about the Commits mailing list