Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Trocar Button ao usar onReload? Olá pessoal, tenho dois botões: Pago e Emitir Recibo. Minha dúvida é, como passo em tempo de execução através do status "S" ou "N" exibir o botão de Pago ou de Emitir Recibo?...
IV
Trocar Button ao usar onReload?  
Olá pessoal, tenho dois botões: Pago e Emitir Recibo.
Minha dúvida é, como passo em tempo de execução através do status "S" ou "N" exibir o botão de Pago ou de Emitir Recibo?

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 (9)


MG

Guarde o status numa TSession, não ajuda?
MG

Um exemplo:

  1. <?php
  2.     $pago TSession::getValue('<nome_form>_pago'); // entende-se que no onEdit ou onSave vc tenha guardando este valor
  3.     
  4.     $btn = new TButton('stt');
  5.     if ($pago) {
  6.         $btn->setValue('Pago');
  7.         $action1 = new TAction(array($this,'onPago'));
  8.         $btn->setAction($action1);
  9.     } else {
  10.         $btn->setValue('Emitir Recibo');
  11.         $action1 = new TAction(array($this,'onEmitirRecibo'));
  12.         $btn->setAction($action1);
  13.     }
  14. ?>
IV

Marcelo, quero implementar em um TDataGridAction.
Tentei aplicar sua dica no onReload mas não tive sucesso, ele esta mudando todos e não linha a linha.
MG

Iran
Posta o código para podermos verificar.
IV

