MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
listcontrols.class
Ir para a documentação deste ficheiro.
1<?php
3{
7 var $size;
8 var $cols;
9
10 function __construct($name='',$label='',$options='',$showValues=false,$hint='')
11 {
12 parent::__construct($name,'',$label);
13 $this->options = $options;
14 $this->showValues = $showValues;
15 $this->hint = $hint;
16 $this->formMode = 1;
17 }
18
19 function GenerateOptions()
20 {
21 $content = '';
22 foreach( array_keys($this->options) as $k )
23 {
24 $o = $this->options[$k];
25 if ( $o instanceof MOptionGroup )
26 {
27 foreach( $o->options as $oo )
28 {
29 $oo->SetControl($this);
30 }
31 $content .= $o->Generate();
32 }
33 else
34 {
35 if ( $o instanceof MOption )
36 {
37 $oo = $o;
38 }
39 elseif ( is_array($o) )
40 {
41 list ($value,$label) = $o;
42 $oo = new MOption('',$value,$label);
43 }
44 else
45 {
46 $oo = new MOption('',$k,$o);
47 }
48 $oo->checked = ($oo->value == $this->value);
49 $oo->SetControl($this);
50 $content .= $oo->Generate();
51 }
52 }
53 return $content;
54 }
55
56 function getOptions()
57 {
58 return $this->options;
59 }
60}
61
63{
65
69 public $event;
70 public $validator;
71
75 private $allowNullValue = true;
76
77 public function __construct($name='', $value='', $label='', $options=array( 'Não', 'Sim' ), $showValues=false, $hint='', $size='')
78 {
79 parent::__construct($name, $label, $options, $showValues, $hint, $size);
80
82
83 $_options = $options[0] ?? '';
84 if ( is_array($_options) )
85 {
86 $options = array_merge(array( '' => _M('--Select--') ), $options);
87 }
88 elseif ( is_array($options) )
89 {
90 $options = array( '' => _M('--Select--') ) + $options;
91 }
92 else
93 {
94 $options = array( '' => _M('--Select--') );
95 }
96
97 $this->options = $options;
98 $this->setValue($value);
99 $this->size = $size;
100 $this->autoPostBack = false;
101 $this->event = '';
102 }
103
104 public function GetOption($value)
105 {
106 foreach ( array_keys($this->options) as $k )
107 {
108 $o = $this->options[$k];
109 if ( is_array($o) )
110 {
111 list($id, $name) = $o;
112 if ( trim($value) == trim($id) )
113 {
114 if ( $this->showValues )
115 {
116 $r = $id . ' - ' . $name;
117 }
118 else
119 {
120 $r = $name;
121 }
122 }
123 }
124 else if ( trim($value) == trim($k) )
125 {
126 if ( $this->showValues )
127 {
128 $r = $k . ' - ' . $o;
129 }
130 else
131 {
132 $r = $o;
133 }
134 }
135 }
136
137 return $r;
138 }
139
140 public function SetOption($option, $value)
141 {
142 $this->options[$option] = $value;
143 }
144
145 public function SetCols($value)
146 {
147 $this->cols = $value;
148 }
149
150 public function SetAutoSubmit($isAuto = true)
151 {
152 $this->autoPostBack = $isAuto;
153 }
154
158 public function setAllowNullValue($allowNullValue = false)
159 {
160 $this->allowNullValue = $allowNullValue;
161 }
162
166 public function getAllowNullValue()
167 {
168 return $this->allowNullValue;
169 }
170
171 public function GenerateInner()
172 {
173 $selected = false;
174
175 if ( $this->event || $this->autoPostBack )
176 {
177 $this->AddAttribute('onChange', " _doPostBack('{$this->event}','');" . "document.{$this->page->name}.submit();");
178 }
179
180 if ( $this->GetClass() == '' )
181 {
182 $this->SetClass('m-combo form-control form-select');
183 }
184
185 if ( !$this->allowNullValue )
186 {
187 unset($this->options['']);
188 }
189
190 if ( $this->readonly )
191 {
192 $hidden = $this->GetRender('inputhidden');
193 $this->SetClass('m-readonly');
194 $this->AddAttribute('readonly');
195 $this->SetValue($this->GetOption($this->GetValue()));
196 $this->size = $this->cols ? $this->cols : strlen(trim($this->getValue())) + 10;
197
198 $this->name .= '_';
199 $this->inner = $this->GenerateLabel() . $this->GetRender('inputtext') . $hidden;
200 }
201 else
202 {
203 $this->content = $this->GenerateOptions();
204 if ( $this->size != '' )
205 {
206 $this->AddAttribute('size', $this->size);
207 }
208 $this->inner = $this->GenerateLabel() . $this->GetRender('select');
209 }
210 }
211
212 public function setIsRequired($isRequired)
213 {
214 $this->setAllowNullValue(false);
215
216 return parent::setIsRequired($isRequired);
217 }
218}
219
221{
222 var $size;
223
224 function __construct($name='', $values=Array('1','2','3'),
225 $label='&nbsp;', $options=Array('Option1','Option2','Option3'),
226 $showValues=false, $hint='', $size='3')
227 {
228 parent::__construct($name,$label,$options,$showValues,$hint);
229 $this->size = $size;
230 $this->value = $values; // is this still necessary?
231 }
232
233 function getName()
234 {
235 return (strpos($this->name, '[]') !== false ? $this->name : $this->name.'[]');
236 }
237
238 function GenerateInner()
239 {
240 /*
241 * FIXME: Why does it need to echo warning messages?
242 * I can't simply change them to errors or warnings. Probably the best would be to show them on the javascript
243 * console or something.
244 */
245 if ( $this->value && !is_array($this->value) )
246 {
247 echo $this->painter->div(new Div('', _M('Values must be a single-dimensional array'), 'alert'));
248 }
249
250 if ( !is_array($this->options) )
251 {
252 echo $this->painter->div(new Div('', _M('Options must be a single or multi-dimensional array'), 'alert'));
253 }
254
255 $this->content = $this->GenerateOptions();
256 $this->AddAttribute('multiple', '');
257 $this->AddAttribute('size', $this->size);
258
259 if ( $this->GetClass() == '' )
260 {
261 $this->SetClass('m-combo m-multi-select');
262 }
263
264 $this->inner = $this->GenerateLabel() . $this->GetRender('select');
265 }
266}
267
269{
270 var $size;
271
272 function __construct($name='',$value='',$label='',$options='',$showValues=false,$hint='',$size=6)
273 {
274 parent::__construct($name,$value,$label,$options,$hint);
275 $this->size = $size;
276 if (is_array($this->options)) {
277 reset($this->options);
278 $o = current($this->options);
279 }
280 }
281
282 function GenerateInner()
283 {
284
285 if ( $this->readonly )
286 {
287 $this->SetClass('m-readonly form-control form-select');
288 $this->AddAttribute('readonly');
289 $this->SetValue($this->GetOption($this->GetValue()));
290 $this->inner = $this->GenerateLabel() . $this->GetRender('inputtext');
291 return;
292 }
293
294 if ( $this->autoPostBack )
295 {
296 $this->AddAttribute( 'onchange', "showLoading();" .
297 "$('#m-loading-message-bg,#m-loading-message').unbind('click');" .
298 "$('#m-loading-message-bg,#m-loading-message').prop('onclick',null);".
299 "_doPostBack('{$this->event}','');".
300 "document.{$this->page->name}.submit();"
301 );
302 }
303
304 $text = new MTextField($this->name,$this->value,'',$this->size);
305 $text->SetAttributes($this->Attributes());
306 $text->AddAttribute('onChange',"ComboBox_onTextChange('{$this->label}', this.form.elements['{$this->name}'],this.form.elements['{$this->name}_sel']);" . ( $this->autoPostBack ? " _doPostBack('{$this->event}',''); document.{$this->page->name}.submit();" : '' ));
307 //$text->AddAttribute('onClick',"ComboBox_onTextChange('{$this->label}', this.form.elements['{$this->name}'],this.form.elements['{$this->name}_sel'])");
308
309 $select = new MSelection("{$this->name}_sel",$this->value,'',$this->options);
310 $select->SetAttributes($this->Attributes());
311 $select->SetClass('m-combo m-combobox form-control form-select');
312 $select->AddAttribute('onChange',"ComboBox_onSelectionChange('{$this->label}', this.form.elements['{$this->name}_sel'], this.form.elements['{$this->name}']);" . ( $this->autoPostBack ? " _doPostBack('{$this->event}',''); document.{$this->page->name}.submit();" : '' ));
313 $select->AddAttribute('onClick',"ComboBox_onSelectionChange('{$this->label}', this.form.elements['{$this->name}_sel'], this.form.elements['{$this->name}'])");
314 $select->addStyle('width', '70%');
315
316 //$span = new Span('',array($text->Generate(),' - ',$select->Generate()));
317 //$this->inner = $this->GenerateLabel() . $span->generate();
318 $container = new MHContainer("{$this->name}_hc", array($this->GenerateLabel(), $text, $select));
319 $container->addAttribute('style', 'min-width:500px');
320
321 $this->inner = $container->generate();
322
323 }
324}
325
326class MDropdownMenu extends MDiv
327{
328 private $itensMenu;
329
330 public function __construct( $name = NULL, $label = ' ', $itensMenu = array(), $image = NULL )
331 {
332 parent::__construct( $name );
333
334 $this->addStyleFile('m_boxes.css');
335 $this->setBoxId( $this->GetId() );
336 $this->setItensMenu($itensMenu);
337
338 $buttonInner = new MButton('btnDropwon' . $name, $label, 'NONE', $image);
339 $buttonInner->setClass('dropdown-toggle');
340 $buttonInner->addAttribute('data-toggle', 'dropdown');
341 $buttonInner->addAttribute('data-bs-toggle', 'dropdown');
342 $fieldsInner[] = $buttonInner;
343
344 $this->setInner($fieldsInner);
345 }
346
347 public function generate()
348 {
349 $inner = $this->getInnerToString();
350
351 $inner .= '<ul class="dropdown-menu">';
352
353 foreach ($this->itensMenu as $itemMenu)
354 {
355 $inner .= '<li>' . $itemMenu->generate() . '</li>';
356 }
357
358 $inner .= '</ul>';
359
360 $class = $this->getClass() . ' dropdown';
361 return '<div class="'.$class.'">' .$inner.'</div>';
362 }
363
364 public function getItensMenu()
365 {
366 return $this->itensMenu;
367 }
368
369 public function setItensMenu($itensMenu)
370 {
371 $this->itensMenu = $itensMenu;
372 }
373}
374
376{
377 private $limitSelect;
378
379 function __construct($name='', $values=Array('1','2','3'),
380 $label='&nbsp;', $options=Array('Option1','Option2','Option3'),
381 $showValues=false, $hint='', $size='3', $limitSelect = null)
382 {
383 parent::__construct($name, $values, $label, $options, $showValues, $hint, $size);
384
385 $this->limitSelect = $limitSelect;
386
387 $this->setClass($this->getClass() . ' m-tag-select');
388
389 $this->addAttribute('title', _M("Clique para ver as opções, você pode selecionar mais de uma", MIOLO::getCurrentModule()));
390 }
391
392 public function GenerateInner()
393 {
394 $options = array();
395 if (!is_null($this->limitSelect))
396 {
397 $options[] = "maximumSelectionLength: {$this->limitSelect}";
398 }
399
400 $optionsString = count($options) > 0 ? '{' . implode(', ', $options) . '}' : '';
401 $this->manager->getPage()->onload("
402 $( document ).ready(function() {\$('#" . $this->name . "').select2({$optionsString});});
403 ");
404
405 return parent::GenerateInner();
406 }
407
408 public function getLimitSelect()
409 {
410 return $this->limitSelect;
411 }
412
413 public function setLimitSelect($limitSelect)
414 {
415 $this->limitSelect = $limitSelect;
416 }
417
418}
419?>
__construct($name='', $value='', $label='', $options='', $showValues=false, $hint='', $size=6)
setBoxId( $id)
Definição mcontrol.class:791
setClass( $cssClass, $add=true)
Definição mcontrol.class:398
setInner($inner)
Definição mcontrol.class:598
addStyleFile( $styleFile)
Definição mcontrol.class:412
addAttribute( $name, $value='')
Definição mcontrol.class:443
getInnerToString()
Definição mcontrol.class:839
__construct( $name=NULL, $label=' ', $itensMenu=array(), $image=NULL)
setItensMenu($itensMenu)
setValue( $value)
static getCurrentModule()
Definição miolo.class:1066
static getInstance()
Definição miolo.class:134
__construct($name='', $label='', $options='', $showValues=false, $hint='')
__construct($name='', $values=Array('1', '2', '3'), $label='&nbsp;', $options=Array('Option1', 'Option2', 'Option3'), $showValues=false, $hint='', $size='3')
SetOption($option, $value)
setIsRequired($isRequired)
GetOption($value)
SetAutoSubmit($isAuto=true)
__construct($name='', $value='', $label='', $options=array( 'Não', 'Sim'), $showValues=false, $hint='', $size='')
setAllowNullValue($allowNullValue=false)
SetCols($value)
setLimitSelect($limitSelect)
__construct($name='', $values=Array('1', '2', '3'), $label='&nbsp;', $options=Array('Option1', 'Option2', 'Option3'), $showValues=false, $hint='', $size='3', $limitSelect=null)