You are on page 1of 44

Adianti Framework 3.

0
Na Pratica

Alexandre E. Souza
Esse livro est venda em http://leanpub.com/adiantiframeworknapratica

Essa verso foi publicada em 2016-05-19

This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and
many iterations to get reader feedback, pivot until you have the right book and build traction once
you do.

2014 - 2016 Alexandre E. Souza


Contedo

Quem Sou eu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Introduo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

O que Adianti Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Instalao . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Componentes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
TTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
TPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
TNoteBook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
TScroll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
TFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
TVBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
THBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
TWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Dialogs TMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
TQuestion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
InputDialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
TQuickForm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
TEntry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
TPassword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

TDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
TSpinner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
TSlider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
TText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
TImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
TCheckGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
CONTEDO

TRadioGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
THtmlEditor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
TLabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
TQuickGrid Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
TDataGrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Grid com Componentes de formulrio . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

Condies para Opes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39


Quem Sou eu
Meu Nome Alexandre Evangelista de Souza, sou desenvolvedor php e um amante de tecnologias
procuro sempre apreender novas tecnologias e aplicalas na linguagem que mais uso, o php.

1
Introduo
Apos o lanamento da nossa primeira verso do ebook adianti na pratica 2.0, tivemos um otimo
feedback dos leitores e amigos da comunidade, sendo assim nessa edio irei, preencher algumas
das lacunas que foram mostradas da verso anterior.
todos os exmplos usados estam em
<<Git Com o Codigo
** Hora do show **
https://github.com/ale-php/livro_adianti_3_0

2
O que Adianti Framework
O Adianti framework um framework desenvolvido pela Adianti Solutions com o foco de
desenvolver sistemas ele usa uma arquitetura paseada em componentes , tem uma estrutura bem
estruturada e segura , do qual permite aos usuarios criarem componetes como servios, mesmo
o seu foco sendo desenvolvimento de sistema perfeitamente possivel desenvolver sites com ele,
usando o framework para o painel admin e criando uma API Rest para ser consumida pelo angular,
esse assunto sera abordado em um dos nossos futuros ebooks.
O Adianti framework conta com uma comunidade ativa tanto no seu forum quando no facebook a
comunidade esta crescendo e o framework sempre sofre alteraes, para melhorias, e concerto de
bugs

3
Instalao
A instalao do Adianti framework bem simples de ser realizada, basta entrar no site Adianti
framework , aps isso basta clicar na opo baixar adianti framework, a segunda opo para o
desenvolvimento em desktop, que sera abordada em outra edio da serie de Programador para
Programador. Feito isso ira baixar o framework compactado, basta descompactar e colocar na pasta
raiz do seu apache.
http://www.adianti.com.br/framework-download

4
Componentes
Vamos conhecer alguns dos componentes do framework, nosso foco conhecer a verso 2.0 , assim
para aqueles que nunca usaram , no se preocupem iremos abordar todos os componentes com
exemplos, detalhados. Containers Os Containers so componentes onde podemos inserir outros
componentes , para alinha-los de melhor maneira, vamos ver um exemplo de cada um deles.

TTable
Nosso primeiro container sera a TTable, que a tabela do HTML esse container organiza os
objetos em tabelas, onde o mtodo addRowSet, permite adicionar vrios objetos em uma mesma
linha da tabela, no nosso exemplo temos 2 campos nome e sobrenome, no se preocupem com os
componentes TEntry, iremos velos futuramente. Essa tabela padro, mas podemos otimiza l , para
que possa atender nossa necessidade, essa estrutura usada a padro do framework todas as paginas
devem estender alguma class como TPage, TWindow, TStandardList etc.., veremos todas em nossos
exemplos.

TTableView

1 <?php
2
3 class TTableView extends TPage
4 {
5 function __construct(){
6 parent::__construct();
7 $table = new TTable(); //componente TTable
8
9 $nome = new TEntry('nome');
10 $sobrenome = new TEntry('sobrenome');
11 $table->addRowSet(new TLabel('nome'),$nome); // linha com 2 componentes
12 $table->addRowSet(new TLabel('sobrenome'),$sobrenome);
13 parent::add($table);
14 }
15 }
16 ?>

Vamos ver essa tabela otimizada, podemos mudar o espao entre as celulas, e as propriedades css

5
Componentes 6

ViewTPanel

1 <?php
2
3 class TTableView extends TPage
4 {
5 function __construct(){
6 parent::__construct();
7 $table = new TTable(); //componente TTable
8
9 $nome = new TEntry('nome');
10 $sobrenome = new TEntry('sobrenome');
11 $table->addRowSet(new TLabel('nome'),$nome); // linha com 2 componentes
12 $table->addRowSet(new TLabel('sobrenome'),$sobrenome);
13 parent::add($table);
14 }
15 }
16 ?>

TPanel
Como podem ver o uso da TTable bem simples , podemos usa-la para alinhar componentes em
formulrios como veremos mais adianti, seguindo nossa linha de raciocnio temos o TPanel, esse
painel interessante pois permite alinharmos os componentes dentro dele manualmente.

ViewTPanel

1 <?php
2 class ViewTPanel extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $panel = new TPanel(500,500);
7 $panel->style ="border: 1px solid #000;";
8 $nome = new TEntry('nome');
9 //$nome->setSize(200); caso queira facilitar os calculos coloque uma largura\
10 n\
11 os componentes
12 $lnome = new TLabel('nome');
13 //$lnome->setSize(50);
14 $panel->put($lnome,0,50);//componente,coluna, linha
15 $panel->put($nome,40,40);
Componentes 7

16 parent::add($panel);
17 }
18 }
19 ?>

o TPanel mais flexvel em aspecto de posio , podemos editar a opo style, como a tabela, ate
mesmo colocar uma class usando $panel->class dessa forma podemos ter painis, estilizados.

TNoteBook
Esse componente um dos mais interessantes, ele permite organizar os componenstes em abas, e
pode ser combinado com o TPanel ou a Table ou com ambos.
A Grande novidade da verso 3.0 poder adcionar o estilo bootstrap 3 em alguns componentes tais
como o TNotebook

ViewTNoteBook

