 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
shaggydog97
Joined: 18 Jul 2007 Posts: 10
|
Posted: Wed Jul 18, 2007 8:42 pm Post subject: The Big Three |
|
|
Would it be possible to combine, Structures_DataGrid, HTML_QuickForm, and HTML_AJAX, to create an edit-in-place DataGrid? I have created an pseudo edit-in-place DataGrid with a custom script, built on top of prototype.js, but the javascript was pretty messy.
It had edit buttons, instead of an event handler, to switch between divs I created with a column formatter callback, and those coming from an ajax proxy page.
Is there a better approach? |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1049
|
Posted: Wed Jul 18, 2007 10:10 pm Post subject: |
|
|
Using QuickForm might be overkill here, but it should be possible. If you don't like to use a formatter, you could also overload (e.g.) the HTMLTable renderer, and add the desired code there.
A combination of SDG and QF can be seen in the CheckableHTMLTable renderer which extends the HTMLTable renderer. It is available only in CVS currently. The idea of this renderer is to add a column with a checkbox for each row.
And while were at the AJAX topic: We don't have concrete plans for supporting such an in-place-editing feature currently, although this would be a nice addition, of course. But we have an AJAX example available (needs CVS code of SDG, and optionally also CVS code of the Pager package), which shows how the output of a renderer (e.g. an HTML table or a block of paging links) can be replaced.
If you have more ideas on this topic, need more help, or whatever, please ask/write here, or send me an email. New ideas are always welcome. |
|
| Back to top |
|
 |
shaggydog97
Joined: 18 Jul 2007 Posts: 10
|
Posted: Wed Jul 18, 2007 10:26 pm Post subject: The Big Three |
|
|
| It almost seems possible to do this with the existing code base. Maybe an experiment is in order... I'll let you know what I come up with. This might turn out to just being a how-to, not necessarily a sub-package. |
|
| Back to top |
|
 |
