Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 19 |
CRAP | |
0.00% |
0 / 54 |
| TButtonAjax | |
0.00% |
0 / 1 |
|
0.00% |
0 / 19 |
930 | |
0.00% |
0 / 54 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 10 |
|||
| show | |
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 11 |
|||
| setCallback | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getCallback | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| setReturnDataType | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getReturnDataType | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
|||
| setBeforeSend | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getBeforeSend | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| setAsync | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getAsync | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
|||
| setContainerId | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getContainerId | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setUrl | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getUrl | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setMessageLoading | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getMessageLoading | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getData | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setData | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| addData | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| 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 | class TButtonAjax extends TButton |
| 42 | { |
| 43 | private $callback; |
| 44 | private $returnDataType; |
| 45 | private $beforeSend; |
| 46 | private $async; |
| 47 | private $containerId; |
| 48 | private $url; |
| 49 | private $messageLoading; |
| 50 | private $data; |
| 51 | |
| 52 | public function __construct( $strName = null, $strValue = null, $strAction = null, $jsCallback = null, $strReturnDataType = null, $jsBeforeSend = null, $boolAsync = null, $strMessageLoading = null,$strUrl = null, $strContainerId = null, $strConfirmMessage = null, $strImageEnabled = null, $strImageDisabled = null, $strHint = null,$mixData=null ) |
| 53 | { |
| 54 | parent::__construct( $strName, $strValue, $strAction, null, $strConfirmMessage, $strImageEnabled, $strImageDisabled, $strHint, null ); |
| 55 | $this->setCallback( $jsCallback ); |
| 56 | $this->setReturnDataType( $strReturnDataType ); |
| 57 | $this->setBeforeSend( $jsBeforeSend ); |
| 58 | $this->setAsync( $boolAsync ); |
| 59 | $this->setContainerId( $strContainerId ); |
| 60 | $this->setUrl( $strUrl ); |
| 61 | $this->setMessageLoading( $strMessageLoading ); |
| 62 | $this->setData( $mixData ); |
| 63 | } |
| 64 | |
| 65 | public function show( $print = true ) |
| 66 | { |
| 67 | if ( $this->getAction() ) |
| 68 | { |
| 69 | $data=''; |
| 70 | if( $this->getData() ) |
| 71 | { |
| 72 | if( is_array( $this->getData() ) ) |
| 73 | { |
| 74 | $data = $this->getData(); |
| 75 | $data = $this->utf8_encode_array($data); |
| 76 | /* |
| 77 | foreach($data as $k=>$v) |
| 78 | { |
| 79 | // se não tiver valor, ler do campo do formulário |
| 80 | $data[ utf8_encode($k) ] = utf8_encode($v); |
| 81 | } |
| 82 | */ |
| 83 | $data = ',"data":'.json_encode($data); |
| 84 | } |
| 85 | } |
| 86 | $strOnClick = 'fwAjaxRequest( {'.( $this->getCallback() ? '"callback":' . $this->getCallback().',' : '' ).( $this->getBeforeSend() ? '"beforeSend":' . $this->getBeforeSend().',' : '' ).'"action":"' . $this->getAction() . '","async":' . ($this->getAsync()===true?'true':'false') . ',"dataType":"' . $this->getReturnDataType() . '","msgLoad":"' . $this->getMessageLoading() . '","containerId":"' . $this->getContainerId() . '","module":"' . $this->getUrl() . '"'.$data.'});'; |
| 87 | $this->setOnClick( $strOnClick ); |
| 88 | $this->setAction(null); |
| 89 | } |
| 90 | return parent::show($print); |
| 91 | } |
| 92 | /** |
| 93 | * Define a função ou handle da função javascript que será chamada ao terminar |
| 94 | * a requisição ajax. |
| 95 | * |
| 96 | * @param string $jsCallback |
| 97 | */ |
| 98 | public function setCallback( $jsCallback = null ) |
| 99 | { |
| 100 | $this->callback = $jsCallback; |
| 101 | return $this; |
| 102 | } |
| 103 | /** |
| 104 | * Retorna a função ou handle da função javascript que será chamada ao terminar |
| 105 | * a requisição ajax. |
| 106 | * |
| 107 | */ |
| 108 | public function getCallback() |
| 109 | { |
| 110 | if( isset( $this->callback )) |
| 111 | { |
| 112 | $a = explode('(',$this->callback); |
| 113 | $this->callback=$a[0]; |
| 114 | } |
| 115 | return $this->callback; |
| 116 | } |
| 117 | /** |
| 118 | * Define o tipo de retorno da chamada ajax. Podendo ser text ou json. |
| 119 | * O padrão será text |
| 120 | * @param string $strReturnDataType |
| 121 | */ |
| 122 | public function setReturnDataType( $strReturnDataType = null ) |
| 123 | { |
| 124 | $this->returnDataType = $strReturnDataType; |
| 125 | return $this; |
| 126 | } |
| 127 | /** |
| 128 | * Retorna o tipo de dados retornado pela requisição ajax, sendo, text ou json |
| 129 | * text é o padrão. |
| 130 | * |
| 131 | */ |
| 132 | public function getReturnDataType() |
| 133 | { |
| 134 | return strtolower( $this->returnDataType ) === 'json' ? 'json' : 'text'; |
| 135 | } |
| 136 | /** |
| 137 | * Define o nome de uma função js ou handle de uma função javascript que |
| 138 | * será executa antes de fazer a requisição ajax. |
| 139 | * Se a função retornar false a chamada será cancelada. |
| 140 | * |
| 141 | * @param string $jsBeforeSend |
| 142 | */ |
| 143 | public function setBeforeSend( $jsBeforeSend = null ) |
| 144 | { |
| 145 | $this->beforeSend = $jsBeforeSend; |
| 146 | return $this; |
| 147 | } |
| 148 | /** |
| 149 | * Retorna o nome da função que será executada antes da requisição ajax |
| 150 | * Se a função retornar false a chamada será cancelada. |
| 151 | */ |
| 152 | public function getBeforeSend() |
| 153 | { |
| 154 | if( isset( $this->beforeSend )) |
| 155 | { |
| 156 | $a = explode('(',$this->beforeSend); |
| 157 | $this->beforeSend=$a[0]; |
| 158 | } |
| 159 | return $this->beforeSend; |
| 160 | } |
| 161 | /** |
| 162 | * Define se a chamada será assincrona ou sincrona |
| 163 | * |
| 164 | * @param boolean $boolAsync |
| 165 | */ |
| 166 | public function setAsync( $boolAsync = null ) |
| 167 | { |
| 168 | $this->async = $boolAsync; |
| 169 | return $this; |
| 170 | } |
| 171 | /** |
| 172 | * Retorna true ou false, se a chamada será assincrona |
| 173 | * |
| 174 | * @param boolean $boolAsyn |
| 175 | */ |
| 176 | public function getAsync() |
| 177 | { |
| 178 | return ( $this->async === false ) ? false : true; |
| 179 | } |
| 180 | /** |
| 181 | * Define o id do elemento html onde será inserido o resultado da consulta ajax |
| 182 | * |
| 183 | * @param string $strContainerId |
| 184 | */ |
| 185 | public function setContainerId( $strContainerId = null ) |
| 186 | { |
| 187 | $this->containerId = $strContainerId; |
| 188 | return $this; |
| 189 | } |
| 190 | /** |
| 191 | * Retorna o id do elemento html onde será inserido o resultado da consulta ajax |
| 192 | * |
| 193 | */ |
| 194 | public function getContainerId() |
| 195 | { |
| 196 | return $this->containerId; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Define a url destino da requisição. |
| 201 | * O padrão será o valor do campo oculto modulo do formulário. |
| 202 | * |
| 203 | * @param string $strUrl |
| 204 | */ |
| 205 | public function setUrl( $strUrl = null ) |
| 206 | { |
| 207 | $this->url = $strUrl; |
| 208 | return $this; |
| 209 | } |
| 210 | /** |
| 211 | * Retorna a url destino da requisição. |
| 212 | * O padrão será o valor do campo oculto modulo do formulário. |
| 213 | * |
| 214 | */ |
| 215 | |
| 216 | public function getUrl() |
| 217 | { |
| 218 | return $this->url; |
| 219 | } |
| 220 | /** |
| 221 | * Define a mensagem que será exibida durante a requisição sincrona. |
| 222 | * |
| 223 | * @param mixed $strMessage |
| 224 | */ |
| 225 | public function setMessageLoading( $strMessage = null ) |
| 226 | { |
| 227 | $this->messageLoading = $strMessage; |
| 228 | return $this; |
| 229 | } |
| 230 | /** |
| 231 | * Retorna a mensagem que será exibida durante a requisição sincrona. |
| 232 | * |
| 233 | * @param mixed $strMessage |
| 234 | */ |
| 235 | public function getMessageLoading() |
| 236 | { |
| 237 | return $this->messageLoading; |
| 238 | } |
| 239 | |
| 240 | public function getData() |
| 241 | { |
| 242 | return $this->data; |
| 243 | } |
| 244 | |
| 245 | public function setData($arrData=null) |
| 246 | { |
| 247 | $this->data = $arrData; |
| 248 | return $this; |
| 249 | } |
| 250 | |
| 251 | public function addData($strName=null,$mixValue=null ) |
| 252 | { |
| 253 | if( !is_null( $strName ) ) |
| 254 | { |
| 255 | $this->data[$strName] = $mixValue; |
| 256 | } |
| 257 | return $this; |
| 258 | } |
| 259 | } |
| 260 | ?> |