1 <?php
2 class ViewTNoteBook extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $panel = new TPanel(500,300);
7 $panel->style ="border: 1px solid #000;";
8 $nome = new TEntry('nome');
9 //$nome->setSize(200); caso queira facilitar os calculos coloque uma largura\
10 n\
11 os componentes
12 $lnome = new TLabel('nome');
13 //$lnome->setSize(50);
14 $panel->put($lnome,0,50);//componente,coluna, linha
15 $panel->put($nome,40,40);
16 $table = new TTable();
17 $table->style = "border:1px solid #000";
18 $nome2 = new TEntry('nome2');
19 $sobrenome = new TEntry('sobrenome');
20 $table->addRowSet(new TLabel('nome2'),$nome2);
21 $table->addRowSet(new TLabel('sobrenome'),$sobrenome);
22
23 //adciona o estilo bootstrap no notebook
24 $notebook = new BootstrapNotebookWrapper(new TNotebook(600,320));//largura e\
Componentes 8

25 altura
26 $notebook->appendPage('Tabela',$table);
27 $notebook->appendPage('Panel',$panel);
28 parent::add($notebook);
29 }
30
31 ?>

TScroll
Este componente cria uma barra de rolagem dentro de um container, caso tenha uma quantidade de
componente alem do tamanho do container em questo, vamos ao modo de uso, usaremos em um
TNotebook.

ViewTScroll

1 <?php
2 class ViewTScroll extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $scroll = new TScroll(); // cria o scroll
7 $scroll->setSize(450,300); // largura e altura
8 $panel = new TPanel(400,400);
9 $notebook = new TNotebook(500,400);//largura e altura
10 $scroll->add($panel);
11 $notebook->appendPage('Panel',$scroll);
12 parent::add($notebook);
13 }
14 }
15 ?>

Como podem ver temos um panel dentro do TScroll, se o componente que estiver dentro do TScroll
tiver uma altura ou largura maiores, que do TScroll ele ira criar as barras de rolagem para que o
usurio possa utilizar, esse componente til quando se ter formulrios grandes.

TFrame
Este componente tem um uso interessante, segundo exemplos do prprio tudor alguns componentes
, podem ter interao direto via jquery, para mostrar ou esconder componentes, usurio o Notebook
para mostrar o uso desse componente , lembrando que pode ser combinado com outro container.
Componentes 9

ViewTFrame

1 <?php
2 class ViewTFrame extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $cpf = new TEntry('cpf');
7 $rg = new TEntry('rg');
8 $fields = new TTable();
9 $fields->addRowSet(new TLabel('CPF:'),$cpf);
10 $fields->addRowSet(new TLabel('RG:'),$rg);
11 $frame = new TFrame;
12 $frame->oid = 'frame';
13 $frame->setLegend('Dados Opcionais');
14 $frame->add($fields);
15 $button = new TButton('show_hide');
16 $button->class = 'btn btn-success btn-sm active'; // class do bootstrap 3
17 $button->setLabel('Dados Opcionais');
18 //codigo usando jquery, podemos usar outros codigos alem desse.
19 $button->addFunction("\$('[oid=frame]').slideToggle(); $(this).toggleCla\
20 ss( 'active' )");
21 $page = new TTable();
22 $page->addRowSet($button);
23 $page->addRowSet($frame);
24 $notebook = new TNotebook(500,400);//largura e altura
25 $notebook->appendPage('Panel',$page);
26 parent::add($notebook);
27 }
28 }
29 ?>

Nesse cdigo temos uma demostrao de como alterar a class de um TButton para usar class do
bootstrap 3 onde tambm inserimos uma action usando jquery que muda o estado do TButton e
mostra e esconde o TFrame, esse efeito pode ser usado em outros componentes desde que, saiba o
id do componente.

TVBox
Este componete serve para podermos organizar outros componentes em Vertical , caso no queira
usar TTable para fazer isso, vejamos 2 formas de usalo.
Componentes 10

ViewTVBox

1 <?php
2 class ViewTVBox extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $cpf = new TEntry('cpf');
7 $cpf->setTip('CPF'); // titulo para quando passar o mause sobre o campo
8 $rg = new TEntry('rg');
9 $rg->setTip('RG');
10 $vbox = new TVBox();
11 $vbox->add($cpf);
12 $vbox->add($rg);
13 $notebook = new TNotebook(300,200);//largura e altura
14 $notebook->appendPage('Panel',$vbox);
15 parent::add($notebook);
16 }
17 }
18 ?>

nesse exemplo usando o setTip do TEntry, para mostrar uma legenda quando passar o mouse sobre
o campo, e adcionamos um a um no TVBox, veremos um metodo mais rapido e com poucas linhas.

ViewTVBoxFast

1 <?php
2 class ViewTVBoxFast extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $cpf = new TEntry('cpf');
7 $cpf->setTip('CPF');
8 $rg = new TEntry('rg');
9 $rg->setTip('RG');
10 $vbox = new TVBox();
11 $vbox->addColSet($cpf,$rg);
12 $notebook = new BootstrapNotebookWrapper(new TNotebook(300,200));//largura e\
13 altura
14 $notebook->appendPage('Panel',$vbox);
15 parent::add($notebook);
16 }
Componentes 11

17 }
18 ?>

Dessa forma passamos os campos em uma unica linha e ele adciona cada campo em uma linha
diferente, uma otima forma de organizar containers dentro de um form ou dentro de um
TNoteBook.

THBox
Esse Container alinha os componentes na Horizontal funciona da mesma forma que o TVBox porem
na horizontal, vamos ver o exemplo de uso.

ViewTHBoxFast

1 <?php
2 class ViewTHBoxFast extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $cpf = new TEntry('cpf');
7 $cpf->setTip('CPF');
8 $rg = new TEntry('rg');
9 $rg->setTip('RG');
10 $hbox = new THBox();
11 $hbox->addRowSet($cpf,$rg);
12 $notebook = new TNotebook(500,200);//largura e altura
13 $notebook->appendPage('Panel',$hbox);
14 parent::add($notebook);
15 }
16 }
17 ?>

