Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TCheckButton -> Você já adicionou um campo chamado... ...
AR
TCheckButton -> Você já adicionou um campo chamado...  
Fechado
  1. <?php
  2. /**
  3.  * DatagridQuickView
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12.  
  13. class SaleListTStatusC extends TPage
  14. {
  15.     private $form;
  16.     private $datagrid;
  17.     private $pageNavigation;
  18.     private $loaded;
  19.     
  20.     public function __construct()
  21.     {
  22.         parent::__construct();
  23.         
  24.         $this->form = new TForm;
  25.         
  26.         // creates one datagrid
  27.         $this->datagrid = new TQuickGrid;
  28.         $this->datagrid->disableDefaultClick(); // important!
  29.         
  30.         $this->form->add($this->datagrid);
  31.         
  32.         $this->datagrid->addQuickColumn('Check''check''left'40) ;
  33.         $this->datagrid->addQuickColumn('Id''id''left'40) ;
  34.         $this->datagrid->addQuickColumn('Distribuidor''usuariocliente_nome''left'300) ;
  35.        // $this->datagrid->addQuickColumn(_t('Status'), 'status' , 'left', 100);
  36.         $status=$this->datagrid->addQuickColumn(_t('Status'), 'status' 'left'100);
  37.         //$this->datagrid->addQuickColumn('Data', 'date', 'left', 80); 
  38.         $date=$this->datagrid->addQuickColumn('Data''date''left'80); 
  39.        // $this->datagrid->addQuickColumn('Valor', 'total', 'left', 80);
  40.         $total=$this->datagrid->addQuickColumn('Valor''total''left'80);
  41.         
  42.        
  43.         
  44.         // creates the datagrid model
  45.         $this->datagrid->createModel();
  46.         
  47.         
  48.         $total->setTransformer(array($this'formatMonetario'));
  49.         $date->setTransformer(array($this'formatDate'));
  50.         $status->setTransformer( array($this'setStatusColor') );
  51.         
  52.         
  53.         // creates the action button
  54.         $button1=new TButton('action1');
  55.         // define the button action
  56.         $button1->setAction(new TAction(array($this'onLibera')), 'Libera Pedido');
  57.         $button1->setImage('fa:arrow-circle-right blue');
  58.         $button1->popover 'true'
  59.         $button1->poptitle 'Ajuda'
  60.         $button1->popcontent 'Libera pedido(s) para podermos processalos.'
  61.         
  62.           // creates the page navigation
  63.         $this->pageNavigation = new TPageNavigation;
  64.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  65.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  66.         
  67.         
  68.         
  69.         $this->form->addField($button1);
  70.         
  71.         // wrap the page content using vertical box
  72.         $vbox = new TVBox;
  73.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  74.         $vbox->add($this->form);
  75.         $vbox->add($button1);
  76.         parent::add($vbox);
  77.     }
  78.     
  79.     
  80.     
  81.        public function setStatusColor($status$object$row)
  82.         {
  83.         $color $object->status_color;
  84.         if ($color)
  85.         {
  86.             return "<span style='color:$color'>" $status '</span>';
  87.         }
  88.         else
  89.         {
  90.             return $status;
  91.         }
  92.     }
  93.  
  94.  
  95.  
  96.   public function formatDate($datalanc$object)
  97.     {
  98.       //  print_r($datalanc);
  99.     //    $date = new DateTime($object->$datalanc);
  100.         $date = new DateTime($datalanc);
  101.         return $date->format('d/m/Y');
  102.     }
  103.  
  104.  
  105.    /**
  106.      * Format Monetários
  107.      */
  108.     public function formatMonetario($valor_mon$object$row)
  109.     {
  110.         $number number_format($valor_mon2',''.');
  111.             return "<span style='color:blue'>$number</span>";
  112.     }
  113.  
  114.     /**
  115.      * Format Monetários
  116.      */
  117.     public function formatPercentual($valor_perc$object$row)
  118.     {
  119.         $number number_format($valor_perc3',''.');
  120.            return "<span style='color:blue'>$number</span>";
  121.     }
  122.     
  123.     
  124.     
  125.     /**
  126.      * Load the data into the datagrid
  127.      */
  128.     function onReload()
  129.     {
  130.         
  131.       $objeto $this->form->getData(); // optional parameter: active record class
  132.         
  133.         // put the data back to the form
  134.         $this->form->setData($objeto);
  135.  
  136.         try
  137.         {
  138.             // open a transaction with database 'samples'
  139.         //    TTransaction::open('catalogo');
  140.             
  141.             
  142.             
  143.       //----------------------------------------------------------
  144.         TTransaction::open('catalogo');
  145.         
  146.        //     TTransaction::setLogger(new TLoggerSTD); // standard output
  147.        //     TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  148.         
  149.         
  150.         
  151.            $user_id='';
  152.            $user_name ='';
  153.            
  154.            $user SystemUser::newFromLogin(TSession::getValue('login') );
  155.              if ($user)
  156.                {
  157.                 $user_id   $user->id;
  158.                 $user_name $user->name;
  159.                }
  160.                 
  161.            TTransaction::close();      
  162.           
  163.      //-------------------------------------------------------------   
  164.            TTransaction::open('catalogo');
  165.      
  166.      
  167.      
  168.              // get the search form data
  169.             
  170.             
  171.             // creates a repository for Contrato
  172.             $repository = new TRepository('Sale');
  173.             $limit 10;
  174.             
  175.             // creates a criteria
  176.             $criteria = new TCriteria;
  177.             
  178.             // default order
  179.             if (empty($param['order']))
  180.             {
  181.                 $param['order'] = 'id';
  182.                 $param['direction'] = 'asc';
  183.             }
  184.           
  185.             
  186.             $criteria->add(new TFilter('system_user_id''='$objeto->id $user_id),TExpression::AND_OPERATOR);
  187.             $criteria->add(new TFilter('id_status''=','1'));
  188.             $criteria->setProperties($param); // order, offset
  189.             $criteria->setProperty('limit'$limit);
  190.             
  191.              
  192.             // load the objects according to criteria
  193.             $objects $repository->load($criteriaFALSE);
  194.  
  195.            // print_r($objects);
  196.  
  197.            // $objects = $repository->load($criteria, FALSE);
  198.           
  199.           
  200.           
  201.          $this->datagrid->clear();
  202.             
  203.          if ($objects)    
  204.          { 
  205.             
  206.            foreach ($objects as $object)
  207.            {
  208.             $object->check = new TCheckButton('check_'.$object->id);
  209.             $object->check->setIndexValue('on');
  210.             
  211.             $this->form->addField($object->check); // important!
  212.             
  213.             $this->datagrid->addItem($object);
  214.            }
  215.           }
  216.             // reset the criteria for record count
  217.             $criteria->resetProperties();
  218.             $count$repository->count($criteria);
  219.             
  220.            
  221.             $this->pageNavigation->setCount($count); // count of records
  222.             $this->pageNavigation->setProperties($param); // order, page
  223.             $this->pageNavigation->setLimit($limit); // limit
  224.            
  225.             
  226.             
  227.             // close the transaction
  228.             TTransaction::close();
  229.             $this->loaded true;
  230.         }
  231.         catch (Exception $e// in case of exception
  232.         {
  233.             // shows the exception error message
  234.             new TMessage('error'$e->getMessage());
  235.             // undo all pending operations
  236.             TTransaction::rollback();
  237.         }
  238.         
  239.     }
  240.     
  241.     /**
  242.      * Simulates an save button
  243.      * Show the form content
  244.      */
  245.     public function onLibera($param)
  246.     {
  247.         $data $this->form->getData(); // optional parameter: active record class
  248.         
  249.         // put the data back to the form
  250.         $this->form->setData($data);
  251.        // print_r($data);
  252.         try
  253.         {
  254.         
  255.           TTransaction::open('catalogo');
  256.           
  257.            foreach ($this->form->getFields() as $name => $field)
  258.              {
  259.             
  260.             if ($field instanceof TCheckButton)
  261.             {
  262.                 $parts explode('_'$name);
  263.                 2495 $parts[1];
  264.                //  print_r($parts);
  265.                 
  266.                 if ($field->getValue() == 'on')
  267.                 {
  268.                 
  269.                    $obj_pedidos = new Sale(2495);
  270.                    $obj_pedidos->id_status '9';
  271.                    $obj_pedidos->store(); // stores th
  272.                   //   print_r('opa');
  273.                        new TMessage('info''Pedido(s) liberado(s) para processamento');
  274.                 }
  275.               
  276.                }
  277.            }
  278.            
  279.             TTransaction::close(); 
  280.         
  281.       
  282.         }
  283.          catch (Exception $e)
  284.         {
  285.             // show the message
  286.             new TMessage('error'$e->getMessage());
  287.         }
  288.         
  289.         
  290.         $this->datagrid->clear();
  291.         $param=array();
  292.         $param['offset']    =0;
  293.         $param['first_page']=1;
  294.         $this->onReload($param); 
  295.  
  296.         
  297.     }
  298.     
  299.     /**
  300.      * shows the page
  301.      */
  302.     function show()
  303.     {
  304.         $this->onReload();
  305.         parent::show();
  306.     }
  307. }
  308. Pessoalestou com um problema nessa "TQuickGrid" com o campo checkquase tudo está funcionando perfeitamenteconsigo selecionargravo o que quero no bancomas quando vou remontar a tela"Linha 305 " recebo essa mensagemVocê já adicionou um campo chamado "check_8" ao formuláriocomo mostra a imagem em anexoMas se não uso $this->onReload($param);"  a grid não é refeita.   Podem me ajudar por favor Grato.

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


