Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 93
TPanel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
600
0.00% covered (danger)
0.00%
0 / 93
 __construct
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 26
 show
0.00% covered (danger)
0.00%
0 / 1
156
0.00% covered (danger)
0.00%
0 / 48
 addControl
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setFlat
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 10
 getFlat
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setLegend
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 6
1<?php
2/*
3 * Formdin Framework
4 * Copyright (C) 2012 Ministério do Planejamento
5 * Criado por Luís Eugênio Barbosa
6 * Essa versão é um Fork https://github.com/bjverde/formDin
7 *
8 * ----------------------------------------------------------------------------
9 * This file is part of Formdin Framework.
10 *
11 * Formdin Framework is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License version 3
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License version 3
21 * along with this program; if not,  see <http://www.gnu.org/licenses/>
22 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
23 * Fifth Floor, Boston, MA  02110-1301, USA.
24 * ----------------------------------------------------------------------------
25 * Este arquivo é parte do Framework Formdin.
26 *
27 * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou
28 * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
29 * do Software Livre (FSF).
30 *
31 * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
32 * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
33 * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
34 * para maiores detalhes.
35 *
36 * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
37 * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
38 * ou escreva para a Fundação do Software Livre (FSF) Inc.,
39 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
40 */
41
42/**
43*  Objeto tipo container que permite ter outros objetos como filhos
44*  Se a propriedade flat for true, exibe com bordas
45*/
46class TPanel extends TControl
47{
48    private $controls;
49    private $flat;
50    public $legend;
51    public function __construct($strName,$strWidth=null,$strHeight=null)
52    {
53        $strWidth     = $strWidth    ==null ? "auto" : $strWidth;
54        $strHeight    = $strHeight==null ? "auto" : $strHeight;
55        $this->setFlat(true);
56        parent::__construct('div',$strName);
57        parent::setFieldType('panel');
58        parent::setWidth($strWidth);
59        parent::setHeight($strHeight);
60        // tirar a borda do painel depois
61        parent::setCss('border'    ,'none');
62        //parent::setCss('border'    ,'1px dashed red');
63        parent::setCss('display','block');
64        // definir as propriedade como nula inicializa-la no array, se por acaso precisar definir a margin-top, por exemplo , ficar abaixo de margin;
65        $this->setcss('margin','');
66        $this->setcss('padding','');
67
68        // legenda do box
69        $this->legend = new TElement('div');
70        $this->legend->setCss('top','-10px');
71        $this->legend->setCss('left','10px');
72        $this->legend->setCss('position','absolute');
73        $this->legend->setCss('background-color','silver');
74        $this->legend->setCss('border','1px solid gray');
75        $this->legend->setCss('padding-left','2px');
76        $this->legend->setCss('padding-right','2px');
77        $this->legend->setCss('font-size','12px');
78        $this->legend->setCss('font-weight','normal');
79        $this->legend->setCss('font-family','arial,sans-serif');
80        $this->legend->setCss('border','1px outset #C0C0C0');
81        $this->legend->setCss('background-color','#E1E1E1');
82        $this->legend->setCss('color','#24618E');
83    }
84    //--------------------------------------------------------------------
85    public function show($print=true)
86    {
87        $box=null;
88        if(!$this->getFlat())
89        {
90            $this->setcss('margin','0');
91            $this->setcss('padding','0');
92            if((int)$this->getWidth()==0)
93            {
94            $this->setWidth(200);
95            }
96            if((int)$this->getHeight()==0)
97            {
98                $this->setHeight(200);
99            }
100            $this->setWidth($this->getWidth()+17);
101            $this->setHeight($this->getHeight()+23);
102            $box = new TBox('box_'.$this->getName(),$this->getWidth()-1,$this->getHeight()-8);
103            $box->setCssBody('background-color',$this->getCss('background-color'));
104            // se tiver legenda inserir um espaço no topo
105            if((string) $this->legend->id != '' )
106            {
107                // ajustar o id da legenda como o id do elemento
108                $this->legend->id= $this->getId().'_legend';
109                $box->setCssBody('margin-top',15);
110                // para nao colar no campo de cima
111                $this->setCss('margin-top','10');
112            }
113            $box->add($this->getChildren());
114            $this->clearChildren();
115
116        }
117        else
118        {
119            // construir o painel
120            if((string)$this->getCss('overflow')=='')
121            {
122                parent::setCss('overflow'    ,'auto');
123            }
124            parent::setCss('margin'        ,'0');
125            parent::setCss('padding'    ,'2');
126        }
127        if(is_array($this->controls) )
128        {
129            foreach ($this->controls as $k => $control)
130            {
131                if($box)
132                {
133                    $box->add($control);
134                }
135                else
136                {
137                    $this->add($control);
138                }
139            }
140        }
141        if($box)
142        {
143            $this->legend->setCss('top','-7px');
144            $this->legend->setCss('left','15px');
145            $this->add($box);
146            // se for groupbox, colocar o label se o label tiver o id definido
147               if($this->legend->id !='')
148               {
149                parent::add($this->legend);
150            }
151        }
152        else
153        {
154            // se tiver legenda, reconfirar o objeto para fieldset e adicionar a tag legend
155            if((string) $this->legend->id != '' )
156            {
157                $this->setTagType('fieldset');
158                // ajustar o id da legenda como o id do elemento
159                $this->legend->id= $this->getId().'_legend';
160                $this->legend->setTagType('legend');
161                $this->legend->setCss('top','');
162                $this->legend->setCss('left','');
163                $this->legend->setCss('position','');
164                $this->legend->setCss('padding-left','2px');
165                $this->legend->setCss('padding-right','2px');
166                $children = $this->getChildren();
167                $this->clearChildren();
168                // o heigh tem que ser alterado para auto devido ao firefox nao aceitar overflow:auto na tag fieldset
169                $this->setcss('height','auto');
170                $this->add($this->legend);
171                $this->add($children);
172            }
173
174        }
175        return parent::show($print);
176    }
177    //--------------------------------------------------------------------
178    public function addControl(TElement $control)
179    {
180        $this->controls[$control->getName()] = $control;
181    }
182    //---------------------------------------------------------------------------------------
183//    public function setFlat($boolFlat=null)
184//    {
185//        $boolFlat = $boolFlat===null ? true :(bool)$boolFlat;
186//        $this->flat = (bool)$boolFlat;
187//    }
188
189    //---------------------------------------------------------------
190    /**
191     * Define a borda 3D ou borda simples do formulário
192     * Se for retirada a borda 3D, assume o fundo padrão cinza claro
193     *
194     * @param boolean $boolValue
195     */
196    public function setFlat($boolFlat=null)
197    {
198        $boolFlat = $boolFlat===null ? true :(bool)$boolFlat;
199        $this->flat = (bool) $boolFlat;
200        if($this->flat)
201        {
202            if((string)$this->getCss('border') == "")
203            {
204                $this->setCss('border','1px solid #808080');
205            }
206            if((string)$this->getCss('background-color')=="")
207            {
208                $this->setCss('background-color','#efefef');
209            }
210        }
211        else
212        {
213            $this->setCss('border','none');
214            $this->setCss('background-color','transparent');
215        }
216    }
217    //---------------------------------------------------------------------------------------
218    public function getFlat()
219    {
220        return $this->flat;
221    }
222    //---------------------------------------------------------------------------------------
223    public function setLegend($strTitle=null)
224    {
225        $this->legend->clearChildren();
226        $this->legend->id='';
227        if((string)$strTitle!="")
228        {
229            $this->legend->add($strTitle);
230            $this->legend->id= $this->getId().'_legend';
231        }
232    }
233}
234
235//$panel = new TPanel('pnl_teste',500,300);
236//$panel->show();
237//return;
238/*
239//$panel->add('Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>Linha <br>');
240$panel->setFlat(true);
241$panel->legend->id='xxx';
242$panel->legend->add('Cadastro de Cliente');
243$panel->add('Linha 1');
244$panel->add('Linha 2<br>');
245$panel->add('Linha 3<br>');
246$panel->add('Linha 4<br>');
247$panel->show();
248*/
249?>