TWindow
Esse Container bem interessante, ele permite que mostre a pagina em modal, podendo ou no
blokiar outras aes, vamos a pratica.
Componentes 12

ViewTWindow

1 <?php
2 class ViewTWindow extends TWindow
3 {
4 function __construct(){
5 parent::__construct();
6 parent::setTitle('Titulo da janela'); // titulo da janela
7 parent::setSize(500,400); //tamanho da janela
8 parent::setModal(true); // coloca em modo modal bloqueando as
9 $cpf = new TEntry('cpf');
10 $cpf->setTip('CPF');
11 $rg = new TEntry('rg');
12 $rg->setTip('RG');
13 $hbox = new THBox();
14 $hbox->addRowSet($cpf,$rg);
15 $notebook = new TNotebook(500,200);//largura e altura
16 $notebook->appendPage('Panel',$hbox);
17 parent::add($notebook);
18 }
19 }
20 ?>
Dialogs TMessage
Essas caixas de Dialogo nos permite, mostrar informaes ,alertas at mesmo opes, ao usurio de
maneira simples. vamos ao nosso primeiro exemplo.

Info

ViewTMessage
1 <?php
2 class ViewTMessage extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 new TMessage('info','Seja bem vindo',null,'Bem Vindo');
7 }
8 }
9 ?>

Neste exemplo temos a TMessagem para informao, interessante nota que temos uma parmetro
null , nesse componente , que um tipo TAction, onde a ao executada se a janela fechada.
Vamos ao exemplo de janela de erro

Error

ViewTMessageError
1 <?php
2 class ViewTMessageError extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 new TMessage('error','No pode fazer esta ao',null,'Erro');
7 }
8 }
9 ?>

Como podem ver nesse exemplo mudamos apenas de info para error, bem simples no vamos ao
exemplos um pouco mais complexos.

13
Dialogs TMessage 14

TQuestion
Esse componente permite que o usurio tenha escolha , como se aceita ou no apagar um contado
muito til para confirmao, antes de apagar qualquer informao.

ViewTQuestion

1 <?php
2 class ViewTQuestion extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6
7 $action1 = new TAction(array($this,'onComfirme'));
8 $action2 = new TAction(array($this,'onCancel'));
9 new TQuestion('Deseja deletar esse contato ?',$action1,$action2,'Deletar \
10 COntato');
11 }
12 public function onComfirme(){
13 new TMessage('info','Confimado',null,'Confirmado');
14 }
15 public function onCancel(){
16 new TMessage('error','Deletar',null,'Deletar');
17 }
18 }
19 ?>

Como podem notar temos , opes diferentes para cada escolha do usurio, sendo assim maior
controle da aplicao, e evitamos que apague uma informao , sem ter certeza do que se esta
fazendo. Vamos agora a mais uma novidade dessa vero,

InputDialog
Nesse exemplo veremos como se faz um form de login usando esse componente.
Dialogs TMessage 15

ViewTInputDialog

1 <?php
2 class ViewTInputDialog extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $form = new TQuickForm('InputDialog');
7 $action = new TAction(array($this,'onMostrar'));
8 $form->addQuickAction('btnMostrar',$action,'bs:floppy-disk red');
9 parent::add($form);
10 }
11 public function onMostrar(){
12 $form = new TQuickForm('input_form');
13 $form->style = 'padding:20px';
14 $login = new TEntry('login');
15 $pass = new TPassword('password');
16 $form->addQuickField('Login', $login);
17 $form->addQuickField('Password', $pass);
18 $form->addQuickAction('Confirm 1', new TAction(array($this, 'onComfirme')), \
19 'ico_save.png');
20 $form->addQuickAction('Confirm 2', new TAction(array($this, 'onCancel'))
21 , 'ico_apply.png');
22 // show the input dialog
23 new TInputDialog('Input dialog title', $form);
24 }
25 public function onComfirme(){
26 new TMessage('info','Confimado',null,'Confirmado');
27 }
28 public function onCancel(){
29 new TMessage('error','Deletar',null,'Deletar');
30 }
31 }
32 ?>

No se preocupem com os forms e outros componentes nosso foco o mtodo onMostrar como
podem ver, quando chamamos o mtodo atravs de um formulrio rpido a caixa mostrada com
o nosso outro formulrio contendo 2 action, ou seja o mesmo conceito da TQuestion porem mais
completo.
Forms
Nesse capitulo iremos ver TUDO sobre formulrio, como criar, como estilizar, e veremos TODOS
seus componentes. Primeiramente vamos conhecer o TQuickForm, que a criao de formulrios
rpidos.

TQuickForm

ViewTQuickForm
1 <?php
2 class ViewTQuickForm extends TPage
3 {
4 function __construct(){
5 parent::__construct();
6 $form = new BootstrapFormWrapper(new TQuickForm('input_form')); // cria o fo\
7 rmulario
8 $login = new TEntry('login'); // cria input do tipo text
9 $pass = new TPassword('password'); //cria input do tipo password
10 $form->addQuickField('Login', $login); // adciona campo com label no form
11 $form->addQuickField('Password', $pass);
12 // adciona botoes de ao, j com ao onde
13 //addQuickAction(label,action,icone);
14 $form->addQuickAction('Confirm 1', new TAction(array($this, 'onComfirme')), \
15 'bs:plus green');
16 $form->addQuickAction('Confirm 2', new TAction(array($this, 'onCancel')) , \
17 'fa:trash-o blue');
18
19 parent::add($form);
20
21 }
22 public function onComfirme(){
23 new TMessage('info','COnfimado',null,'Confirmado');
24 }
25 public function onCancel(){
26 new TMessage('error','Deletar',null,'Deletar');
27 }
28 }
29 ?>

16
Forms 17

Nesse cdigo temos uma explicao sobre o TEntry e o TPassword como podem ver so simples
campos html, outro ponto importante so os cones usados nas QuickAction, temos no Comfirm1
um cone do bootstrap 3 onde usa-se bs:nomeico cor, dessa maneira posso usar todos os cones
do bootstrap 3, j no comfirm 2 temos o conde da Font awesome onde podemos usar todos seus
cones usando fa:icone cor, dessa maneira podemos usar nos botes tambm , para assim termos um
melhor visual de nosso sistema, como sabemos no adianta ser funcional se no for bonito. Vamos
aproveitar o contexto e ver todos os componentes que podem ser usados nos formulrios e como
pegar o contedo de cada um deles.

