input=$p_input;
$x["input"]=serialize($p_input);
$this->json=json_encode($x, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
$this->message=_("Cliquez pour éditer");
}
///@brief build a Inplace_Edit object from
/// a serialized string (ajax json parameter = input)
static function build($p_serialize)
{
$input= unserialize($p_serialize);
$obj=new Inplace_Edit($input);
return $obj;
}
function display()
{
echo $this->input->value;
}
/**
* @brief response in ajax to be edited
*/
function ajax_input() {
ob_start();
echo $this->input->input();
echo ''._('ok').'';
echo ''._('cancel').'';
echo <<
$('{$this->input->id}edit').addClassName('inplace_edit_input');
{$this->input->id}edit.onclick=null;
inplace_edit_ok{$this->input->id}.onclick= function () {
var json={$this->json};
json['ieaction']='ok';
json['value']=$('{$this->input->id}').value;
new Ajax.Updater('{$this->input->id}edit'
,'{$this->callback}',
{parameters: json ,evalScripts:true});}
inplace_edit_cancel{$this->input->id}.onclick= function () {
var json={$this->json};
json['ieaction']='cancel';
new Ajax.Updater('{$this->input->id}edit'
,'{$this->callback}',
{parameters: json ,evalScripts:true});}
EOF;
$ret= ob_get_contents();
ob_end_clean();
return $ret;
}
/**
* @brief display only the value , if the action after saving or cancelling
*
*/
function value()
{
$v=$this->input->get_value();
$v=(trim($v)=="")?$this->message:$v;
echo $v,
' ',
"
";
}
/***
* @brief display the value with the click event
*/
function input() {
ob_start();
echo <<
EOF;
$v=$this->input->get_value();
$v=(trim($v)=="")?$this->message:$v;
echo $v;
echo' ';
echo "";
echo "
";
$ret= ob_get_contents();
ob_end_clean();
return $ret;
}
/**
* @brief the php callback file to call for ajax
*/
function set_callback($callback) {
$this->callback=$callback;
}
/***
* @brief the JSON parameter to give to the script,
* this function shouldn't be used since it override the default JSON value
* @see add_json_parameter
*/
function set_json($json) {
$this->json=$json;
}
/**
* Add json parameter to the current one, if there attribute already exists
* it will be overwritten
*/
function add_json_param($p_attribute,$p_value) {
$x=json_decode($this->json,TRUE);
$x[$p_attribute]=$p_value;
$this->json=json_encode($x, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
}
/**
* \brief return the HtmlObject , var input
*
*/
function get_input() {
return $this->input;
}
/**
* @brief set the var input (HtmlObject) and update the
* json attribute input
* @param HtmlInput $p_input
*/
function set_input(HtmlInput $p_input) {
$this->input = $p_input;
$x=json_decode($this->json,TRUE);
$x["input"]=serialize($p_input);
$this->json=json_encode($x, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
}
/**
* Set the value of the HtmlInput object $input
* @param type $p_value
*/
function set_value($p_value) {
$input=$this->get_input();
$this->input->set_value(strip_tags($p_value));
$this->set_input($input);
}
/**
* Message to display if the value is empty
* @param string $p_str
*/
function set_message($p_str) {
$this->message=$p_str;
}
}