noalyss Version-9
Public Member Functions | Static Public Member Functions | Private Attributes
Inplace_Edit Class Reference

Inplace_edit class for ajax update of HtmlInput object. More...

+ Collaboration diagram for Inplace_Edit:

Public Member Functions

 __construct (HtmlInput $p_input)
 Create a Inplace_Edit, initialise JSON and fullfill the default json value: input which is the HtmlInput object serialized. More...
 
 add_json_param ($p_attribute, $p_value)
 Add json parameter to the current one, if there attribute already exists it will be overwritten. More...
 
 ajax_input ()
 response in ajax to be edited More...
 
 display ()
 
 get_input ()
 return the HtmlObject , var input More...
 
 input ()
 
 set_callback ($callback)
 the php callback file to call for ajax More...
 
 set_input (HtmlInput $p_input)
 set the var input (HtmlObject) and update the json attribute input More...
 
 set_json ($json)
 
 set_message ($p_str)
 Message to display if the value is empty. More...
 
 set_value ($p_value)
 Set the value of the HtmlInput object $input. More...
 
 value ()
 display only the value , if the action after saving or cancelling More...
 

Static Public Member Functions

static build ($p_serialize)
 build a Inplace_Edit object from a serialized string (ajax json parameter = input) More...
 

Private Attributes

 $callback
 Php file which answered the ajax. More...
 
 $input
 HtmlInput object. More...
 
 $json
 Json object to pass to JavaScript. More...
 
 $message
 Message to display if value is empty. More...
 

Detailed Description

Inplace_edit class for ajax update of HtmlInput object.

You need an ajax to response and modify the data. Some parameters will be sent by default when you click on the element

Very important it is the DOM ID of the HtmlInput element, it must unique. For the date set a uniq dom id, otherwise it fails $id_limit_date->id=uniqid("date");

Examples
inplace_edit.test.php.

Definition at line 41 of file inplace_edit.class.php.

Constructor & Destructor Documentation

◆ __construct()

Inplace_Edit::__construct ( HtmlInput  $p_input)

Create a Inplace_Edit, initialise JSON and fullfill the default json value: input which is the HtmlInput object serialized.

Parameters
HtmlInput$p_input

Definition at line 58 of file inplace_edit.class.php.