FormCustomView

1 <?php
2 class FormCustomView extends TPage
3 {
4 private $form;
5 /**
6 * Class constructor
7 * Creates the page
8 */
9 function __construct()
10
11 {
12 parent::__construct();
13 // create the notebook
14 $notebook = new TNotebook(620, 340);
15 // create the form
16 $this->form = new TForm;
17 // creates the notebook page
18 $table = new TTable;
19 $table2 = new TTable;
20 $table3 = new TTable;
21 // add the notebook inside the form
22 // create the form fields
23 $field1 = new TEntry('field1');
24 $field2 = new TEntry('field2');
25 $field3 = new TEntry('field3');
26 $field4 = new TEntry('field4');
27 $field5 = new TPassword('field5');
28 $field6 = new TDate('field6');
29 $field7 = new TSpinner('field7');
30 $field8 = new TSlider('field8');
31 $field9 = new TText('field9');
32 $field10 = new TImage('app/images/42_thumb.jpeg');
Forms 18

33 $field10->width = '100px';
34 $field11 = new TCombo('field13'); // combo box
35 // imagem
36 // itens do fiend11
37 $itens = array('alexandre'=>"alexandre",'Elbert'=>"Elbert");
38 $field11->addItems($itens); // adciona os itens
39 $field12 = new TCheckGroup('checkbox');
40 $field13 = new TRadioGroup('radiobutton');
41 // grupo de checkbox
42 $field12->addItems(array('php'=>'php','asp'=>'asp','javascript'=>'javascript\
43 '));
44 // adciona itens no radio grupo
45 $field13->addItems(array('masculino'=>'masculino','feminino'=>'feminino'));
46
47 $field14 = new THtmlEditor('field10');
48 $field14->setSize(400,200);
49
50 $field1->setTip('Tip para field 1'); // usando tipo
51
52 $field2->setValue('123');
53 $field2->setEditable(FALSE);
54 $field3->setMask('99.999-999');
55 $field4->setMaxLength(10);
56 $field6->setSize(100);
57 $field7->setRange(0,100,10);
58 $field8->setRange(0,100,10);
59 $field7->setValue(30);
60 $field8->setValue(50);
61 $field9->setSize(300, 50);
62
63 // add rows for the fields
64 $table->addRowSet( new TLabel('TEntry object:'), $field1 );
65 $table->addRowSet( new TLabel('TEntry not editable:'), $field2 );
66 $table->addRowSet( new TLabel('TEntry with mask:'), $field3, new TLabel('99.\
67 999-999') );
68 $table->addRowSet(
69 $table->addRowSet(
70 $table->addRowSet(
71 $table->addRowSet(
72 $table->addRowSet(
73 $table->addRowSet(
74 $table2->addRowSet(
Forms 19

75 $table2->addRowSet(
76 $table2->addRowSet(
77 $table2->addRowSet(
78
79 new TLabel('TEntry with maxlength (10):'), $field4 );
80 new TLabel('TPassword object:'), $field5 );
81 new TLabel('TDate Object:'), $field6 );
82 new TLabel('Spinner Object:'), $field7 );
83 new TLabel('Slider Object:'), $field8 );
84 new TLabel('TText Object:'), $field9 );
85 new TLabel('IMagem:'), $field10 );
86 new TLabel('ComboBox'), $field11 );
87 new TLabel('Checkbox'), $field12 );
88 new TLabel('RadioButtons'), $field13 );
89 $table3->addRowSet( new TLabel('Editor HTML'), $field14 );
90 // creates the action button
91 $button1=new TButton('action1');
92 // define the button action
93 $button1->setAction(new TAction(array($this, 'mostrarDados')), 'mostrarD\
94 ados');
95 $button1->setImage('bs:search');
96 // define wich are the form fields
97 $this->form->setFields(array($field1, $field2, $field3, $field4, $field5,
98 $field6, $field7, $field8, $field9,$field1\
99 1,$field12,$field13,$field14, $button1));
100 // add a row for the button
101 $row=$table->addRow();
102 $row->addCell($button1);
103 // adds the notebook page
104 $notebook->appendPage('Input elements', $table);
105 $notebook->appendPage('Input elements 2', $table2);
106 $this->form->add($notebook);
107 parent::add($this->form);
108 }
109
110
111 public function mostrarDados($param)
112 {
113 $data = $this->form->getData(); // optional parameter: active record cla\
114
115 // put the data back to the form
116 $this->form->setData($data);
Forms 20

117
118
119 // creates
120
121 $message = "a string with the form element's values";
122 $message .= 'TEntry : ' . $data->field1 . '<br>';
123 $message .= 'TEntry not editable : ' . $data->field2 . '<br>';
124 $message .= 'TEntry with mask: ' . $data->field3 . '<br>';
125 $message .= 'TEntry with maxlength (10) : ' . $data->field4 . '<br>';
126 $message .= 'TPassword object : ' . $data->field5 . '<br>';
127 $message .= 'TDate Object: ' . $data->field6 . '<br>';
128 $message .= 'Spinner Object : ' . $data->field7 . '<br>';
129 $message .= 'Slider Object: ' . $data->field8 . '<br>';
130 $message .= 'TText Object : ' . $data->field9 . '<br>';
131 $message .= 'Editor HTML : ' . $data->field10. '<br>';
132
133 // grupos de campos
134 echo "TCheckGoup";
135 print_r($data->checkbox) ;
136 echo "TRadioGroup";
137 print_r($data->radiobutton);
138 // show the message
139 new TMessage('info', $message);
140 }
141 }
142 ?>

TEntry
esse componente cria um iput do tipo texto onde podem ser alterados seu Tip, e inserido mascaras
seu uso bem simples

TEntry

1 <?php
2
3 $field1 = new TEntry('field1');
4 $field1->setTip('Tip for field 1'); // dica de campo
5 $field1->setValue('123'); // seta valor inicial
6 $field1->setEditable(FALSE); // bloqueia edio de valor
7 $field1->setMask('99.999-999'); // mascara para valores
8 $field1->setMaxLength(10); // limit de caracters
Forms 21

