noalyss Version-9
select_box.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 * @file
22 * @brief display a kind of select
23 */
24
25/**
26 * Display a kind of select
27 * @include select-box-test.php
28 */
29// Copyright Author Dany De Bontridder danydb@aevalys.eu
31{
32
33 var $id;
34 var $item;
35 private $cnt;
36 private $filter; //!< allow a dynamic not case sensitive search
38 private $position; //!< change depending if we are in an absolute block or not
39 protected $style_box;
40 protected $value;
41
42 /**
43 * Default constructor
44 * @param type $p_id javascript DOMid
45 * @param type $value Label to display
46 * @example select-box-test.php
47 */
49 {
50 $this->id=$p_id;
51 $this->item=array();
52 $this->value=$value;
53 $this->cnt=0;
54 $this->default_value=-1;
55 $this->style_box="";
56 $this->filter="";
57 $this->position="normal";
58 }
59
60 public function get_id()
61 {
62 return $this->id;
63 }
64
65 public function set_id($id)
66 {
67 $this->id=$id;
68 return $this;
69 }
70
71 public function get_item()
72 {
73 return $this->item;
74 }
75
76 public function get_default_value()
77 {
79 }
80
81 public function set_item($item)
82 {
83 $this->item=$item;
84 return $this;
85 }
86
88 {
89 $this->default_value=$default_value;
90 return $this;
91 }
92
93 public function get_position()
94 {
95 return $this->position;
96 }
97
98 public function set_position($position)
99 {
100 if (!in_array($position, array("normal", "in-absolute", "absolute")))
101 {
102 throw new Exception("SB0005", EXC_PARAM_VALUE);
103 }
104 $this->position=$position;
105 return $this;
106 }
107
108 protected function compute_position()
109 {
110 $list_id=sprintf('%s_list', $this->id);
111 switch ($this->position)
112 {
113 case 'absolute':
114 case "normal":
115 case "in-absolute":
116 // Show when click
117 $javascript=sprintf('
118 $("%s_bt").onclick=function() {
119 displaySelectBox("%s");
120 }
121 ', $this->id, $this->id);
122
123 break;
124
125 default:
126 break;
127 }
128 return $javascript;
129 }
130
131 function input()
132 {
133 $list_id=sprintf('%s_list', $this->id);
134
135 // Show when click
136 $javascript=$this->compute_position();
137
138 // display the button
139 printf('<input type="button" class="smallbutton " id="%s_bt" value="%s &#8681;" >',
140 $this->id, $this->value);
141 printf('<input type="hidden" id="%s" name="%s" value="%s">',
142 $this->id, $this->id, $this->default_value);
143 printf('<div class="select_box " id="select_box%s" style="%s">',
144 $this->id, $this->style_box);
145
146 // Show the filter if there is one,
147 if ($this->filter!="")
148 {
149
150 echo HtmlInput::filter_list($list_id);
151 }
152
153 // Print the list of possible options
154 printf('<ul id="%s">', $list_id);
155 for ($i=0; $i<count($this->item); $i++)
156 {
157 if ($this->item[$i]['type']=="url")
158 {
159 printf('<li><a href="%s">%s</a></li>', $this->item[$i]['url'], $this->item[$i]['label']);
160 }
161 else // For javascript
162 if ($this->item[$i]['type']=="javascript")
163 {
164 printf('<li><a href="javascript:void(0)" onclick="%s">%s</a></li>', $this->item[$i]['javascript'],
165 $this->item[$i]['label']);
166 }
167 else if ($this->item[$i]['type']=="value")
168 {
169 printf('<li><a href="javascript:void(0)" onclick="%s">%s</a></li>', $this->item[$i]['javascript'],
170 $this->item[$i]['label']);
171 }
172 else if ($this->item[$i]['type']=="input")
173 {
174 $ok=new IButton("ok");
175 $ok->value=$this->item[$i]['label'];
176 $ok->javascript=$this->item[$i]['input']->javascript;
177 printf('<li> %s %s</li>', $this->item[$i]['input']->input(), $ok->input()
178 );
179 }
180 }
181
182 echo "</ul>";
183 echo "</div>";
184
185 // javascript : onclick on button
186 echo "<script>";
187 echo $javascript;
188 echo "</script>";
189 }
190
191 function add_url($label, $url)
192 {
193 $this->item[$this->cnt]['label']=$label;
194 $this->item[$this->cnt]['url']=$url;
195 $this->item[$this->cnt]['type']="url";
196 $this->cnt++;
197 }
198
199 function add_javascript($label, $javascript,$replace=false)
200 {
201 $this->item[$this->cnt]['label']=$label;
202 if ( $replace )
203 {
204 $this->item[$this->cnt]['javascript']=
205 sprintf("$('%s_bt').value='%s \u21E9';",$this->id,noalyss_str_replace("'","",$label)).
206 $javascript.";$('select_box{$this->id}').hide()";
207 } else {
208 $this->item[$this->cnt]['javascript']=$javascript.";$('select_box{$this->id}').hide()";
209 }
210 $this->item[$this->cnt]['type']="javascript";
211 $this->cnt++;
212 }
213
215 {
216 $this->item[$this->cnt]['label']=$label;
217 $this->item[$this->cnt]['update']=$value;
218 $this->item[$this->cnt]['javascript']=sprintf(" $('%s').value='%s';$('%s_bt').value='%s \u21E9';$('select_box%s').hide()",
219 $this->id, $value, $this->id, $label, $this->id);
220 $this->item[$this->cnt]['type']='value';
221 $this->cnt++;
222 }
223
224 function add_input($p_label, HtmlInput $p_element)
225 {
226 /* $this->item[$this->cnt]['label']=$p_element->label;
227 $this->item[$this->cnt]['value']=$p_element->value;
228 $this->item[$this->cnt]['javascript']=$p_element->javascript;
229 *
230 */
231 $this->item[$this->cnt]['label']=$p_label;
232 $this->item[$this->cnt]['input']=clone $p_element;
233 $this->item[$this->cnt]['type']='input';
234 $this->cnt++;
235 }
236
238 {
239 $this->filter=$p_filter;
240 }
241
242 function get_filter()
243 {
244 return $this->filter;
245 }
246
247}
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
$url
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
static filter_list($p_list_id)
Display a field for searching an element in a list, the searchable text must be in an element with th...
Html Input.
Display a kind of select.
add_javascript($label, $javascript, $replace=false)
$filter
allow a dynamic not case sensitive search
add_input($p_label, HtmlInput $p_element)
set_position($position)
set_filter($p_filter)
set_default_value($default_value)
$position
change depending if we are in an absolute block or not
__construct($p_id, $value)
add_url($label, $url)
add_value($label, $value)
const EXC_PARAM_VALUE
Definition: constant.php:343