Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Chamar um formulário por meio de uma condicional IF Bom dia pessoal Tenho dois forms: ClientesFormPF e ClientesFormPJ Gostaria de clicar no botão Editar dentro do Grid e conforme o tipo de pesso física ou jurídica chamar o form correspondente, segue meu código abaixo: ...
PS
Chamar um formulário por meio de uma condicional IF  
Bom dia pessoal
Tenho dois forms: ClientesFormPF e ClientesFormPJ
Gostaria de clicar no botão Editar dentro do Grid e conforme o tipo de pesso física ou jurídica chamar o form correspondente, segue meu código abaixo:

  1. <?php
  2. /**
  3.  * ClientesLista Listing
  4.  * @author  <your name here>
  5.  */
  6. class ClientesLista extends TPage
  7. {
  8.     private $form// form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $formgrid;
  12.     private $loaded;
  13.     private $deleteButton;
  14.     
  15.     /**
  16.      * Class constructor
  17.      * Creates the page, the form and the listing
  18.      */
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.         
  23.         // creates the form
  24.         $this->form = new BootstrapFormBuilder('form_search_Clientes');
  25.         $this->form->setFormTitle('Clientes');        
  26.         // create the form fields
  27.         $id             = new TEntry('id');        
  28.         $nome             = new TEntry('nome');
  29.         $pessoa_tp_id     = new TDBCombo('pessoa_tp_id''gestoros''PessoaTp''id''nome');
  30.         $cpfcnpj         = new TEntry('cpfcnpj');
  31.         $criteria         = new TCriteria;
  32.         $ativo             = new THidden('ativo');
  33.         $ativo             '1';
  34.         $criteria->add(new TFilter('ativo_id''='$ativo));
  35.         //$cidades_id = new TDBUniqueSearch('cidades_id', 'gestoros', 'Cidades', 'id', 'nome', 'nome');
  36.         $cidades_id = new TDBCombo('cidades_id''gestoros''Cidades''id''nome''nome'$criteria);                
  37.         //$cidades_id->setValue('TODAS');
  38.         $ativo_id = new TDBCombo('ativo_id''gestoros''Ativo''id''nome');
  39.         
  40.         $nome->style "text-transform: uppercase";
  41.         
  42.         // add the fields
  43.         $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  44.         $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
  45.         $this->form->addFields( [ new TLabel('Pessoa') ], [ $pessoa_tp_id ] );
  46.         $this->form->addFields( [ new TLabel('CPF/CNPJ') ], [ $cpfcnpj ] );
  47.         $this->form->addFields( [ new TLabel('Cidade') ], [ $cidades_id ] );
  48.         $this->form->addFields( [ new TLabel('Ativo') ], [ $ativo_id ] );
  49.         // set sizes
  50.         $id->setSize('100%');
  51.         $nome->setSize('100%');
  52.         $pessoa_tp_id->setSize('100%');
  53.         $cpfcnpj->setSize('100%');
  54.         $cidades_id->setSize('100%');
  55.         $ativo_id->setSize('100%');
  56.         
  57.         // keep the form filled during navigation with session data
  58.         $this->form->setDataTSession::getValue(__CLASS__ '_filter_data') );
  59.         
  60.         // add the search form actions
  61.         $btn $this->form->addAction(_t('Find'), new TAction([$this'onSearch']), 'fa:search');
  62.         $btn->class 'btn btn-sm btn-primary';
  63.         $this->form->addActionLink(_t('New'), new TAction(['ClientesForm''onEdit']), 'fa:plus green');
  64.         
  65.         // creates a Datagrid
  66.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  67.         $this->datagrid->style 'width: 100%';
  68.         $this->datagrid->datatable 'true';
  69.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');        
  70.         $this->datagrid->enablePopover('Clique para alterar''Cliente: <b> {id} </b>');
  71.         // creates the datagrid columns
  72.         $column_id = new TDataGridColumn('id''Id''right'10);
  73.         $column_nome = new TDataGridColumn('nome''Nome''left');
  74.         $column_pessoa_tp_id = new TDataGridColumn('pessoa_tp->nome''Pessoa''left');
  75.         $column_cpfcnpj = new TDataGridColumn('cpfcnpj''CPF/CNPJ''left');
  76.         $column_cidades_id = new TDataGridColumn('cidades->nome''Cidade''right');
  77.         $column_ativo_id = new TDataGridColumn('ativo_id''Ativo''right');
  78.         // add the columns to the DataGrid
  79.         $this->datagrid->addColumn($column_id);
  80.         $this->datagrid->addColumn($column_nome);
  81.         $this->datagrid->addColumn($column_pessoa_tp_id);
  82.         $this->datagrid->addColumn($column_cpfcnpj);
  83.         $this->datagrid->addColumn($column_cidades_id);
  84.         $this->datagrid->addColumn($column_ativo_id);
  85.         $column_ativo_id->setTransformer( function($value$object$row) {
  86.             $class = ($value=='2') ? 'danger' 'success';
  87.             $label = ($value=='2') ? _t('No') : _t('Yes');
  88.             $div = new TElement('span');
  89.             $div->class="label label-{$class}";
  90.             $div->style="text-shadow:none; font-size:12px; font-weight:lighter";
  91.             $div->add($label);
  92.             return $div;
  93.         });
  94.         // creates the datagrid column actions
  95.         $column_id->setAction(new TAction([$this'onReload']), ['order' => 'id']);
  96.         $column_nome->setAction(new TAction([$this'onReload']), ['order' => 'nome']);
  97.         
  98.         //Abindo de acordo com tipo de pessoa
  99.         $action1 = new TDataGridAction(['ClientesForm''onEdit'], ['id'=>'{id}']);
  100.         
  101.         //$action1 = new TDataGridAction(['ClientesForm', 'onEdit'], ['id'=>'{id}']);
  102.         $action2 = new TDataGridAction([$this'onDelete'], ['id'=>'{id}']);
  103.         
  104.         $this->datagrid->addAction($action1_t('Edit'),   'far:edit blue');
  105.         $this->datagrid->addAction($action2 ,_t('Delete'), 'far:trash-alt red');
  106.         $action_servico = new TDataGridAction(array($this'AlterarCliente'));
  107.         $action_servico->setLabel('Alterar Cliente');
  108.         $action_servico->setImage('fa:donate blue fa-lg');
  109.         $action_servico->setField('id');
  110.         $this->datagrid->addAction($action_servico);
  111.         
  112.         // create the datagrid model
  113.         $this->datagrid->createModel();
  114.         
  115.         // creates the page navigation
  116.         $this->pageNavigation = new TPageNavigation;
  117.         $this->pageNavigation->setAction(new TAction([$this'onReload']));
  118.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  119.         
  120.         // vertical box container
  121.         $container = new TVBox;
  122.         $container->style 'width: 100%';
  123.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  124.         $container->add($this->form);
  125.         $container->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation));
  126.         
  127.         parent::add($container);
  128.     }
  129.     
  130.     /**
  131.      * Inline record editing
  132.      * @param $param Array containing:
  133.      *              key: object ID value
  134.      *              field name: object attribute to be updated
  135.      *              value: new attribute content 
  136.      */
  137.     public function onInlineEdit($param)
  138.     {
  139.         try
  140.         {
  141.             // get the parameter $key
  142.             $field $param['field'];
  143.             $key   $param['key'];
  144.             $value $param['value'];
  145.             
  146.             TTransaction::open('gestoros'); // open a transaction with database
  147.             $object = new Clientes($key); // instantiates the Active Record
  148.             $object->{$field} = $value;
  149.             $object->store(); // update the object in the database
  150.             TTransaction::close(); // close the transaction
  151.             
  152.             $this->onReload($param); // reload the listing
  153.             new TMessage('info'"Record Updated");
  154.         }
  155.         catch (Exception $e// in case of exception
  156.         {
  157.             new TMessage('error'$e->getMessage()); // shows the exception error message
  158.             TTransaction::rollback(); // undo all pending operations
  159.         }
  160.     }
  161.     
  162.     /**
  163.      * Register the filter in the session
  164.      */
  165.     public function onSearch()
  166.     {
  167.         // get the search form data
  168.         $data $this->form->getData();
  169.         
  170.         // clear session filters
  171.         TSession::setValue(__CLASS__.'_filter_id',   NULL);
  172.         TSession::setValue(__CLASS__.'_filter_nome',   NULL);
  173.         TSession::setValue(__CLASS__.'_filter_pessoa_tp_id',   NULL);
  174.         TSession::setValue(__CLASS__.'_filter_cpfcnpj',   NULL);
  175.         TSession::setValue(__CLASS__.'_filter_cidades_id',   NULL);
  176.         TSession::setValue(__CLASS__.'_filter_ativo_id',   NULL);
  177.         if (isset($data->id) AND ($data->id)) {
  178.             $filter = new TFilter('id''='$data->id); // create the filter
  179.             TSession::setValue(__CLASS__.'_filter_id',   $filter); // stores the filter in the session
  180.         }
  181.         if (isset($data->nome) AND ($data->nome)) {
  182.             $filter = new TFilter('nome''like'"%{$data->nome}%"); // create the filter
  183.             TSession::setValue(__CLASS__.'_filter_nome',   $filter); // stores the filter in the session
  184.         }
  185.         if (isset($data->pessoa_tp_id) AND ($data->pessoa_tp_id)) {
  186.             $filter = new TFilter('pessoa_tp_id''='$data->pessoa_tp_id); // create the filter
  187.             TSession::setValue(__CLASS__.'_filter_pessoa_tp_id',   $filter); // stores the filter in the session
  188.         }
  189.         if (isset($data->cpfcnpj) AND ($data->cpfcnpj)) {
  190.             $filter = new TFilter('cpfcnpj''like'"%{$data->cpfcnpj}%"); // create the filter
  191.             TSession::setValue(__CLASS__.'_filter_cpfcnpj',   $filter); // stores the filter in the session
  192.         }
  193.         if (isset($data->cidades_id) AND ($data->cidades_id)) {
  194.             $filter = new TFilter('cidades_id''='$data->cidades_id); // create the filter
  195.             TSession::setValue(__CLASS__.'_filter_cidades_id',   $filter); // stores the filter in the session
  196.         }
  197.         if (isset($data->ativo_id) AND ($data->ativo_id)) {
  198.             $filter = new TFilter('ativo_id''='$data->ativo_id); // create the filter
  199.             TSession::setValue(__CLASS__.'_filter_ativo_id',   $filter); // stores the filter in the session
  200.         }
  201.         
  202.         // fill the form with data again
  203.         $this->form->setData($data);
  204.         
  205.         // keep the search data in the session
  206.         TSession::setValue(__CLASS__ '_filter_data'$data);
  207.         
  208.         $param = array();
  209.         $param['offset']    =0;
  210.         $param['first_page']=1;
  211.         $this->onReload($param);
  212.     }
  213.     
  214.     /**
  215.      * Load the datagrid with data
  216.      */
  217.     public function onReload($param NULL)
  218.     {
  219.         try
  220.         {
  221.             // open a transaction with database 'gestoros'
  222.             TTransaction::open('gestoros');
  223.             
  224.             // creates a repository for Clientes
  225.             $repository = new TRepository('Clientes');
  226.             $limit 10;
  227.             // creates a criteria
  228.             $criteria = new TCriteria;
  229.             
  230.             // default order
  231.             if (empty($param['order']))
  232.             {
  233.                 $param['order'] = 'id';
  234.                 $param['direction'] = 'asc';
  235.             }
  236.             $criteria->setProperties($param); // order, offset
  237.             $criteria->setProperty('limit'$limit);
  238.             //Desabilita o click do datagrid
  239.             $this->datagrid->disableDefaultClick();                        
  240.             if (TSession::getValue(__CLASS__.'_filter_id')) {
  241.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_id')); // add the session filter
  242.             }
  243.             if (TSession::getValue(__CLASS__.'_filter_nome')) {
  244.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_nome')); // add the session filter
  245.             }
  246.             if (TSession::getValue(__CLASS__.'_filter_pessoa_tp_id')) {
  247.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_pessoa_tp_id')); // add the session filter
  248.             }
  249.             if (TSession::getValue(__CLASS__.'_filter_cpfcnpj')) {
  250.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_cpfcnpj')); // add the session filter
  251.             }
  252.             if (TSession::getValue(__CLASS__.'_filter_cidades_id')) {
  253.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_cidades_id')); // add the session filter
  254.             }
  255.             if (TSession::getValue(__CLASS__.'_filter_ativo_id')) {
  256.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_ativo_id')); // add the session filter
  257.             }
  258.             
  259.             // load the objects according to criteria
  260.             $objects $repository->load($criteriaFALSE);
  261.             
  262.             if (is_callable($this->transformCallback))
  263.             {
  264.                 call_user_func($this->transformCallback$objects$param);
  265.             }
  266.             
  267.             $this->datagrid->clear();
  268.             if ($objects)
  269.             {
  270.                 // iterate the collection of active records
  271.                 foreach ($objects as $object)
  272.                 {
  273.                     // add the object inside the datagrid
  274.                     $this->datagrid->addItem($object);
  275.                 }
  276.             }
  277.             
  278.             // reset the criteria for record count
  279.             $criteria->resetProperties();
  280.             $count$repository->count($criteria);
  281.             
  282.             $this->pageNavigation->setCount($count); // count of records
  283.             $this->pageNavigation->setProperties($param); // order, page
  284.             $this->pageNavigation->setLimit($limit); // limit
  285.             
  286.             // close the transaction
  287.             TTransaction::close();
  288.             $this->loaded true;
  289.         }
  290.         catch (Exception $e)
  291.         {
  292.             new TMessage('error'$e->getMessage());
  293.             TTransaction::rollback();
  294.         }
  295.     }
  296.     
  297.     /**
  298.      * Ask before deletion
  299.      */
  300.     public static function onDelete($param)
  301.     {
  302.         // define the delete action
  303.         $action = new TAction([__CLASS__'Delete']);
  304.         $action->setParameters($param); // pass the key parameter ahead
  305.         
  306.         // shows a dialog to the user
  307.         new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  308.     }
  309.     
  310.     /**
  311.      * Delete a record
  312.      */
  313.     public static function Delete($param)
  314.     {
  315.         try
  316.         {
  317.             $key=$param['key']; // get the parameter $key
  318.             TTransaction::open('gestoros'); // open a transaction with database
  319.             $object = new Clientes($keyFALSE); // instantiates the Active Record
  320.             $object->delete(); // deletes the object from the database
  321.             TTransaction::close(); // close the transaction
  322.             
  323.             $pos_action = new TAction([__CLASS__'onReload']);
  324.             new TMessage('info'AdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  325.         }
  326.         catch (Exception $e// in case of exception
  327.         {
  328.             new TMessage('error'$e->getMessage()); // shows the exception error message
  329.             TTransaction::rollback(); // undo all pending operations
  330.         }
  331.     }
  332.     
  333.     /**
  334.      * method show()
  335.      * Shows the page
  336.      */
  337.     public function show()
  338.     {
  339.         // check if the datagrid is already loaded
  340.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload''onSearch')))) )
  341.         {
  342.             if (func_num_args() > 0)
  343.             {
  344.                 $this->onReloadfunc_get_arg(0) );
  345.             }
  346.             else
  347.             {
  348.                 $this->onReload();
  349.             }
  350.         }
  351.         parent::show();
  352.     }
  353.     /**
  354.     * Ação antes da Edição
  355.     */
  356.     public function AlterarCliente($param)
  357.     {
  358.         try
  359.         {
  360.             TTransaction::open('gestoros');
  361.             if (isset($param['key']))
  362.             {
  363.                 $key $param['key'];
  364.                 $cliente = new Clientes($key);
  365.                 if ($cliente->pessoa_tp_id == '2')
  366.                 {
  367.                     //$action_edit = new TAction(array('ClientesForm', 'onEdit'));
  368.                     $action_edit = new TDataGridAction(['ClientesFormPJ''onEdit'], ['id'=>'{id}']);
  369.                 }
  370.                 else
  371.                 {
  372.                     //$action_edit = new TAction(array('ClientesFormPJ', 'onEdit'));
  373.                     $action_edit = new TDataGridAction(['ClientesForm''onEdit'], ['id'=>'{id}']);
  374.                 }
  375.             }
  376.             TTransaction::close(); // close the transaction
  377.         }
  378.             catch (exception $e)
  379.             {
  380.             new TMessage('error'$e->getMessage());
  381.             }
  382.     }
  383.     
  384. }
  385. ?>


Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (4)


PS

Minha chamada:

  1. <?php
  2.     $action_servico = new TDataGridAction(array($this'AlterarCliente'));
  3.         $action_servico->setLabel('Alterar Cliente');
  4.         $action_servico->setImage('fa:donate blue fa-lg');
  5.         $action_servico->setField('id');
  6.         $this->datagrid->addAction($action_servico);
  7. ?>


Minha função:

  1. <?php
  2.     public function AlterarCliente($param)
  3.     {
  4.         try
  5.         {
  6.             TTransaction::open('gestoros');
  7.             if (isset($param['key']))
  8.             {
  9.                 $key $param['key'];
  10.                 $cliente = new Clientes($key);
  11.                 if ($cliente->pessoa_tp_id == '2')
  12.                 {
  13.                     $action_edit = new TDataGridAction(['ClientesFormPJ''onEdit'], ['id'=>'{id}']);
  14.                 }
  15.                 else
  16.                 {
  17.                     $action_edit = new TDataGridAction(['ClientesForm''onEdit'], ['id'=>'{id}']);
  18.                 }
  19.             }
  20.             TTransaction::close(); // close the transaction
  21.         }
  22.             catch (exception $e)
  23.             {
  24.             new TMessage('error'$e->getMessage());
  25.             }
  26.     }
  27. ?>

PS

Pessoal, ajuda urgente.
Alguém pode dar uma força ?
NR

  1. <?php
  2. if ($cliente->pessoa_tp_id == '2')
  3. {
  4.      //$action_edit = new TDataGridAction(['ClientesFormPJ', 'onEdit'], ['id'=>'{id}']);
  5.      TApplication::loadPage('ClientesFormPJ''onEdit', ['id'=>$key]);
  6. }
  7. else
  8. {
  9.      //$action_edit = new TDataGridAction(['ClientesForm', 'onEdit'], ['id'=>'{id}']);
  10.      TApplication::loadPage('ClientesForm''onEdit', ['id'=>$key]);
  11. }
  12. ?>
PS

Nataniel Rabaioli, parabéns e muito obrigado, ficou show.
Irei compartilhar meu código aqui, caso mais algém tenha essa dúvida.

  1. <?php
  2. /**
  3.  * ClientesLista Listing
  4.  * @author  <your name here>
  5.  */
  6. class ClientesLista extends TPage
  7. {
  8.     private $form// form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $formgrid;
  12.     private $loaded;
  13.     private $deleteButton;
  14.     
  15.     /**
  16.      * Class constructor
  17.      * Creates the page, the form and the listing
  18.      */
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.         
  23.         // creates the form
  24.         $this->form = new BootstrapFormBuilder('form_search_Clientes');
  25.         $this->form->setFormTitle('Clientes');        
  26.         // create the form fields
  27.         $id             = new TEntry('id');        
  28.         $nome             = new TEntry('nome');
  29.         $pessoa_tp_id     = new TDBCombo('pessoa_tp_id''gestoros''PessoaTp''id''nome');
  30.         $cpfcnpj         = new TEntry('cpfcnpj');
  31.         $criteria         = new TCriteria;
  32.         $ativo             = new THidden('ativo');
  33.         $ativo             '1';
  34.         $criteria->add(new TFilter('ativo_id''='$ativo));
  35.         //$cidades_id     = new TDBUniqueSearch('cidades_id', 'gestoros', 'Cidades', 'id', 'nome', 'nome');
  36.         $cidades_id     = new TDBCombo('cidades_id''gestoros''Cidades''id''nome''nome'$criteria);                
  37.         //$cidades_id->setValue('TODAS');
  38.         $ativo_id         = new TDBCombo('ativo_id''gestoros''Ativo''id''nome');
  39.         
  40.         $nome->style "text-transform: uppercase";
  41.         
  42.         // add the fields
  43.         $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  44.         $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
  45.         $this->form->addFields( [ new TLabel('Pessoa') ], [ $pessoa_tp_id ] );
  46.         $this->form->addFields( [ new TLabel('CPF/CNPJ') ], [ $cpfcnpj ] );
  47.         $this->form->addFields( [ new TLabel('Cidade') ], [ $cidades_id ] );
  48.         $this->form->addFields( [ new TLabel('Ativo') ], [ $ativo_id ] );
  49.         // set sizes
  50.         $id->setSize('100%');
  51.         $nome->setSize('100%');
  52.         $pessoa_tp_id->setSize('100%');
  53.         $cpfcnpj->setSize('100%');
  54.         $cidades_id->setSize('100%');
  55.         $ativo_id->setSize('100%');
  56.         
  57.         // keep the form filled during navigation with session data
  58.         $this->form->setDataTSession::getValue(__CLASS__ '_filter_data') );
  59.         
  60.         // add the search form actions
  61.         $btn $this->form->addAction(_t('Find'), new TAction([$this'onSearch']), 'fa:search');
  62.         $btn->class 'btn btn-sm btn-primary';
  63.         $this->form->addActionLink(_t('New'), new TAction(['ClientesForm''onEdit']), 'fa:plus green');
  64.         
  65.         // creates a Datagrid
  66.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  67.         $this->datagrid->style 'width: 100%';
  68.         $this->datagrid->datatable 'true';
  69.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');        
  70.         $this->datagrid->enablePopover('Clique para alterar''Cliente: <b> {id} </b>');
  71.         // creates the datagrid columns
  72.         $column_id              = new TDataGridColumn('id''Id''right'10);
  73.         $column_nome          = new TDataGridColumn('nome''Nome''left');
  74.         $column_pessoa_tp_id = new TDataGridColumn('pessoa_tp_id''Pessoa''left');
  75.         $column_cpfcnpj      = new TDataGridColumn('cpfcnpj''CPF/CNPJ''left');
  76.         $column_cidades_id      = new TDataGridColumn('cidades->nome''Cidade''right');
  77.         $column_ativo_id      = new TDataGridColumn('ativo_id''Ativo''right');
  78.         // add the columns to the DataGrid
  79.         $this->datagrid->addColumn($column_id);
  80.         $this->datagrid->addColumn($column_nome);
  81.         $this->datagrid->addColumn($column_pessoa_tp_id);
  82.         $this->datagrid->addColumn($column_cpfcnpj);
  83.         $this->datagrid->addColumn($column_cidades_id);
  84.         $this->datagrid->addColumn($column_ativo_id);
  85.         $column_ativo_id->setTransformer( function($value$object$row) {
  86.             $class = ($value=='2') ? 'danger' 'success';
  87.             $label = ($value=='2') ? _t('No') : _t('Yes');
  88.             $div = new TElement('span');
  89.             $div->class="label label-{$class}";
  90.             $div->style="text-shadow:none; font-size:12px; font-weight:lighter";
  91.             $div->add($label);
  92.             return $div;
  93.         });
  94.         // creates the datagrid column actions
  95.         $column_id->setAction(new TAction([$this'onReload']), ['order' => 'id']);
  96.         $column_nome->setAction(new TAction([$this'onReload']), ['order' => 'nome']);
  97.         
  98.         //Abindo de acordo com tipo de pessoa
  99.         if ($pessoa_tp_id == '1')
  100.         {
  101.             $action1 = new TDataGridAction(['ClientesFormPJ''onEdit'], ['id'=>'{id}']);
  102.         } else {
  103.             $action1 = new TDataGridAction(['ClientesForm''onEdit'], ['id'=>'{id}']);
  104.         }
  105.         
  106.         //$action1 = new TDataGridAction(['ClientesForm', 'onEdit'], ['id'=>'{id}']);
  107.         $action2 = new TDataGridAction([$this'onDelete'], ['id'=>'{id}']);
  108.         
  109.         //$action1 = new TDataGridAction(['ClientesForm', 'onEdit'], ['id'=>'{id}']);
  110.         $this->datagrid->addAction($action1_t('Edit'),   'far:edit blue');
  111.         $this->datagrid->addAction($action2 ,_t('Delete'), 'far:trash-alt red');
  112.         
  113.         //Altera o Cliente conforme tipo de pessoa 
  114.         //$action_servico = new TDataGridAction(['ClientesForm', 'onEdit']);        
  115.         $action_servico = new TDataGridAction(array($this'AlterarCliente'));
  116.         $action_servico->setLabel('Alterar Cliente');
  117.         $action_servico->setImage('fa:donate blue fa-lg');
  118.         $action_servico->setField('id');
  119.         $this->datagrid->addAction($action_servico);
  120.         
  121.         // create the datagrid model
  122.         $this->datagrid->createModel();
  123.         
  124.         // creates the page navigation
  125.         $this->pageNavigation = new TPageNavigation;
  126.         $this->pageNavigation->setAction(new TAction([$this'onReload']));
  127.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  128.         
  129.         // vertical box container
  130.         $container = new TVBox;
  131.         $container->style 'width: 100%';
  132.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  133.         $container->add($this->form);
  134.         $container->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation));
  135.         
  136.         parent::add($container);
  137.     }
  138.     
  139.     /**
  140.      * Inline record editing
  141.      * @param $param Array containing:
  142.      *              key: object ID value
  143.      *              field name: object attribute to be updated
  144.      *              value: new attribute content 
  145.      */
  146.     public function onInlineEdit($param)
  147.     {
  148.         try
  149.         {
  150.             // get the parameter $key
  151.             $field $param['field'];
  152.             $key   $param['key'];
  153.             $value $param['value'];
  154.             
  155.             TTransaction::open('gestoros'); // open a transaction with database
  156.             $object = new Clientes($key); // instantiates the Active Record
  157.             $object->{$field} = $value;
  158.             $object->store(); // update the object in the database
  159.             TTransaction::close(); // close the transaction
  160.             
  161.             $this->onReload($param); // reload the listing
  162.             new TMessage('info'"Record Updated");
  163.         }
  164.         catch (Exception $e// in case of exception
  165.         {
  166.             new TMessage('error'$e->getMessage()); // shows the exception error message
  167.             TTransaction::rollback(); // undo all pending operations
  168.         }
  169.     }
  170.     
  171.     /**
  172.      * Register the filter in the session
  173.      */
  174.     public function onSearch()
  175.     {
  176.         // get the search form data
  177.         $data $this->form->getData();
  178.         
  179.         // clear session filters
  180.         TSession::setValue(__CLASS__.'_filter_id',   NULL);
  181.         TSession::setValue(__CLASS__.'_filter_nome',   NULL);
  182.         TSession::setValue(__CLASS__.'_filter_pessoa_tp_id',   NULL);
  183.         TSession::setValue(__CLASS__.'_filter_cpfcnpj',   NULL);
  184.         TSession::setValue(__CLASS__.'_filter_cidades_id',   NULL);
  185.         TSession::setValue(__CLASS__.'_filter_ativo_id',   NULL);
  186.         if (isset($data->id) AND ($data->id)) {
  187.             $filter = new TFilter('id''='$data->id); // create the filter
  188.             TSession::setValue(__CLASS__.'_filter_id',   $filter); // stores the filter in the session
  189.         }
  190.         if (isset($data->nome) AND ($data->nome)) {
  191.             $filter = new TFilter('nome''like'"%{$data->nome}%"); // create the filter
  192.             TSession::setValue(__CLASS__.'_filter_nome',   $filter); // stores the filter in the session
  193.         }
  194.         if (isset($data->pessoa_tp_id) AND ($data->pessoa_tp_id)) {
  195.             $filter = new TFilter('pessoa_tp_id''='$data->pessoa_tp_id); // create the filter
  196.             TSession::setValue(__CLASS__.'_filter_pessoa_tp_id',   $filter); // stores the filter in the session
  197.         }
  198.         if (isset($data->cpfcnpj) AND ($data->cpfcnpj)) {
  199.             $filter = new TFilter('cpfcnpj''like'"%{$data->cpfcnpj}%"); // create the filter
  200.             TSession::setValue(__CLASS__.'_filter_cpfcnpj',   $filter); // stores the filter in the session
  201.         }
  202.         if (isset($data->cidades_id) AND ($data->cidades_id)) {
  203.             $filter = new TFilter('cidades_id''='$data->cidades_id); // create the filter
  204.             TSession::setValue(__CLASS__.'_filter_cidades_id',   $filter); // stores the filter in the session
  205.         }
  206.         if (isset($data->ativo_id) AND ($data->ativo_id)) {
  207.             $filter = new TFilter('ativo_id''='$data->ativo_id); // create the filter
  208.             TSession::setValue(__CLASS__.'_filter_ativo_id',   $filter); // stores the filter in the session
  209.         }
  210.         
  211.         // fill the form with data again
  212.         $this->form->setData($data);
  213.         
  214.         // keep the search data in the session
  215.         TSession::setValue(__CLASS__ '_filter_data'$data);
  216.         
  217.         $param = array();
  218.         $param['offset']    =0;
  219.         $param['first_page']=1;
  220.         $this->onReload($param);
  221.     }
  222.     
  223.     /**
  224.      * Load the datagrid with data
  225.      */
  226.     public function onReload($param NULL)
  227.     {
  228.         try
  229.         {
  230.             // open a transaction with database 'gestoros'
  231.             TTransaction::open('gestoros');
  232.             
  233.             // creates a repository for Clientes
  234.             $repository = new TRepository('Clientes');
  235.             $limit 10;
  236.             // creates a criteria
  237.             $criteria = new TCriteria;
  238.             
  239.             // default order
  240.             if (empty($param['order']))
  241.             {
  242.                 $param['order'] = 'id';
  243.                 $param['direction'] = 'asc';
  244.             }
  245.             $criteria->setProperties($param); // order, offset
  246.             $criteria->setProperty('limit'$limit);
  247.             //Desabilita o click do datagrid
  248.             $this->datagrid->disableDefaultClick();                        
  249.             if (TSession::getValue(__CLASS__.'_filter_id')) {
  250.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_id')); // add the session filter
  251.             }
  252.             if (TSession::getValue(__CLASS__.'_filter_nome')) {
  253.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_nome')); // add the session filter
  254.             }
  255.             if (TSession::getValue(__CLASS__.'_filter_pessoa_tp_id')) {
  256.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_pessoa_tp_id')); // add the session filter
  257.             }
  258.             if (TSession::getValue(__CLASS__.'_filter_cpfcnpj')) {
  259.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_cpfcnpj')); // add the session filter
  260.             }
  261.             if (TSession::getValue(__CLASS__.'_filter_cidades_id')) {
  262.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_cidades_id')); // add the session filter
  263.             }
  264.             if (TSession::getValue(__CLASS__.'_filter_ativo_id')) {
  265.                 $criteria->add(TSession::getValue(__CLASS__.'_filter_ativo_id')); // add the session filter
  266.             }
  267.             
  268.             // load the objects according to criteria
  269.             $objects $repository->load($criteriaFALSE);
  270.             
  271.             if (is_callable($this->transformCallback))
  272.             {
  273.                 call_user_func($this->transformCallback$objects$param);
  274.             }
  275.             
  276.             $this->datagrid->clear();
  277.             if ($objects)
  278.             {
  279.                 // iterate the collection of active records
  280.                 foreach ($objects as $object)
  281.                 {
  282.                     // add the object inside the datagrid
  283.                     $this->datagrid->addItem($object);
  284.                 }
  285.             }
  286.             
  287.             // reset the criteria for record count
  288.             $criteria->resetProperties();
  289.             $count$repository->count($criteria);
  290.             
  291.             $this->pageNavigation->setCount($count); // count of records
  292.             $this->pageNavigation->setProperties($param); // order, page
  293.             $this->pageNavigation->setLimit($limit); // limit
  294.             
  295.             // close the transaction
  296.             TTransaction::close();
  297.             $this->loaded true;
  298.         }
  299.         catch (Exception $e)
  300.         {
  301.             new TMessage('error'$e->getMessage());
  302.             TTransaction::rollback();
  303.         }
  304.     }
  305.     
  306.     /**
  307.      * Ask before deletion
  308.      */
  309.     public static function onDelete($param)
  310.     {
  311.         // define the delete action
  312.         $action = new TAction([__CLASS__'Delete']);
  313.         $action->setParameters($param); // pass the key parameter ahead
  314.         
  315.         // shows a dialog to the user
  316.         new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  317.     }
  318.     
  319.     /**
  320.      * Delete a record
  321.      */
  322.     public static function Delete($param)
  323.     {
  324.         try
  325.         {
  326.             $key=$param['key']; // get the parameter $key
  327.             TTransaction::open('gestoros'); // open a transaction with database
  328.             $object = new Clientes($keyFALSE); // instantiates the Active Record
  329.             $object->delete(); // deletes the object from the database
  330.             TTransaction::close(); // close the transaction
  331.             
  332.             $pos_action = new TAction([__CLASS__'onReload']);
  333.             new TMessage('info'AdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  334.         }
  335.         catch (Exception $e// in case of exception
  336.         {
  337.             new TMessage('error'$e->getMessage()); // shows the exception error message
  338.             TTransaction::rollback(); // undo all pending operations
  339.         }
  340.     }
  341.     
  342.     /**
  343.      * method show()
  344.      * Shows the page
  345.      */
  346.     public function show()
  347.     {
  348.         // check if the datagrid is already loaded
  349.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload''onSearch')))) )
  350.         {
  351.             if (func_num_args() > 0)
  352.             {
  353.                 $this->onReloadfunc_get_arg(0) );
  354.             }
  355.             else
  356.             {
  357.                 $this->onReload();
  358.             }
  359.         }
  360.         parent::show();
  361.     }
  362.     /**
  363.     * Ação antes da Edição
  364.     */
  365.     public function AlterarCliente($param)
  366.     {
  367.         try
  368.         {
  369.             TTransaction::open('gestoros');
  370.             if (isset($param['key']))
  371.             {
  372.                 $key $param['key'];
  373.                 $cliente = new Clientes($key);
  374.                 if ($cliente->pessoa_tp_id == '2')
  375.                 {
  376.                     //TApplication::loadPage( 'ClientesFormPJ' ,  'onEdit' , [ 'key' => $key ]);
  377.                     AdiantiCoreApplication::loadPage'ClientesFormPJ' ,  'onEdit' , [ 'key' => $key ]);
  378.                 }
  379.                 else
  380.                 {
  381.                     TApplication::loadPage'ClientesForm' ,  'onEdit' , [ 'key' => $key ]);
  382.                 }
  383.             }
  384.             TTransaction::close(); // close the transaction
  385.         }
  386.             catch (exception $e)
  387.             {
  388.             new TMessage('error'$e->getMessage());
  389.             }
  390.     }
  391.     
  392. }
  393. ?>

</your>