9 $field1->{css} = "background-color:#efffef";
10
11 ?>

como podem ver temos uma vasta lista de propriedades que podemos usar e o interessante que
podemos alterar class do css e at mesmo o css

TPassword
1 <?php
2
3 $field1 = new TPassword('field1');
4
5 ?>

um campo simples onde tem as opes do TEntry porem um campo para senhas
TDate
um campo usado para, datas por padro sua mascara no formato Y-m-d mas pode ser alterado
usando o setmask.

1 $field1 = new TDate('field1');


2 $field1->setMask('dd/mm/Y');

TSpinner
Esse componente permite que o usurio , use apenas nmeros, particularmente esse setRange, no
funciona como deveria, mas pode vim a ser til.

1 $field1 = new TSpinner('field1');


2 $field1->setRange($min,$max,$step) // para trocar os valores

TSlider
Esse componente permite que o usurio , use uma barra para escolher o valor , em numero bom para
gerenciadores de tarefas ou processos.

1 $field1 = new TSlider('field1');


2 $field1->setRange($min,$max,$step) // para trocar os valores

TText
Componente usado para caixa de texto onde se pode passar uma altura e largura um campo simples,
onde o usurio no pode usar qualquer formatao para o texto.

1 $field1 = new TText('field1');


2 $field1->setSize($width, $height); // largura , altura

TImage

22
TDate 23

1 <?php
2
3 $field1 = new TImage('app/images/42_thumb.jpeg');
4 $field1->width = '100px'; // pode usar as propriedades da imagem para altera-la
5
6 ?>

TCheckGroup
Este campo usado para criar grupos de checkbox, onde se passa uma array , na propriedade setItens
onde o usuario pode selecionar varios itens, ao mesmo tempo

1 <?php
2
3 $field1 = new TCheckGroup('cursos');
4 // array de itens, para utilizar na hora de pegar os valores.
5 $field1->addItems(array('php'=>'php','asp'=>'asp','javascript'=>'javascript'));
6
7 ?>

TRadioGroup
Utilizado quando restrito a escolha de um nico item , como por exemplo em um formulrio onde
se tem que escolher seu sexo.

1 <?php
2 $field1 = new TRadioGroup('sexo');
3 // array de itens, para utilizar na hora de pegar os valores.
4 $field1->addItems(array('php'=>'php','asp'=>'asp','javascript'=>'javascript'));
5
6 ?>

THtmlEditor
Cria uma caixa de edio de texto, semelhante ao editor de texto simples com recursos de edio
, veremos futuramente, uma class semelhante na PWD, onde temos um componente, semelhante ,
porem melhorado.
TDate 24

1 <?php
2
3 $field1 = new THtmlEditor('field1');
4 $field1->setSize(400,200);
5
6 ?>

TLabel
Esse componente cria uma label para os campos, usado para indicar um campo.

1 <?php
2
3 $lfield1 = new TLabel('CPF');
4 $lfield1->class = 'label label-success';
5
6 ?>

nas Grids e ver como elas funcionam, a algum tempo , listar dados em tabelas era um terror linhas
, colunas porem com o Adianti fica tudo mais lindo, e facl
Grids
O Objetivo das grids justamente mostrar o quanto facil, mostrar contedo e as personalizar. Para
nosso primeiro exemplo vamos usar o exemplo do tutor

DatagridQuickView

