Quick search:

8. Event handler

This application is situated in the example8 folder. To run it on your own server you need the same data as for example3. To try it out on the phpPeanuts website click here.

It extends a copy from example 7 with customization of a part through an event handler. In version 1.1 there is also an extra button added to the HoursCategory EditDetailsPage, this will be explained at the bottom here.

The event handler extends the Employee IndexPage itemTable with a column holding shortcuts to the items 'hours' property page. Setting an event handler on a part is a way of specializing the part. In order to specialize the itemTable we needed to know from where it was  included. This is similar to what we did in example 6, only now we found that the ItemTablePart is generated by the printItemTablePart method of ObjectIndexPage. To override that, we needed to specialize the page first. This is similar to example 7, the new page class is example8.EmployeeIndexPage.

The printItemTable method we implemented calls getInitItemTable
that creates the part object and initializes it by setting self (the page object) as the event handler for two events: printTableHeaders and printItemCells.

When the page object calls the printBody method of the part object, the part object will behave normally until it has to print the tableHeaders. Then, instead of calling its own default event handling method printTableHeaders, it calls our printTableHeaders on the page object. The first thing this method does is calling the original event handler on the part object. This prints the default table headers. Then it prints an empty table header for the extra column.

The printing of the item table takes its normal course from there, until the cells of an item need to be printed. Here again, our method on the page object is called instead of the default one, it calls back the default for printing the normal cells of the item. Then it prints a hyperlink to the items propertyPage. Also see how to assemble a hyperlink or form. This is repeated for each item.

In version 1.1 we also added an extra button to the HoursCategory EditDetailsPage. To do this we first needed to specialize the page. This is similar to example 7, the new page class is example8.HoursCategoryEditDetailsPage. Then we could override the getButtonsList method with our own version that calls the parent method and addes a button by calling its inherited getButton method. This is the simpelest way to add an extra button. For other ways see how to add, modify or remove a button.