Changeset 1196

Show
Ignore:
Timestamp:
07/01/09 19:30:36 (4 years ago)
Author:
tschaub
Message:

Separate adapter config from config for component being adapted.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • apps/opengeo/geoexplorer/trunk/src/script/app/GeoExplorer/LayerMenuItem.js

    r1194 r1196  
    1010 */ 
    1111 
    12 /** ..class:: GeoExplorer.LayerMenuItem(config) 
     12/** api: constructor 
     13 *  ..class:: LayerMenuItem(config) 
    1314 *      :param: config: the configuration for the menu item 
    1415 * 
     
    1819 
    1920/** api: config[layer]  
    20  * The :class:`GeoExt.data.LayerRecord` to be toggled. 
     21 * The :class:`GeoExt.data.LayerRecord` to be toggled. 
    2122 */ 
     23 
     24/** api: config[panelConfig] 
     25 *  A config object for the panel that is adapted to create this menu item. 
     26 */ 
     27 
    2228Ext.namespace("GeoExplorer"); 
    2329GeoExplorer.LayerMenuItem = function(config) { 
    24     config.layout = config.layout || 'column'; 
     30     
     31    var record = config.layerRecord; 
     32    var layer = record.get("layer"); 
    2533 
    26     this.panel = new Ext.Panel(config); 
    27     var layerRecord = config.layerRecord; 
     34    // create panel to be adapted as menu item 
     35    var panel = new Ext.Panel(Ext.applyIf(config.panelConfig || {}, { 
     36        layout: "column", 
     37        cls: "gx-layer-menu-item", 
     38        defautls: { 
     39            border: false 
     40        }, 
     41        items: [{ 
     42            xtype: record.get("background") ? "radio" : "checkbox", 
     43            checked: layer.getVisibility(), 
     44            handler: function(el, checked) { 
     45                layer.setVisibility(checked); 
     46            } 
     47        }, { 
     48            html: record.get("title") 
     49        }] 
     50    })); 
    2851 
    29     //var queryRadio = null; 
    30     //if (layerRecord.get("queryable")){ 
    31     //    queryRadio = new Ext.form.Radio({checked: false, name: 'query'}); 
    32     //} else { 
    33     //    queryRadio = new Ext.Panel(); 
    34     //} 
    35  
    36     var visibilityField = null; 
    37  
    38     if (layerRecord.get("background")) { 
    39         visibilityField = new Ext.form.Radio({ 
    40             checked: layerRecord.get("layer").getVisibility(), 
    41             handler: function(radio, checked) { 
    42                 layerRecord.get('layer').setVisibility(checked); 
    43             } 
    44         }); 
    45         //need to adjust the checkboxes according to layer visiblity 
    46     } else { 
    47         visibilityField = new Ext.form.Checkbox({ 
    48             checked: layerRecord.get("layer").getVisibility(),  
    49             handler: function (checkbox, checked) { 
    50                 layerRecord.get("layer").setVisibility(checked); 
    51             } 
    52         }); 
    53     } 
    54  
    55     this.panel.add(visibilityField); 
    56     //this.panel.add(queryRadio); 
    57     this.panel.add({html: layerRecord.get("title"), border: false}); 
    58     this.panel.addClass("gx-layer-menu-item"); 
    59  
    60     this.panel.on("render", function(panel){ 
    61         panel.getEl().swallowEvent("click"); 
     52    delete config.panelConfig; 
     53     
     54    // set default config for menu item 
     55    Ext.applyIf(config, { 
     56        handler: function(item) { 
     57            layer.setVisibility(!layer.getVisibility()); 
     58            panel.getEl().swallowEvent("click"); 
     59        } 
    6260    }); 
    6361 
    64     GeoExplorer.LayerMenuItem.superclass.constructor.call( 
    65         this,  
    66         this.panel,  
    67         config); 
     62    GeoExplorer.LayerMenuItem.superclass.constructor.call(this, panel, config); 
    6863}; 
    6964