1 <?php
2 /**
3 * DatagridQuickView
4
5 */
6 class DatagridQuickView extends TPage
7 {
8 private $datagrid;
9 public function __construct()
10 {
11 parent::__construct();
12 // creates one datagrid
13 $this->datagrid = new TQuickGrid;
14 $this->datagrid->setHeight(320);
15 // add the columns
16 $this->datagrid->addQuickColumn('Code',
17 'code',
18 'right', 70, new TAction(array($this, 'onColumnAction')), array('column', 'c\
19 ode'));
20 $this->datagrid->addQuickColumn('Name',
21 'name',
22 'left', 180, new TAction(array($this, 'onColumnAction')), array('column', 'n\
23 ame'));
24 $this->datagrid->addQuickColumn('Address', 'address', 'left', 180, new TActi\
25 on(array($this, 'onColumnAction')), array('column', 'address'));
26
27 $this->datagrid->addQuickColumn('Phone','fone','left', 160, new TAction(arra\
28 y($this, 'onColumnAction')), array('column', 'fone'));
29 $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
30 // add the actions
31 $this->datagrid->addQuickAction('View',
32 new TDataGridAction(array($this, 'onView')),'name', 'ico_find.png');
33 $this->datagrid->addQuickAction('Delete', new TDataGridAction(array($this, '\

25
Grids 26

34 onDelete')), 'code', 'ico_delete.png');


35
36 // creates the datagrid model
37 $this->datagrid->createModel();
38 // wrap the page content using vertical box
39 $vbox = new TVBox;
40 $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
41 $vbox->add($this->datagrid);
42 parent::add($vbox);
43 }
44 /**
45 * Load the data into the datagrid
46 */
47 function onReload()
48 {
49 $this->datagrid->clear();
50
51 // add an regular object to the datagrid
52 $item = new StdClass;
53 $item->code= '1';
54 $item->name= 'Fbio Locatelli';
55 $item->address = 'Rua Expedicionario';
56 $item->fone= '1111-1111';
57 $this->datagrid->addItem($item);
58 // add an regular object to the datagrid
59 $item = new StdClass;
60 $item->code = '2';
61 $item->name = 'Julia Haubert';
62 $item->address = 'Rua Expedicionarios';
63
64 $item->fone= '2222-2222';
65 $this->datagrid->addItem($item);
66 // add an regular object to the datagrid
67 $item = new StdClass;
68 $item->code = '3';
69 $item->name = 'Carlos Ranzi';
70 $item->address = 'Rua Oliveira';
71 $item->fone = '3333-3333';
72 $this->datagrid->addItem($item);
73
74 // add an regular object to the datagrid
75 $item = new StdClass;
Grids 27

76 $item->code = '4';
77 $item->name = 'Daline DallOglio';
78 $item->address = 'Rua Oliveira';
79 $item->fone = '4444-4444';
80 $this->datagrid->addItem($item);
81 }
82 /**
83 * method onColumnAction()
84 * Executed when the user clicks at the column title
85 */
86 function onColumnAction($param)
87 {
88 // get the parameter and shows the message
89 $key=$param['column'];
90 new TMessage('info', "You clicked at the column $key");
91 }
92 /**
93 * method onDelete()
94 * Executed when the user clicks at the delete button
95 */
96 function onDelete($param)
97 {
98 // get the parameter and shows the message
99 $key=$param['key'];
100 new TMessage('error', "The register $key may not be deleted");
101 }
102
103 /**
104 * method onView()
105 * Executed when the user clicks at the view button
106 */
107 function onView($param)
108 {
109 // get the parameter and shows the message
110 $key=$param['key'];
111 new TMessage('info', "The name is : $key");
112 }
113 /**
114 * shows the page
115 */
116 function show()
117 {
Grids 28

118 $this->onReload();
119 parent::show();
120 }
121 }
122 ?>

Essa a TQuickGrid um grid rpida onde temos algumas , opes vamos ver parte a parte todo o
codigo. Aqui criamos a TQuickGrid e damos uma altura para ela.

1 <?php
2
3 // creates one datagrid
4 $this->datagrid = new TQuickGrid;
5 $this->datagrid->setHeight(320);
6
7 ?>

Nessa parte colocamos os campos que iremos passar no mtodo de carregar, onde temos addQuick-
Column(label,nome da coluna,posio, tamanho, action) essa action disparada caso o usurio click
na coluna, sem usar os botes , da grid

1 <?php
2
3 // add the columns
4 $this->datagrid->addQuickColumn('Code','code','right', 70,
5 Action(array($this, 'onColumnAction')), array('column', 'code'));
6 $this->datagrid->addQuickColumn('Name','name','left', 180,
7 Action(array($this, 'onColumnAction')), array('column', 'name'));
8 $this->datagrid->addQuickColumn('Address', 'address', 'left', 180,
9 Action(array($this, 'onColumnAction')), array('column', 'address'));
10 $this->datagrid->addQuickColumn('Phone','fone','left', 160,
11 Action(array($this, 'onColumnAction')), array('column', 'fone'));

Aqui temos as aes, para a grid, sim o botes que ficam na grid, lembrando que nessa verso
podemos usar os cones do bottstrap, que chamarei de BT. Nas action temos View que o label , da
action, seguido da TDataGridAction(array(class da action,nome da action),parametro,icone)
Grids 29

1 <?php
2 // add the actions
3 $this->datagrid->addQuickAction('View',new TDataGridAction(array($this, 'onView'\
4 )),'name', 'bs:search red');
5 $this->datagrid->addQuickAction('Delete', new TDataGridAction(array($this, 'onDe\
6 lete')), 'code', 'ico_delete.png');

?>
Agora onde cria a grid propriamente dita.

1 <?php
2
3 // creates the datagrid model
4 $this->datagrid->createModel();

TQuickGrid Actions
Vamos agora ao mtodo onde popula nossa grid, como podem ver bem simples onde temos, a
StdClass, que um objeto genrico , assim por dianti , para mostrar para o framework basta usar o
nome dado a linha lembram, code,name,address,fone, dessa maneira o framework j intende oque
tem que ser colocado onde.

1 <?php
2
3 <?php
4 function onReload()
5 {
6 $this->datagrid->clear();
7 // add an regular object to the datagrid
8 $item = new StdClass;
9 $item->code= '1';
10 $item->name= 'Fbio Locatelli';
11 $item->address = 'Rua Expedicionario';
12 $item->fone = '1111-1111';
13 $this->datagrid->addItem($item);
14 // add an regular object to the datagrid
15 $item = new StdClass;
16 $item->code = '2';
17 $item->name = 'Julia Haubert';
18 $item->address = 'Rua Expedicionarios';
19 $item->fone = '2222-2222';
Grids 30

20 $this->datagrid->addItem($item);
21 // add an regular object to the datagrid
22 $item = new StdClass;
23 $item->code = '3';
24 $item->name = 'Carlos Ranzi';
25 $item->address = 'Rua Oliveira';
26 $item->fone = '3333-3333';
27 $this->datagrid->addItem($item);
28 // add an regular object to the datagrid
29 $item = new StdClass;
30 $item->code = '4';
31 $item->name = 'Daline DallOglio';
32 $item->address = 'Rua Oliveira';
33 $item->fone = '4444-4444';
34 $this->datagrid->addItem($item);
35 }
36
37
38 ?>

Apos isso para mostrar ao carregar a pagina basta chamar o metodo que criamos, no metodo show
da TPage assim ao mostrar a pagina , ele ira popular a grid.

1 <?php
2 function show()
3 {
4 $this->onReload();
5 parent::show();
6 }
7 ?>

No esquecendo os mtodos, que usamos nas linhas as Actions, vamos ver com cria-las, j que
colocamos as actions nas linhas ao clicar na linha , ele dispara o metodo onColumnAction que esta
na mesma class , que a grid por isso usado a palavra $this, na action assim indica que a ao esta
na mesma class que a grid. Como podem ver, em nosso mtodos temos a varivel $param, que
nossos parametros passados na action dessa maneira conseguimos, reordenar a grid, mostrar dados,
ate mesmo apagar linhas.
Grids 31

1 <?php
2
3 function onColumnAction($param)
4 {
5 // get the parameter and shows the message
6 $key=$param['column'];
7 new TMessage('info', "You clicked at the column $key");
8 }

Vamos ver como seria os metodos para visualizar ou excluir itens. No mtodo , acima usamos a
column para pegarmos, o dado da coluna, j nas actions , da grid usadas nos botes, usamos o
parametro key.

1 <?php
2
3 function onDelete($param)
4 {
5 // get the parameter and shows the message
6 $key=$param['key'];
7 new TMessage('error', "The register $key may not be deleted");
8 }
9 function onView($param)
10 {
11 // get the parameter and shows the message
12 $key=$param['key'];
13 new TMessage('info', "The name is : $key");
14 }

Estilizando as Grids possivel alterarmos os css da grid do mesmo modo que dos outros componentes
isso pode ser feito atraves de css de maneira muito simples, basta mudar a class da grid para a que
criamos, lembrando que a grid uma table sendo assim fica fcil. pode usar o parent::include, para
incluir o css caso for alterar uma nica, tabela, ou pode incluir no template para alterar todas assim
, basta apenas alterar as class das grids.

1 $this->datagrid->class='table-estilizada';
2 // inclui css
3 parent::include_css('app/resources/custom-table.css');

TDataGrid
Vamos agora ver como funciona uma grid mais complexa, temos a TDataGrid bem simples de usar.
Bem semelhante a TQuickGrid porem, nessa podemos facilmente colocar um grupo de botes de
Grids 32

opo ao invs de colocarmos como na grid de TQuickGrid, temos ento a TDataGrid, sem nem uma
alterao a diferena que suas Actions sem mais detalhadas e mais facil de passar parmetros.
Lembrando que temos a opo de usar o bootstrap e de deixar a grid responsiva

DatagridActionGroupView

1 <?php
2 class DatagridActionGroupView extends TPage
3 {
4 private $datagrid;
5 public function __construct()
6 {
7 parent::__construct();
8 // creates one datagrid
9 $this->datagrid = new TDataGrid;
10 // create the
11 $code = new TDataGridColumn('code','Code','right',50);
12 $name = new TDataGridColumn('name','Name',left,100);
13 $address = new TDataGridColumn('address','Adddress',left,100);
14 $telephone = new TDataGridColumn('fone','Fone',left,100);
15
16 // add the columns to the datagrid
17 $this->datagrid->addColumn($code);
18 $this->datagrid->addColumn($name);
19 $this->datagrid->addColumn($address);
20 $this->datagrid->addColumn($telephone);
21
22 // creates two datagrid actions
23 $action1 = new TDataGridAction(array($this, 'onView'));
24 $action1->setLabel('View name');
25 $action1->setImage('bs:search blue');
26 $action1->setField('name');
27 $action2 = new TDataGridAction(array($this, 'onDelete'));
28 $action2->setLabel('Try to delete');
29 $action2->setImage('bs:remove red');
30 $action2->setField('code');
31 $action3 = new TDataGridAction(array($this, 'onView'));
32 $action3->setLabel('View address');
33 $action3->setImage('bs:hand-right green');
34 $action3->setField('address');
35 $this->datagrid->addAction($action1);
36 $this->datagrid->addAction($action2);
37 $this->datagrid->addAction($action3);
Grids 33

38 // creates the datagrid model


39 $this->datagrid->createModel();
40 parent::add($this->datagrid);
41 }
42 /**
43 * Load the data into the datagrid
44 */
45 function onReload()
46 {
47 $this->datagrid->clear();
48
49 // add an regular object to the datagrid
50 $item = new StdClass;
51 $item->code = '1';
52 $item->name= 'Fbio Locatelli';
53 $item->address = 'Rua Expedicionario';
54 $item->fone= '1111-1111';
55 $this->datagrid->addItem($item);
56 // add an regular object to the datagrid
57 $item = new StdClass;
58 $item->code= '2';
59 $item->name= 'Julia Haubert';
60 $item->address = 'Rua Expedicionarios';
61 $item->fone= '2222-2222';
62 $this->datagrid->addItem($item);
63 // add an regular object to the datagrid
64 $item = new StdClass;
65 $item->code= '3';
66 $item->name= 'Carlos Ranzi';
67 $item->address = 'Rua Oliveira';
68 $item->fone= '3333-3333';
69 $this->datagrid->addItem($item);
70 // add an regular object to the datagrid
71 $item = new StdClass;
72 $item->code = '4';
73 $item->name= 'Daline DallOglio';
74 $item->address = 'Rua Oliveira';
75 $item->fone= '4444-4444';
76 $this->datagrid->addItem($item);
77 }
78 /**
79 * method onDelete()
Grids 34

80 * Executed when the user clicks at the delete button


81 */
82 function onDelete($param)
83 {
84 // get the parameter and shows the message
85 $key=$param['key'];
86
87 new TMessage('error', "The register $key may not be deleted");
88 }
89 /**
90 * method onView()
91 * Executed when the user clicks at the view button
92 */
93 function onView($param)
94 {
95 // get the parameter and shows the message
96 $key=$param['key'];
97 new TMessage('info', "The information is : $key");
98 }
99 /**
100 * shows the page
101 */
102 function show()
103 {
104 $this->onReload();
105 parent::show();
106 }
107 }
108 ?>

Podemos colocar um grupo de opes juntos, sem ter que alterar muita coisa. basta tirar o $this-
>datagrid->addAction.

Grid com Componentes de formulrio


Podemos , usar componentes de formularios na grid , dessa forma fica facil editar, ou ate mesmo
selecionar, vamos usar a mesma class acima, e apenas altera-la.
Grids 35

DatagridActionGroupViewForm

1 <?php
2 class DatagridActionGroupViewForm extends TPage
3 {
4 private $datagrid;
5 private $form;
6 public function __construct()
7 {
8 parent::__construct();
9 // creates one datagrid
10 $this->datagrid = new TDataGrid;
11 $this->form = new TForm('progs');
12 $btnSalvar = TButton::create('salvar',array($this,'onSave'),'salvar','bs\
13 :user');
14 //cria box para organizar os itens
15 $box = new TVBox();
16 $box->add($this->datagrid);
17 $box->add($btnSalvar);
18 $this->form->add($box);
19
20 $this->form->addField($btnSalvar);
21 // create the datagrid columns
22 $code = new TDataGridColumn('code','Code','right',50);
23 $name = new TDataGridColumn('name','Name',left,100);
24 $address = new TDataGridColumn('address','Adddress',left,100);
25 $telephone = new TDataGridColumn('fone','Fone',left,100);
26 // add the columns to the datagrid
27 $this->datagrid->addColumn($code);
28 $this->datagrid->addColumn($name);
29 $this->datagrid->addColumn($address);
30 $this->datagrid->addColumn($telephone);
31 // creates two datagrid actions
32 $action1 = new TDataGridAction(array($this, 'onView'));
33 $action1->setLabel('View name');
34 $action1->setImage('bs:search blue');
35 $action1->setField('name');
36
37 $action2 = new TDataGridAction(array($this, 'onDelete'));
38 $action2->setLabel('Try to delete');
39 $action2->setImage('bs:remove red');
40 $action2->setField('code');
41
Grids 36

42 $action3 = new TDataGridAction(array($this, 'onView'));


43 $action3->setLabel('View address');
44 $action3->setImage('bs:hand-right green');
45 $action3->setField('address');
46
47
48 $action_group = new TDataGridActionGroup('Actions', 'bs:th');
49 $action_group->addHeader('Available Options');
50 $action_group->addAction($action2);
51 $action_group->addSeparator();
52 $action_group->addHeader('Another Options');
53
54 $action_group->addAction($action3);
55 // add the actions to the datagrid
56 $this->datagrid->addActionGroup($action_group);
57 // creates the datagrid model
58 $this->datagrid->createModel();
59 parent::add($this->form);
60 }
61 /**
62 * Load the data into the datagrid
63 */
64 function onReload()
65 {
66 $this->datagrid->clear();
67 // add an regular object to the datagrid
68 $item = new StdClass;
69 $item->code= '1';
70 $item->name= 'Fbio Locatelli';
71 $item->address = new TEntry('anddress1'); // coloca um TENtry
72 $item->address->setValue('Rua Expedicionario'); // seta o valor
73 $item->fone= '1111-1111';
74 $this->datagrid->addItem($item);
75 $this->form->addField($item->address);
76 }
77 /**
78 * method onDelete()
79 * Executed when the user clicks at the delete button
80 */
81 function onDelete($param)
82 {
83 // get the parameter and shows the message
Grids 37

84 $key=$param['key'];
85 new TMessage('error', "The register $key may not be deleted");
86 }
87
88 /**
89 * method onView()
90 * Executed when the user clicks at the view button
91 */
92 function onView($param)
93 {
94 // get the parameter and shows the message
95 $key=$param['key'];
96 new TMessage('info', "The information is : $key");
97 }
98 function onSave(){
99 }
100 /**
101 * shows the page
102 */
103 function show()
104 {
105 $this->onReload();
106 parent::show();
107 }
108 }
109 ?>

Observem que colocamos um form , e dentro dele a TGrid, apos isso basta no metodo onde carrega
a TGrid passarmos o componente e seu valor.

Email e Telefone Edit

1 // add an regular object to the datagrid


2 $item = new StdClass;
3 $item->code= '1';
4 $item->name= 'Fbio Locatelli';
5 $item->address = 'Rua Expedicionario';
6 $item->fone= '1111-1111';
7 $this->datagrid->addItem($item);
8 // add an regular object to the datagrid
9 $item = new StdClass;
10 $item->code = '2';
11 $item->name = 'Julia Haubert';
Grids 38

12 $item->address = 'Rua Expedicionarios';


13
14 $item->fone= '2222-2222';
15 $this->datagrid->addItem($item);
16 // add an regular object to the datagrid
17 $item = new StdClass;
18 $item->code = '3';
19 $item->name = 'Carlos Ranzi';
20 $item->address = 'Rua Oliveira';
21 $item->fone = '3333-3333';
22 $this->datagrid->addItem($item);
23
24 // add an regular object to the datagrid
25 $item = new StdClass;
26 $item->code = '4';
27 $item->name = 'Daline DallOglio';
28 $item->address = 'Rua Oliveira';
29 $item->fone = '4444-4444';
30 $this->datagrid->addItem($item);
31 }
32 /**
33 * method onColumnAction()
34 * Executed when the user clicks at the column title

Pode-se usar qualquer componente usado em formulrio, desde que se passa seu valor.
Condies para Opes
Como essa nova verso bem interessante , para controle de permisso no preciso usar if no
meio do codigo, podemos usar condies que podem ou no mostrar as opes desde que tenham
um rollback Usando o codigo a cima, basta alterar uma action , inserindo a propriedade que ira
checar se deve ou no ser exibida.

1 <?php
2
3 // creates datagrid actions
4 $action1 = new TDataGridAction(array($this, 'onView'));
5 $action1->setLabel('View name');
6 $action1->setImage('bs:search blue');
7 $action1->setField('name');
8 $action1->setDisplayCondition(array($this,'verifica')); // verifica se deve ser \
9 exibida
10
11 ?>

Para mostrar se possivel ou no, mostrar o item basta fazer uma comparao e retornar uma valor
boolean, assim se for falso o retorno ele no exibe, se for verdadeira que o item dever ser exibido.

Email e Telefone Edit

1 function onReload()
2 {
3 $this->datagrid->clear();
4
5 // add an regular object to the datagrid
6 $item = new StdClass;
7 $item->code= '1';
8 $item->name= 'Fbio Locatelli';
9 $item->address = 'Rua Expedicionario';
10 $item->fone= '1111-1111';
11 $this->datagrid->addItem($item);
12 // add an regular object to the datagrid
13 $item = new StdClass;
14 $item->code = '2';
15 $item->name = 'Julia Haubert';

39
Condies para Opes 40

16 $item->address = 'Rua Expedicionarios';


17
18 $item->fone= '2222-2222';
19 $this->datagrid->addItem($item);
20 // add an regular object to the datagrid
21 $item = new StdClass;
22 $item->code = '3';
23 $item->name = 'Carlos Ranzi';
24 $item->address = 'Rua Oliveira';
25 $item->fone = '3333-3333';
26 $this->datagrid->addItem($item);
27
28 // add an regular object to the datagrid
29 $item = new StdClass;
30 $item->code = '4';
31 $item->name = 'Daline DallOglio';
32 $item->address = 'Rua Oliveira';
33 $item->fone = '4444-4444';
34 $this->datagrid->addItem($item);
35 }

1 <?php
2
3
4 public function verifica( $object )
5 {
6 if ($object->code > 1 )
7 {
8 return TRUE;
9 }
10 return FALSE;
11 }

You might also like