Tentei usar o TSession::getValue e TSession::setValue mas ele só ler o primeiro registro e apresentar um botão para todoss.
Coloquei o código original.

  1. <?php
  2. class DiariaList extends TPage
  3. {
  4.     private $form// form
  5.     private $datagrid// listing
  6.     private $pageNavigation;
  7.     private $formgrid;
  8.     private $loaded;
  9.     private $deleteButton;
  10.     
  11.     /**
  12.      * Class constructor
  13.      * Creates the page, the form and the listing
  14.      */
  15.     public function __construct()
  16.     {
  17.         parent::__construct();
  18.         . . .       
  19.         // creates the datagrid columns
  20.         $column_favorecido_id = new TDataGridColumn('favorecido_id''Favorecido''left');
  21.         $column_dataDiaria = new TDataGridColumn('dataDiaria''Data Diária''left');
  22.         $column_objetivo = new TDataGridColumn('objetivo''Objetivo''left');
  23.         $column_origem = new TDataGridColumn('origem''Origem''left');
  24.         $column_destino = new TDataGridColumn('destino''Destino''left');
  25.         $column_dataInicial = new TDataGridColumn('dataInicial''Data Inicial''left');
  26.         $column_dataFinal = new TDataGridColumn('dataFinal''Data Final''left');
  27.         $column_autorizado = new TDataGridColumn('autorizado''Autorizado''center');
  28.         // add the columns to the DataGrid
  29.         $this->datagrid->addColumn($column_favorecido_id);
  30.         $this->datagrid->addColumn($column_dataDiaria);
  31.         //$this->datagrid->addColumn($column_objetivo);
  32.         $this->datagrid->addColumn($column_origem);
  33.         $this->datagrid->addColumn($column_destino);
  34.         $this->datagrid->addColumn($column_dataInicial);
  35.         $this->datagrid->addColumn($column_dataFinal);
  36.         $this->datagrid->addColumn($column_autorizado);
  37.         $column_autorizado->setTransformer( function($value$object$row
  38.         {
  39.             $class = ($value=='N') ? 'danger' 'success';
  40.             $label = ($value=='N') ? _t('No') : _t('Yes');
  41.             $div = new TElement('span');
  42.             $div->class="label label-{$class}";
  43.             $div->style="text-shadow:none; font-size:12px; font-weight:lighter";
  44.             $div->add($label);
  45.             return $div;
  46.         });
  47.         
  48.        
  49.         // create EDIT action
  50.         $action_edit = new TDataGridAction(array('DiariaForm''onEdit'));
  51.         $action_edit->setButtonClass('btn btn-default');
  52.         $action_edit->setLabel(_t('Edit'));
  53.         $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  54.         $action_edit->setField('id');
  55.         $this->datagrid->addAction($action_edit);
  56.         
  57.         // create DELETE action
  58.         $action_del = new TDataGridAction(array($this'onDelete'));
  59.         $action_del->setButtonClass('btn btn-default');
  60.         $action_del->setLabel(_t('Delete'));
  61.         $action_del->setImage('fa:trash-o red fa-lg');
  62.         $action_del->setField('id');
  63.         $this->datagrid->addAction($action_del);
  64.                                
  65.         /************************************************************************************
  66.        * A partir deste ponto quero apresentar ou o botão de Pagar ou Emitir Recibo
  67.         ************************************************************************************/
  68.         // create INSERTREL action  
  69.         $action_Rel = new TDataGridAction(array($this'onInsertRel'));
  70.         $action_Rel->setButtonClass('btn btn-default');
  71.         $action_Rel->setLabel('Pagar');
  72.         $action_Rel->setImage('fa:thumbs-o-up green fa-lg');
  73.         $action_Rel->setField('id');
  74.         $this->datagrid->addAction($action_Rel);
  75.  
  76.         // create GENERATE action
  77.         $action_Gen = new TDataGridAction(array($this'onGenerate'));
  78.         $action_Gen->setButtonClass('btn btn-default');
  79.         $action_Gen->setLabel('Emitir Recibo');
  80.         $action_Gen->setImage('fa:print purple fa-lg');
  81.         $action_Gen->setField('id');
  82.         $this->datagrid->addAction($action_Gen);
  83.         
  84.         
  85.         // create the datagrid model
  86.         $this->datagrid->createModel();
  87.           . . .
  88.     }
  89.     
  90.     
  91.     /**
  92.      * Load the datagrid with data
  93.      */
  94.     public function onReload($param NULL)
  95.     {
  96.         try
  97.         {
  98.             // open a transaction with database 'empresa'
  99.             TTransaction::open('empresa');
  100.             
  101.             // creates a repository for Diaria
  102.             $repository = new TRepository('Diaria');
  103.             $limit 10;
  104.             // creates a criteria
  105.             $criteria = new TCriteria;
  106.             
  107.             // default order
  108.             if (empty($param['order']))
  109.             {
  110.                 $param['order'] = 'id';
  111.                 $param['direction'] = 'asc';
  112.             }
  113.             $criteria->setProperties($param); // order, offset
  114.             $criteria->setProperty('limit'$limit);
  115.            
  116.             if (TSession::getValue('DiariaList_filter_favorecido_id')) {
  117.                 $criteria->add(TSession::getValue('DiariaList_filter_favorecido_id')); // add the session filter
  118.             }
  119.             if (TSession::getValue('DiariaList_filter_dataDiaria')) {
  120.                 $criteria->add(TSession::getValue('DiariaList_filter_dataDiaria')); // add the session filter
  121.             }
  122.             if (TSession::getValue('DiariaList_filter_origem')) {
  123.                 $criteria->add(TSession::getValue('DiariaList_filter_origem')); // add the session filter
  124.             }
  125.             if (TSession::getValue('DiariaList_filter_destino')) {
  126.                 $criteria->add(TSession::getValue('DiariaList_filter_destino')); // add the session filter
  127.             }
  128.             if (TSession::getValue('DiariaList_filter_autorizado')) {
  129.                 $criteria->add(TSession::getValue('DiariaList_filter_autorizado')); // add the session filter
  130.             }
  131.             
  132.             // load the objects according to criteria
  133.             $objects $repository->load($criteriaFALSE);
  134.             
  135.             if (is_callable($this->transformCallback))
  136.             {
  137.                 call_user_func($this->transformCallback$objects$param);
  138.             }
  139.             
  140.             $this->datagrid->clear();
  141.             if ($objects)
  142.             {
  143.                 // iterate the collection of active records
  144.                 foreach ($objects as $object)
  145.                 {
  146.                     // add the object inside the datagrid
  147.                     $this->datagrid->addItem($object);                    
  148.                 }
  149.             }
  150.             
  151.             // reset the criteria for record count
  152.             $criteria->resetProperties();
  153.             $count$repository->count($criteria);
  154.             
  155.             $this->pageNavigation->setCount($count); // count of records
  156.             $this->pageNavigation->setProperties($param); // order, page
  157.             $this->pageNavigation->setLimit($limit); // limit
  158.             
  159.             // close the transaction
  160.             TTransaction::close();
  161.             $this->loaded true;
  162.         }
  163.         catch (Exception $e// in case of exception
  164.         {
  165.             // shows the exception error message
  166.             new TMessage('error'$e->getMessage());
  167.             // undo all pending operations
  168.             TTransaction::rollback();
  169.         }
  170.     }
  171.     
  172. }
  173. ?>
MG

Iran

Vc carrega o form a partir de um onEdit, correto?
Neste onEdit, você seta a session com o status que você quer e na hora de adicionar a action no datagrid você recupera o valor e valida se adiciona ou não.
Veja no exemplo do onReload, se existe filtros pré armazenado na session ele usa e add no criteria.
O princípio é o mesmo.
FC

segue esse exemplo

www.adianti.com.br/framework_files/tutor/index.php?class=DatagridCon
IV

A resposta de Felipe resolveu de forma provisória, mas Marcelo ainda não entendi a logica de como carregar os componentes a partir de:
  1. <?php
  2.             $this->datagrid->clear();
  3.             if ($objects)
  4.             {
  5.                 // iterate the collection of active records
  6.                 foreach ($objects as $object)
  7.                 {
  8.                     // add the object inside the datagrid
  9.                     $this->datagrid->addItem($object);
  10.                 }
  11.             }
  12. ?>


Quero em uma coluna só, mostrar o um botão "Pago" ou botão "Emitir" . Já tentei de varias formas criar os botões a partir do $this->datagrid->addItem($object); mas sem sucesso.
MG

Iran

Veja, os botões não são carregados pelo foreach, somente os objetos (linhas) são carregadas da forma mencionada.

Utilize o exemplo do Felipe que "conditions" que dará certo!


www.adianti.com.br/framework_files/tutor/index.php?class=DatagridCon