NR

Adriano, o que acontece é que a função onReload está sendo chamada 2 vezes. Tente substituir o método show de sua classe pelo do trait AdiantiStandardListTrait, que já tem algumas verificações para impedir que isso aconteça:
  1. <?php
  2. public function show()
  3.     {
  4.         // check if the datagrid is already loaded
  5.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload''onSearch')))) )
  6.         {
  7.             if (func_num_args() > 0)
  8.             {
  9.                 $this->onReloadfunc_get_arg(0) );
  10.             }
  11.             else
  12.             {
  13.                 $this->onReload();
  14.             }
  15.         }
  16.         parent::show();
  17.     }
  18. ?>
AR

Olá Nataniel, obrigado por sua resposta. Funciona bem quando tenho na gride um só registro, quando tenho mais de um, ocorre o erro, é apresentado a mensagem informando que "check concatenando com o a id que permaneceu na grid, ou seja que não foi selecionado" já está adicionado no formulário. segue anexo 1 e 2.
NR

Essa função que passei não funcionou?
AR

Não funcionou, continuo recebendo a mesma mensagem.
NR

Tente adicionar esse if antes do addField na onReload:
  1. <?php
  2. if (! $this->loaded)
  3.    $this->form->addField($object->check);
  4. ?>
AR

Agora funcionou perfeitamente. Muito Obrigado Nataniel.