shaggydog97
Joined: 18 Jul 2007 Posts: 10
|
Posted: Thu Jul 19, 2007 7:26 pm Post subject: The Big Three |
|
|
I got it Working!!!
Step 1: Follow how-to's and create DB_DataObjects using createTables.php script
Step 2: Setup your DATABASE.links.ini file
Step 3: Use DB_DataObject_FormBuilder to build the forms
Step 4: Build DataGrids from the DataObjects, either use column formatter call backs, or like I did, use a template renderer
Step 5: Send the QuickForm array build by FormBuilder to a template or just echo the html. Do not use QuickForm_Renderer_ArraySmarty, it does not separate the form element's into their own array like the Default Renderer does.
Step 6: Use HTML_AJAX.replace and put javascript "onClick" methods onto the datagrid <tr>'s that swap them to the quickForm elements
I am using Edit/Delete and Cancel/Save buttons for my dataGrid, so it's not truly edit in place. I just don't like fooling with event handlers if I don't have to.
You will need some way to identify which record you are editing, so I added id's to my <tr>'s, they are just the primary key's for the table
READ THIS NOW !!!!!!!!!!
DO NOT COPY AND PASTE THIS CODE!!! THIS IS NOT A COMPLETE HOW TO.
You should be intimately familiar with DB_DataObjects, DB_DataObject_FormBuilder, Structures_DataGrids, and QuickForm before attempting this
Part of my DataGrid Smarty Template:
| Code: |
<!-- Build body -->
{section name=row loop=$recordSet}
<tr onclick="HTML_AJAX.replace(this,'index.php?edit={$TABLE}&id={$recordSet[row][0]}');" id="{$recordSet[row][0]}" {if $smarty.section.row.iteration is even}bgcolor="#EEEEEE"{/if}>
{section name=col loop=$recordSet[row]}
<td id="{$recordSet[row][0]}-{$columnSet[col].name}" {$columnSet[col].attributes}>{$recordSet[row][col]}</td>
{/section}
</tr>
{/section}
|
My Controller Page:
Note the Variable Variable's
| Code: | <?PHP
/* admin.php
*
* This is the Admin front page logic
* Note: Tthis script uses Varible Varible names to call the tables
* Usage ?edit=TABLENAME for a form or ?view=TABLENAME for a datagrid
* Pass &id=KEY to ?edit to edit a specific record
* Post &where=WHERE CLAUSE to ?view to filter the dataGrid
*/
/* Debugging Code */
//DB_DataObject::debugLevel(5); //Enable
//$all_tpl_vars = $smarty->get_template_vars();
//echo "<pre>\n";
//print_r($all_tpl_vars);
//echo "</pre>\n";
/* End Debugging Code */
require("include.php");
if ( isset($_GET['edit']) ) { // Create a New Record, send an id to edit
require_once('DB/DataObject/FormBuilder.php');
require_once ('HTML/QuickForm/Renderer/ArraySmarty.php');
$$_GET['edit'] = DB_DataObject::factory($_GET['edit']);
if (isset($_GET['id'])) { // Check for ID to edit a record
$$_GET['edit']->get($_GET['id']);
}
if (PEAR::isError($$_GET['edit'])) {
die( "Sorry... we were unable to process your request! <br /><br />". $$_GET['edit']->getMessage() );
}
/* Build the form */
$formBuilder =& DB_DataObject_FormBuilder::create($$_GET['edit']);
$formBuilder->linkDisplayLevel = 3;
$form =& $formBuilder->getForm();
/* Validate the form */
if($form->validate()) {
$form->process(array(&$formBuilder, 'processForm'), false);
//this is optional, you can comment out this to make the form appear for editing again
$form->freeze();
}
/* Display the form */
$smarty->assign('form_data', $form->toArray());
$smarty->display('form.tpl');
$all_tpl_vars = $smarty->get_template_vars();
} else if (isset($_GET['view']) ) { //Display Datatable
$smarty->assign('TITLE', 'Admin Page');
$smarty->assign('HEADER', 'Admin Control Panel');
$smarty->display(FS_ROOT.'templates/index.tpl');
require 'Structures/DataGrid.php';
$$_GET['view'] = DB_DataObject::factory($_GET['view']);
$datagrid =& new Structures_DataGrid(20);
if (isset($_POST['where']) ) {
$$_GET['view']->whereAdd($_POST['where']);
}
$test = $datagrid->bind($$_GET['view']);
/* Print binding error if any */
if (PEAR::isError($test)) {
die( "Sorry... we were unable to process your request! <br /><br />". $test->getMessage() );
}
if ($datagrid->getRecordCount() == 0) {
echo "No Records";
}
/* Fill the template will the datagrid */
$test = $datagrid->fill($smarty);
/* Print rendering error if any */
if (PEAR::isError($test)) {
echo $test->getMessage();
}
//$all_tpl_vars = $smarty->get_template_vars();
//echo "<pre>\n";
//print_r($all_tpl_vars);
//echo "</pre>\n";
$smarty->assign('TABLE', $_GET['view'] );
$smarty->display('datagrid.tpl');
} else {
$smarty->assign('TITLE', 'Admin Page');
$smarty->assign('HEADER', 'Admin Control Panel');
$smarty->display(FS_ROOT.'templates/index.tpl');
}
?> |
Useful? |
|
| Back to top |
|
 |
shaggydog97
Joined: 18 Jul 2007 Posts: 10
|
Posted: Thu Jul 19, 2007 7:32 pm Post subject: The Big Three |
|
|
Oh here's the form template:
| Code: |
<tr id="{$form_data.sections[0].elements[0].value}" {if $smarty.section.row.iteration is even}bgcolor="#EEEEEE"{/if}>
<td id="{$form_data.sections[0].elements[0].value}-{$form_data.sections[0].elements[0].name}" >{$form_data.sections[0].elements[0].value}</td>
{section name=col loop=$form_data.sections[0].elements}
<td id="{$form_data.sections[0].elements[col].value}-{$form_data.sections[0].elements[col].name}" >{$form_data.sections[0].elements[col].html}</td>
{/section}
</tr>
|
|
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1049
|
Posted: Fri Jul 20, 2007 12:12 pm Post subject: |
|
|
| Nice to read that it works now. Unfortunately, your example is IMHO too complex for putting it as an example into the package or the manual. |
|
| Back to top |
|
 |
shaggydog97
Joined: 18 Jul 2007 Posts: 10
|
Posted: Fri Jul 20, 2007 2:08 pm Post subject: The Big Three |
|
|
| I agree. I haven't looked to much into the Frameworks based on dataobjects yet but, this could fit nicely into somthing like that. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|