58 {
59 $this->input=$p_input;
60 $x["input"]=base64_encode(serialize($p_input));
61 $this->json=json_encode($x, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP |JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
62 $this->message=_("Cliquez pour éditer");
63 }

References input().

+ Here is the call graph for this function:

Member Function Documentation

◆ add_json_param()

Inplace_Edit::add_json_param (   $p_attribute,
  $p_value 
)

Add json parameter to the current one, if there attribute already exists it will be overwritten.

Definition at line 198 of file inplace_edit.class.php.

198 {
199 $x=json_decode($this->json,TRUE);
200 $x[$p_attribute]=$p_value;
201 $this->json=json_encode($x, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP |JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
202 }

◆ ajax_input()

Inplace_Edit::ajax_input ( )

response in ajax to be edited

Definition at line 79 of file inplace_edit.class.php.

79 {
80 ob_start();
81 echo $this->input->input();
82 if ($this->input instanceof ITextarea) {
83 echo '<br>';
84 }
85 echo Icon_Action::validate("inplace_edit_ok".$this->input->id,"");
86 echo Icon_Action::cancel("inplace_edit_cancel".$this->input->id, "");
87 echo <<<EOF
88 <script>
89 $('{$this->input->id}edit').addClassName('inplace_edit_input');
90 {$this->input->id}edit.onclick=null;
91 inplace_edit_ok{$this->input->id}.onclick= function () {
92 var json={$this->json};
93 json['ieaction']='ok';
94 json['value']=$('{$this->input->id}').value;
95 new Ajax.Updater('{$this->input->id}edit'
96 ,'{$this->callback}',
97 {parameters: json ,evalScripts:true});}
98 inplace_edit_cancel{$this->input->id}.onclick= function () {
99 var json={$this->json};
100 json['ieaction']='cancel';
101 new Ajax.Updater('{$this->input->id}edit'
102 ,'{$this->callback}',
103 {parameters: json ,evalScripts:true});}
104
105 </script>
106EOF;
107 $ret= ob_get_contents();
108 ob_end_clean();
109 return $ret;
110 }
Manage the TEXTAREA html element.
static validate($p_id, $p_javascript)
Display the icon to modify a idem.
static cancel($p_id, $p_javascript)
Display the icon to modify a idem.

References $ret, Icon_Action\cancel(), input(), and Icon_Action\validate().

+ Here is the call graph for this function:

◆ build()

static Inplace_Edit::build (   $p_serialize)
static

build a Inplace_Edit object from a serialized string (ajax json parameter = input)

Examples
inplace_edit.test.php.

Definition at line 66 of file inplace_edit.class.php.

67 {
68 $input= unserialize(base64_decode($p_serialize));
70 return $obj;
71 }
Inplace_edit class for ajax update of HtmlInput object.
$input
HtmlInput object.

References $input, and $obj.

◆ display()

Inplace_Edit::display ( )

Definition at line 72 of file inplace_edit.class.php.

73 {
74 echo $this->input->value;
75 }

References input().

+ Here is the call graph for this function:

◆ get_input()

Inplace_Edit::get_input ( )

return the HtmlObject , var input

Definition at line 207 of file inplace_edit.class.php.

207 {
208 return $this->input;
209 }

References $input.

Referenced by set_value().

◆ input()

Inplace_Edit::input ( )

Definition at line 145 of file inplace_edit.class.php.

145 {
146 ob_start();
147 $v=$this->input->get_value();
148 $v=html_entity_decode($v??"");
149 if ( $this->input instanceof ITextarea) {
150 echo '<span class="" id="'.$this->input->id.'edit" >';
151 echo '<pre class="field_follow_up">';
152 $v=(trim($v)=="")?$this->message:$v;
153 echo $v;
154 echo '</pre>';
155 echo'<span class="smallbutton" style="margin-left:5px">Cliquer pour changer</span> ';
156 } else {
157 $v=(trim($v)=="")?$this->message:$v;
158 echo <<<EOF
159 <span class="inplace_edit" id="{$this->input->id}edit" >
160EOF;
161 echo $v;
162
163 echo'<span class="smallicon icon" style="margin-left:5px">&#xe80d;</span> ';
164 }
165 echo "</span>";
166 echo "
167
168 <script>
169 {$this->input->id}edit.onclick=function() {
170 new Ajax.Updater('{$this->input->id}edit'
171 ,'{$this->callback}',
172 {parameters: {$this->json} ,evalScripts:true});
173 }
174 </script>
175 ";
176 $ret= ob_get_contents();
177 ob_end_clean();
178 return $ret;
179 }
span($p_string, $p_extra='')
Definition: ac_common.php:43

References $ret, input(), and span().

Referenced by __construct(), ajax_input(), display(), input(), set_input(), set_value(), and value().

+ Here is the call graph for this function:

◆ set_callback()

Inplace_Edit::set_callback (   $callback)

the php callback file to call for ajax

Definition at line 183 of file inplace_edit.class.php.

183 {
184 $this->callback=$callback;
185 }
$callback
Php file which answered the ajax.

References $callback.

◆ set_input()

Inplace_Edit::set_input ( HtmlInput  $p_input)

set the var input (HtmlObject) and update the json attribute input

Parameters
HtmlInput$p_input

Definition at line 215 of file inplace_edit.class.php.

215 {
216 $this->input = $p_input;
217 $x=json_decode($this->json,TRUE);
218 $x["input"]=base64_encode(serialize($p_input));
219 $this->json=json_encode($x, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP |JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
220 }

References input().

Referenced by set_value().

+ Here is the call graph for this function:

◆ set_json()

Inplace_Edit::set_json (   $json)

Definition at line 191 of file inplace_edit.class.php.

191 {
192 $this->json=$json;
193 }
$json
Json object to pass to JavaScript.

References $json.

◆ set_message()

Inplace_Edit::set_message (   $p_str)

Message to display if the value is empty.

Parameters
string$p_str

Definition at line 234 of file inplace_edit.class.php.

234 {
235 $this->message=$p_str;
236 }

◆ set_value()

Inplace_Edit::set_value (   $p_value)

Set the value of the HtmlInput object $input.

Parameters
type$p_value

Definition at line 225 of file inplace_edit.class.php.

225 {
226 $input=$this->get_input();
227 $this->input->set_value($p_value);
228 $this->set_input($input);
229 }
get_input()
return the HtmlObject , var input
set_input(HtmlInput $p_input)
set the var input (HtmlObject) and update the json attribute input

References $input, get_input(), input(), and set_input().

+ Here is the call graph for this function:

◆ value()

Inplace_Edit::value ( )

display only the value , if the action after saving or cancelling

Definition at line 115 of file inplace_edit.class.php.

116 {
117 $v=$this->input->get_value();
118 $v=html_entity_decode($v??"");
119 if ( $this->input instanceof ITextarea) {
120
121 echo '<pre class="field_follow_up">';
122 $v=(trim($v)=="")?$this->message:$v;
123 echo $v;
124 echo '</pre>';
125 echo'<span class="smallbutton" style="margin-left:5px">Cliquer pour changer</span> ';
126 } else {
127 $v=(trim($v)=="")?$this->message:$v;
128 echo $v,
129 '<span class="smallicon icon" style="margin-left:5px">&#xe80d;</span> ';
130 }
131
132 echo "
133 <script>
134 $('{$this->input->id}edit').removeClassName('inplace_edit_input');
135 {$this->input->id}edit.onclick=function() {
136 new Ajax.Updater('{$this->input->id}edit'
137 ,'{$this->callback}',
138 {parameters: {$this->json} ,evalScripts:true});}
139 </script>
140 ";
141 }

References input().

+ Here is the call graph for this function:

Field Documentation

◆ $callback

Inplace_Edit::$callback
private

Php file which answered the ajax.

Definition at line 50 of file inplace_edit.class.php.

Referenced by set_callback().

◆ $input

Inplace_Edit::$input
private

HtmlInput object.

Definition at line 46 of file inplace_edit.class.php.

Referenced by build(), get_input(), and set_value().

◆ $json

Inplace_Edit::$json
private

Json object to pass to JavaScript.

Definition at line 48 of file inplace_edit.class.php.

Referenced by set_json().

◆ $message

Inplace_Edit::$message
private

Message to display if value is empty.

Definition at line 52 of file inplace_edit.class.php.


The documentation for this class was generated from the following file: