Hi Jean,
This is a 3 part process:
1. Add an entry in the actions.ini file.
2. Create a javascript function for pass parameters to the PHP action.
3. Create a custom action (PHP) to do the work.
As an example we will consider the update selected action. The actions.ini file entry looks like:
- Code: Select all
[update_selected]
url="javascript:updateSelected('result_list')"
label="Update"
description="Update selected records"
category=selected_result_actions
permission=edit
icon="{$dataface_url}/images/edit.gif"
Key things to notice here:
1. The url refers to a javascript function, which takes a single parameter referring to the result list.
2. The category is 'selected_result_actions'. This is what causes the button to appear along the bottom of the result list.
Now the javascript function looks like:
- Code: Select all
function updateSelected(tableid){
var ids = getSelectedIds(tableid);
if ( ids.length == 0 ){
alert("Please first check boxes beside the records you wish to copy, and then press 'Copy'.");
return;
}
var form = document.getElementById("result_list_selected_items_form");
form.elements['--selected-ids'].value = ids.join("\n");
form.elements['-action'].value = 'copy_replace';
form.submit();
}
Things to notice here:
1. It takes a single parameter: tableid which refers to an html table (which is passed in the call to our function in the url attribute in the actions.ini file.
2. We obtain the selected record ids by calling the getSelectedIds() function (part of the xataface distribution).
3. We obtain a reference to the select list form and append an element for the selected ids (to pass to the PHP action). We also set the '-action' element of the form to name our PHP action that we will create.
4. Then we submit the form.
Finally, let's look at the PHP action. It basically needs to obtain Dataface_Record objects corresponding to the selected ids, and do something....
- Code: Select all
class dataface_actions_copy_replace {
....
function handle(&$params){
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$table =& Dataface_Table::loadTable($query['-table']);
$records = df_get_selected_records($query);
etc ....
Notice the use of the df_get_selected_records() function to obtain an array of records. From here you can do what you like with the action.
Hope this makes sense. Let me know if you require clarification.
-Steve