Changeset 1257

Show
Ignore:
Timestamp:
10/30/08 10:06:47 (2 months ago)
Author:
elemoine
Message:

add removeControl to Toolbar (see #280)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/widgets/toolbar/Toolbar.js

    r1046 r1257  
    129129                this.toggleHandler(control, pressed); 
    130130            }, this); 
    131  
    132             //make sure the state of the control and the state of the button match 
    133             var self = this; 
     131            // make sure the state of the control and the state of the 
     132            // button match 
    134133            control.events.on({ 
    135                 "activate": function() { 
    136                     button.toggle(true); 
    137                 }, 
    138                 "deactivate": function() { 
    139                     button.toggle(false); 
    140                     self.checkDefaultControl(button, control); 
    141                 } 
     134                "activate": this.onControlActivate, 
     135                "deactivate": this.onControlDeactivate, 
     136                scope: this 
    142137            }); 
    143138        } 
     
    145140        this._buttons.push(button); 
    146141        return button; 
     142    }, 
     143 
     144    /** 
     145     * Method: removeControl 
     146     * Remove a control from the toolbar. 
     147     * 
     148     * Parameters: 
     149     * control - {<OpenLayers.Control>} The control to remove from 
     150     *     the toolbar. 
     151     */ 
     152    removeControl: function (control) { 
     153        var button = this.getButtonForControl(control); 
     154 
     155        button.destroy(); 
     156        OpenLayers.Util.removeItem(this._buttons, button); 
     157 
     158        control.events.un({ 
     159            "activate": this.onControlActivate, 
     160            "deactivate": this.onControlDeactivate, 
     161            scope: this 
     162        }); 
     163        this.map.removeControl(control); 
     164        OpenLayers.Util.removeItem(this.controls, control); 
     165    }, 
     166 
     167    /** 
     168     * onControlActivate 
     169     * Called when a control is activated. 
     170     * 
     171     * Parameters: 
     172     * evt - {Object} An object with an object property referencing 
     173     *     the control. 
     174     */ 
     175    onControlActivate: function(evt) { 
     176        var control = evt.object; 
     177        var button = this.getButtonForControl(control); 
     178        button.toggle(true); 
     179    }, 
     180 
     181    /** 
     182     * onControlDeactivate 
     183     * Called when a control is deactivated. 
     184     * 
     185     * Parameters: 
     186     * evt - {Object} An object with an object property referencing 
     187     *     the control. 
     188     */ 
     189    onControlDeactivate: function(evt) { 
     190        var control = evt.object; 
     191        var button = this.getButtonForControl(control); 
     192        button.toggle(false); 
     193        this.checkDefaultControl(button); 
    147194    }, 
    148195 
     
    313360     * Parameters: 
    314361     * button - {<Ext.Toolbar.Button>} 
    315      * control - {<OpenLayers.Control>} 
    316      */ 
    317     checkDefaultControl: function(button, control) { 
     362     */ 
     363    checkDefaultControl: function(button) { 
    318364        var group = button.toggleGroup; 
    319365        if(group) {