Cat Prototype Edit Inline
Class Cat Prototype Edit Inline
Simple class for “edit in line” with prototype javascript library.
Click HERE for see the code of this class
Here is an example to use this class:
< ?php
// Include the library
include(cat-prototype.inc.php');
$eip = new Cat_Edit_Inline('js/', $_SERVER['PHP_SELF'].'?ajax=on');
// Check if there is an ajax request return false if there isn't data return false
$request = $eip->getAjaxDatas();
if ($request && isset($_GET['ajax'])) {
// set php header
$this->setHeaderPhp(false, true);
// empty id
if (!isset($request['id']) || !isset($request['option_id'])) {
print("Incorrected datas - No id sent !");
}
// continue
else {
// Update the database
/* update_function(); */
// Print text
print ($request['content']);
}
}
// No ajax data sent
else {
// Set default size of textarea
$this->setInitEditOptions('size', 80);
// Setto default cols of textarea
$this->setInitEditOptions('cols', 60);
// Set saving_text
$this->setInitEditOptions('saving_text', 'Saving...');
// Set text field
$this->setElement(array('id'=>'field_name','ajax_data'=>array('option_id'=>1)));
// Set body text
$bodyOptions = array('html_start'=>"<em>description of the field</em>");
// Set body element
$this->setElementBody('option_name', 'option_value', $bodyOptions);
// Set textarea field
$this->setElement(array('id'=>'field_name', 'type'=>'textarea', 'ajax_data'=>array('option_id'=>2)));
// Set body textarea
$bodyOptions = array('html_start'=>"<em>description of the field</em>");
// Set body element
$this->setElementBody('option_name', 'option_value', $bodyOptions);
// Select / Option yes / no
$optionsSelect = array('yes'=>'yes', 'no'=>'no');
$this->setElement(array('id'=>'field_name', 'type'=>'select', 'options'=>$optionsSelect, 'ajax_data'=>array('option_id'=>2)));
// Set body select
$bodyOptions = array('html_start'=>"<em>description of the field</em>");
// Set body element
$this->setElementBody('option_name', 'option_value', $bodyOptions);
// Inizialize class
$eip->initEditInline();
// Get header havascript e css
$header = $eip->getJavascript().$eip->getCss();
echo
"< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Eip demo".
$header."
</head>
<body>
<h1>Eip Demo</h1>
<div>
".$eip->getBody()."
</div>
</body>
</html>";
}
?>

Size: 18.96 KB
Hits : 12
Hits : 12
