noalyss Version-9
inum.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22
23/*!\file
24 * \brief for the numeric input text field
25 */
26/*!\brief
27 * This class handles only the numeric input, the input will
28 * call a javascript
29 * to change comma to period and will round it (2 decimal), the precision is given by
30 * the attribute prec
31 * attribute
32 * extra = extra code (free)
33 * size = size of the field
34 * prec = precision default = 2
35 * name = name of the html object
36 * javascript = javascript to execute (default = onchange="format_number(this,2);)
37 * value = value of the widget
38 *
39 */
40
41class INum extends IText
42{
43 var $prec; //!< decimal
44 function __construct($name='', $value='', $id="")
45 {
46 parent::__construct($name, $value, $id);
47
48 $this->size=9;
49 $this->style='class="inum"';
50 $this->javascript='onchange="format_number(this,2);"';
51 }
52
53 /*!\brief print in html the readonly value of the widget */
54
55 public function display()
56 {
57
58 $readonly=" readonly ";
59 $this->id=($this->id=="")?$this->name:$this->id;
60
61 $style=' class="inum input_text_ro"';
62 $this->value=str_replace('"', '', $this->value??"0");
63 $r='<INPUT '.$style.' TYPE="TEXT" id="'.
64 $this->id.'"'.
65 'NAME="'.$this->name.'" VALUE="'.$this->value.'" '.
66 'SIZE="'.$this->size.'" '.$this->javascript." $readonly $this->extra >";
67
68 /* add tag for column if inside a table */
69 if ($this->table==1)
70 $r='<td>'.$r.'</td>';
71
72 return $r;
73 }
74
75 /*!\brief show the html input of the widget */
76
77 public function input($p_name=null, $p_value=null)
78 {
79 if (isset($this->prec))
80 {
81 $this->javascript='onchange="format_number(this,'.$this->prec.');"';
82 }
83 $this->name=($p_name==null)?$this->name:$p_name;
84 $this->value=($p_value===null)?$this->value:$p_value;
85 $this->id=($this->id=="")?$this->name:$this->id;
86
87 if ($this->readOnly==true)
88 return $this->display();
89
90 $t=((isset($this->title)))?'title="'.$this->title.'" ':' ';
91
92 $extra=(isset($this->extra))?$this->extra:"";
93
94 $this->value=noalyss_str_replace('"', '', $this->value);
95 $strAttribute=$this->get_node_attribute();
96 if (!isset($this->css_size) || empty ($this->css_size))
97 {
98 $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
99 $this->id.'"'.$t.
100 'NAME="'.$this->name.'" VALUE="'.$this->value.'" '.
101 'SIZE="'.$this->size.'" '.$this->javascript." $this->extra $strAttribute >";
102 /* add tag for column if inside a table */
103 }
104 else
105 {
106 $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
107 $this->id.'"'.$t.
108 'NAME="'.$this->name.'" VALUE="'.$this->value.'" '.
109 ' style="width:'.$this->css_size.';" '.$this->javascript." $this->extra $strAttribute >";
110 }
111
112 if ($this->table==1)
113 $r='<td>'.$r.'</td>';
114
115 return $r;
116 }
117 /**
118 * @brief like inplace_edit but without the ajax call, the INPUT text will be changed but not submitted
119 * @parameter $p_js_update optionnal script to execute if we update the fied
120 * @return string
121 */
122 function change($p_js_update="")
123 {
124 if ( $this->id=="") {
125 $this->id=uniqid();
126 }
127 $id_read=sprintf("x1_span_%s",$this->id);
128 $id_input=sprintf("x2_span_%s",$this->id);
129
130 $p_javascript_read=sprintf("$('%s').hide();$('%s').show();",
131 $id_read,$id_input);
132
133 $p_javascript_input=sprintf("$('%s').hide();$('%s').show();",
134 $id_input,$id_read);
135
136 $p_javascript_update=sprintf("$('update_%s').innerHTML=$('%s').value;$('%s').hide();$('%s').show();$p_js_update",
137 $this->id,
138 $this->id,
139 $id_input,$id_read);
140
141 $r=sprintf('<span id="%s">',$id_read);
142 $r.=sprintf('<span id="update_%s">',$this->id).$this->value.'</span>';
143 $r.=Icon_Action::modify(uniqid(), $p_javascript_read);
144 $r.='</span>';
145
146 $r.=sprintf('<span id="%s" style="display:none">',$id_input);
147 $r.=$this->input();
148 $r.=Icon_Action::validate(uniqid(), $p_javascript_update);
149 $r.=Icon_Action::cancel(uniqid(), $p_javascript_input);
150 $r.='</span>';
151 return $r;
152
153 }
154
155}
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$ret javascript
$opd_description style
$name size
$description css_size
$from_poste name
get_node_attribute()
Insert attribute inside a INPUT TYPE, these attribute can be retrieved in javascript with element....
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
input($p_name=null, $p_value=null)
show the html input of the widget
Definition: inum.class.php:77
display()
print in html the readonly value of the widget
Definition: inum.class.php:55
__construct($name='', $value='', $id="")
Definition: inum.class.php:44
change($p_js_update="")
like inplace_edit but without the ajax call, the INPUT text will be changed but not submitted @parame...
Definition: inum.class.php:122
$prec
decimal
Definition: inum.class.php:43
Html Input.
Definition: itext.class.php:30
static modify($p_id, $p_javascript)
Display the icon to modify a idem.
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.
$all table
$anc_filter title
$max_email_input prec
$icard readOnly
$poste extra