Monday, March 2, 2009

Refresh Button with custom code for P4A Applications

I have been using p4a for over a year now and have created several custom codes to do little helpful things whle developing applications in it. One such thing is to create a button that will refresh the mask instead of clearing the cookies using the firefox web developer toolbar. This is a screen shot with the button.


I added the code to refresh the mask here: https://sourceforge.net/forum/message.php?msg_id=6595951 but I have included it below.

The function to create the toolbar is below:

function createToolBar() {

$toolbar = & $this->build('p4a_simple_toolbar', 'toolbar');
//$toolbar = & $this->build('p4a_simple_toolbar', 'toolbar');
$toolbar->buttons->save->setLabel('Save');
//$toolbar->addLabel($toolbar->buttons->save, 'Save Content');
//$toolbar->buttons->save->setTitle('Save Content');
$toolbar->buttons->new->setLabel('New');
$toolbar->buttons->delete->setLabel('Delete');
$toolbar->buttons->print->setLabel('Print Information');
$toolbar->buttons->cancel->setLabel('Cancel');

$toolbar->addSeparator('left');
$refreshMaskDefault = & $toolbar->addButton('refreshMaskDefault', 'reload', 'left');
$refreshMaskDefault->setLabel('Refresh Page');

$this->intercept($refreshMaskDefault, 'onClick', 'doRefreshOriginalPage');

$toolbar->setMask($this);
return $toolbar;
}

The function to refresh the maks is below:

function doRefreshOriginalPage(){
$p4a = & p4a::singleton();
$this->destroy();
$p4a->openMask($this->getName());
}

Anyone can add their image to the button but just use the code and refresh the mask without clearing the cookies. If there are any modifications to the code you can let me know. :) I am open to it.

6 comments:

Unknown said...

Hi Jerome
I need your expetise: I'm new to P4A and I'm having trouble with refreshing after I make changes to the code. For example, I'll add a menu item to the mask, or add a new database field to display but it will not refresh when I reload the page on the browser. How would I resolve this?
Thanks!

Regards,
Steve

Jerome Bailey said...

ok. thanks for your comment. how do you refresh the mask? can you post your code so i can take a look?

depending on where you add the field or button, you will need to either refresh the source or the entire mask. you will probably need to write a function to do this.

Jerome Bailey said...

did you try the function i wrote to refresh the mask? if you missed it, here it is:

function doRefreshOriginalPage(){
$p4a = & p4a::singleton();
$this->destroy();
$p4a->openPopup($this->getName());
}

try that and let me know how things go

Unknown said...

Thanks for the quick reply!
Where would this function be implemented?

Just to clarify, I'm playing around with the product_catalogue sample application that comes with the framework. So for example, when I add a menu item (in products_catalogue.php) as follows:


$this->menu->addItem("myItems", "My Items");
$this->menu->items->myItems->addItem("categories")
->implement("onclick", $this, "menuClick");

Refreshing the browser does not display the new menu item.

However, if I add $_SESSION = array(); to the index.php file, upload and refresh, the menu item shows. I then go back and comment out $_SESSION = array(); from the index file and upload again.

rgds
Steve

Jerome Bailey said...

you do not need to trouble the index file. have you tried clearing the session? if you havent, make sure you have the firefox developers toolbar and click on "cookies" then "clear session cookies".

Unknown said...

Jerome, just wanted to let you know that using the FireFox dev toolbar did the trick. Thanks!