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 / 15
CRAP
0.00% covered (danger)
0.00%
0 / 50
TGridEditColumn
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 15
506
0.00% covered (danger)
0.00%
0 / 50
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 15
 setSize
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getSize
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setMaxLength
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getMaxLength
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setEditName
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getEditName
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setMask
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getMask
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getEdit
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 10
 setValue
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 5
 setKeyValue
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getKeyValue
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 setCssEdit
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 setEventEdit
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
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 */
41class TGridEditColumn extends TGridColumn
42{
43    private $size;
44    private $maxLength;
45    private $mask;
46    private $editName;
47    private $keyValue;
48    private $edit;
49
50    /**
51    * Implementa coluna para entrada de dados textual no gride
52    *
53    * @param string $strEditName
54    * @param string $strTitle
55    * @param string $strFieldName
56    * @param string $strDataType
57    * @param integer $intSize
58    * @param integer $intMaxLength
59    * @param string $strMask
60    * @param string $strWidth
61    * @param string $strAlign
62    * @param boolean $boolReadOnly
63    * @return TGridEditColumn
64    */
65    public function __construct($strEditName
66                                ,$strTitle=null
67                                ,$strFieldName=null
68                                ,$strDataType=null
69                                ,$intSize=null
70                                ,$intMaxLength=null
71                                ,$strMask=null
72                                ,$strWidth=null
73                                ,$strAlign=null
74                                ,$boolReadOnly=null
75                                ){
76        
77        parent::__construct($strFieldName,$strTitle,$strWidth);
78        $this->setId('col_'.strtolower($strEditName));
79        $this->setColumnType('edit');
80        $this->setSize($intSize);
81        $this->setMaxLength($intMaxLength);
82        $this->setEditName($strEditName);
83        $this->setDataType($strDataType);
84        $this->setMask($strMask);
85        $this->setClass('fwField');
86        $this->setCss('margin','2px');
87        $this->setSortable(false);
88        $this->edit = new TElement(); // só para guardar o css e eventos quer serão atribuidos so objeto edit quando este for criado.
89        /*
90        $this->setCss('font-size','12px');
91        $this->setCss('font-family','Arial,Times New Roman');
92        */
93        $this->setCss('text-align',$strAlign);
94
95        $this->setReadOnly($boolReadOnly);
96    }
97    public function setSize($intNewValue = null)
98    {
99        $this->size = (int) $intNewValue;
100    }
101    public function getSize()
102    {
103        return $this->size;
104    }
105    public function setMaxLength($intNewValue = null)
106    {
107        $intNewValue = is_null($intNewValue) ? $this->getSize() : (int) $intNewValue;
108        $this->maxLength = $intNewValue;
109    }
110    public function getMaxLength()
111    {
112        return $this->maxLength;
113    }
114    public function setEditName($strNewValue = null)
115    {
116        $this->editName = $strNewValue;
117    }
118    public function getEditName()
119    {
120        return $this->editName;
121    }
122    public function setMask($strNewValue = null)
123    {
124        $this->mask = $strNewValue;
125    }
126    public function getMask()
127    {
128        return $this->mask;
129    }
130    public function getEdit()
131    {
132        if(!$this->getMask())
133        {
134               $edit = new TEdit(strtolower($this->getEditName()).'['.$this->getKeyValue().']',$this->getValue(),$this->getMaxLength(), $this->getSize());
135               $edit->setId(strtolower($this->getEditName().'_'.$this->getRowNum()));
136            $edit->setMaxLenght($this->getMaxLength());
137               $edit->setSize($this->getSize());
138        }
139        else
140        {
141               //$edit = new TMask(strtolower($this->getEditName().'_'.$this->getRowNum()),$this->getValue(),$this->getMask());
142               //$edit = new TMask(strtolower($this->getEditName()).'['.$this->getRowNum().']',$this->getValue(),$this->getMask());
143               $edit = new TMask(strtolower($this->getEditName()).'['.$this->getKeyValue().']',$this->getValue(),$this->getMask());
144               $edit->setId(strtolower($this->getEditName().'_'.$this->getRowNum()));
145        }
146        // adicionar o nome do campo como attibuto do input
147        $edit->setAttribute('fieldname',$this->getFieldName() );
148
149        //$edit->setCss($this->getCss());
150        /*if( is_null( $edit->getCss('border') ) )
151        {
152            $edit->setCss('border','1px solid silver');
153        }
154        $edit->setEvents($this->getEvents());
155        $this->clearEvents();
156        */
157        // adicionar os eventos da coluna ao campo
158        $edit->setEvents($this->getEvents());
159        return $edit;
160    }
161    public function setValue($strNewValue=null)
162    {
163
164        // o valor postado tem preferencia sobre o valor do $res
165        //if( $_POST &&  $this->getRowNum() > 0 && isset($_POST[$this->getEditName()]) && isset($_POST[$this->getEditName()][$this->getRowNum()]))
166        if( FormDinHelper::pregMatch('/text|memo|number/', $this->getDataType()) == 1 )
167        {
168            if( $_POST &&  $this->getRowNum() > 0 && isset($_POST[$this->getEditName()][$this->getKeyValue()]))
169            {
170                $strNewValue = $_POST[$this->getEditName()][$this->getKeyValue()];
171            }
172        }
173        parent::setValue($strNewValue);
174    }
175    //-------------------------------------------------------------------------------------------
176    public function setKeyValue($strNewValue=null)
177    {
178        $this->keyValue = $strNewValue;
179    }
180    //--------------------------------------------------------------------------------------------
181    public function getKeyValue()
182    {
183        return is_null($this->keyValue)?$this->getRowNum():$this->keyValue;
184    }
185    //---------------------------------------------------------------------------------------
186    public function setCssEdit($mixProperty,$newValue=null)
187    {
188        $this->edit->setcss($mixProperty,$newValue);
189    }
190    /**
191    * Define o evento e a funcao javascript do campo edit;
192    * Se for restritivo e a função executada retornar false, interrompe a execução dos próximos eventos se houver
193    *
194    * @param string $eventName
195    * @param string $functionJs
196    * @param boolean $boolRestrictive
197    */
198    public function setEventEdit($eventName,$functionJs=null,$boolRestrictive=null)
199    {
200        $this->edit->setEvent($eventName,$functionJs,$boolRestrictive);
201    }
202}
203?>