[Chameleon] button within a widget

Paul Spencer pspencer at dmsolutions.ca
Sat Nov 6 20:05:25 EST 2004


-Ken-ici,

to remove this error, you will need a method of detecting whether or not 
the button will be visible.  For simplicity, I will assume that you are 
using a member variable mbButtonIsVisible.

In all you GetXXXX functions, you will then do something like:

function GetJavascriptIncludes()
{
     if ($this->mbButtonIsVisible)
         $aReturn = $this->moButton->GetJavascriptIncludes();
     else
         $aReturn = array();
     //your includes
     return $aReturn;
}

Also, the code you have for your initialization function is unnecessary, 
or at least not the preferred way of coding a widget.  In particular, it 
should read:

$this->moButton->InitDefaults();
$this->moButton->SetOnClick( 'VTMAddData' );

and your widget tag should have the following:

<cwc2 type="[YourWidgetName]" styleresource="TextButtons" label="Add 
Data" image="icons/icon_update.png" [other params] >
   <image state="normal"/>
   <image state="hover"/>
   <image state="selected"/>
</cwc2>

The button code will then do the rest for you :)

Cheers

Paul
Ken-ichi wrote:
> Thanks for the tips Paul.  I've been working a different project for a 
> while, hence the lag.  I've successfully added a button to my widget 
> using your instructions and adapting some code from the UpdateMap 
> widget, but every time the page loads, I get a javascript error that reads:
> 
> image object for cwcimage_16 not found?
> 
> I'm fairly sure this is because the button is only drawn when the widget 
> is displaying results, which only happens when another widget is used to 
> select an area on the map.  So even though the button is not written 
> into the HTML, its JavaScript CWCButton object still is.  You can take a 
> look at this at http://fisher.cnr.berkeley.edu/vtm/data/mapbrowse/, and 
> using the Select VTM Quads tool to select quads on the map.  Whenever 
> quad results are not displayed you get the error.
> 
> Any ideas on how I can fix this?
> 
> -Ken-ichi
> 
> PS. My button-related InitDefaults() lines look like this:
> 
> 
> //initialize the Add Data button ($moButton)
>        $this->moButton->InitDefaults();
>        $this->moButton->SetOnClick( 'VTMAddData' );
> 
>        $this->moButton->mszStyleResource = "TextButtons";
>        $this->moButton->moParent->maParams['LABEL'] = "Add Data";
>        $oApp = GetChameleonApplication();
>        $szImage = $oApp->findFile( 'icons/icon_update.png' );
>        $this->moButton->maszImages['normal'] = 
> $this->moButton->GetImage( 'normal', array( "image" => $szImage ) );
>        $this->moButton->maszImages['hover'] = $this->moButton->GetImage( 
> 'hover', array( "image" => $szImage ) );
>        $this->moButton->maszImages['selected'] = 
> $this->moButton->GetImage( 'selected', array( "image" => $szImage ) );
>        $this->moButton->mszImageTip = "Add VTM Data";
> 
> 
> Paul Spencer wrote:
> 
>> You can easily do this ... the steps are (roughly):
>>
>> * include the button code:
>>
>> include_once( dirname(__FILE__)."/../Button.php" );
>>
>> * add a class member variable to hold the button object:
>>
>> class myWidget extends CWCWidget
>> {
>> var $moButton = null;
>>
>>
>> * In the constructor of your widget:
>>
>> $this->moButton = new CWCButton( $this );
>>
>> * In InitDefaults:
>>
>> $this->moButton->InitDefaults();
>> $this->moButton->SetOnClick( 'myWidgetFunction' );
>>
>> You will need to call all the functions that CWCButton uses, check 
>> Button.php to see which ones they are.  In general, it will be
>>
>> function GetJavascriptIncludes()
>> {
>>     $aReturn = $this->moButton->GetJavascriptIncludes();
>>
>>     //your includes
>>
>>     return $aReturn;
>> }
>>
>> there are several of these ... you need them ALL even if you don't do 
>> anything in the functions other than call the button function and 
>> return the resulting array.
>>
>> in DrawPublish() you can now do:
>>
>> $szButton = $this->moButton->DrawPublish();
>>
>> and then incorporate $szButton into your output that gets returned 
>> from DrawPublish.
>>
>> The button will call myWidgetFunction( ) when clicked.  
>> myWidgetFunction will receive the button object as the first 
>> parameter, then any other parameters you supplied (see Button.php to 
>> pass other parameters, its not usually necessary)
>>
>> Cheers,
>>
>> Paul
>>
>> Ken-ichi wrote:
>>
>>> Hi all.  I'm developing a custom and rather non-standard widget that 
>>> shows geospatial datasets based on a rectangular query, and then 
>>> allows the user to choose which results to add to the map.  It's 
>>> non-standard because it shows results in the same window as the map, 
>>> as opposed to a popup.  I want to add a submit button to the widget's 
>>> output (DrawPublish()) but I'm not sure how to go about embedding a 
>>> textbutton within a widget.  I supposed I could just include the 
>>> straight HTML for the form input in my widget, but I'd like to just 
>>> use a standard Chameleon textbutton if possible.  Is there a way to 
>>> do this?
>>>
>>> Thanks.
>>>
>>> -Ken-ichi
>>> _______________________________________________
>>> Chameleon mailing list
>>> Chameleon at lists.maptools.org
>>> http://lists.maptools.org/mailman/listinfo/chameleon
>>>
>>
> 
> 


More information about the Chameleon mailing list