IS
Manter Formulários preenchido depois de TDataGridAction
Ola! já estou sofrendo a um mês para solucionar uma situação, "Manter Formulário preenchido depois da ação TDataGridAction (delete ou edit)", muito básico se fosse diretamente no PHP, mas TDataGridAction essa classe ela limpa os dados da tela, tenho um TDate e dois TDBcombo, com preenchimento dependente. O foco do meu problema seria TDataGridAction que faz um post ou get na pagina executa uma ação. vou postar meu código se alguém puder me ajudar ou mesmo eu contrato o serviço para resolver este problema, estou com o framework somente a dois meses ainda não me adaptei totalmente. Já tentei variáveis de sessão, mas o tempo de execução não da certo, já tentei "form->setData($data);" mas depois que é executado TDataGridAction recarrega a classe os dados são zerados. São duas grids e 3 actions nas grids
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
- <?php
- class EmbarqueList extends TPage
- {
- private $form; // search form
- private $datagrid; // listing
- private $total;
- private $cartgrid;
- private $pageNavigation;
- private $loaded;
- /**
- * Class constructor
- * Creates the page, the search form and the listing
- */
- public function __construct()
- {
- parent::__construct();
- new TSession;
- // creates the form
- $this->form = new TForm('form_embarque');
- $panel_master = new TPanelGroup( 'Pesquisar' );
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- $this->form->add($panel_master);
- $panel_master->add($vbox);
- $frame_general = new TFrame;
- $frame_general->class = 'tframe tframe-custom';
- $frame_general->style = 'background:whiteSmoke';
- $table_general = new TTable;
- $table_general->width = '100%';
- $frame_general->add($table_general);
- $frame_product = new TFrame;
- $frame_product->class = 'tframe tframe-custom';
- $vbox->add( $frame_general );
- $vbox->add( $frame_product );
- //$customer_id = new TDBSeekButton('cidade_id', 'marca', $this->form->getName(), 'ViewViagem', 'name', 'cidade_id', 'cidade_id');
- //$customer_name = new TEntry('customer_name');
- // create the form fields
- $date = new TDate('saida');
- $date->setMask('dd/mm/yyyy');
- $date->setDatabaseMask('yyyy-mm-dd');
- $gdata = TSession::getValue('recarga');
- $criteria2 = new TCriteria;
- $criteria2->add(new TFilter('(DATE(DATA_INI))', '=', $gdata->saida));
- $cidade = new TDBCombo('cidade_id', 'marca', 'ViewViagem', 'cidade_id', '{cidade->nome}', null, $criteria2);
- $cidade->enableSearch();
- //$cidade->setChangeAction(new TAction(array($this, 'onChangeAction')));
- $criteria1 = new TCriteria;
- $criteria1->add(new TFilter('(DATE(DATA_INI))', '=', $gdata->saida));
- $criteria1->add(new TFilter('cidade_id', '=', $gdata->cidade_id));
- $viagem = new TDBCombo('carro_id', 'marca', 'Viagem', 'id', '{carro->modelo}', null, $criteria1);
- $viagem->enableSearch();
- //$viagem->setChangeAction(new TAction(array($this, 'onChangecarro')));
- $date->setSize(100);
- $cidade->setSize(350);
- $viagem->setSize(350);
- $this->form->addField($date);
- //$this->form->addField($customer_id);
- //$this->form->addField($customer_name);
- //$this->form->addField($cidade);
- $this->form->addField($cidade);
- $this->form->addField($viagem);
- $table_general->addRowSet( $label_date = new TLabel('Data (*)'), $date );
- $table_general->addRowSet( $label_cidade = new TLabel('Cidade (*)'), $cidade );
- $table_general->addRowSet( $label_viagem = new TLabel('Carro (*)'), $viagem );
- $label_date->setFontColor('#FF0000');
- // creates a DataGrid
- $this->datagrid = new TQuickGrid;
- $this->cartgrid = new TQuickGrid;
- // creates the datagrid columns
- $this->datagrid->addQuickColumn('Paciente/Acompanhante', '{paciente->NOME_PAC}', 'left', 280);
- $this->datagrid->addQuickColumn('Estabelecimento', '{estabelecimento->cnes->NOME_FANTA}', 'left', 280);
- $this->cartgrid->addQuickColumn('Paciente/Acompanhante', '{paciente->NOME_PAC}', 'left', 280);
- $this->cartgrid->addQuickColumn('Estabelecimento', '{estabelecimento->cnes->NOME_FANTA}', 'left', 280);
- // creates datagrid actions
- $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this, 'onSelect')), ['id','cidade_id', 'viagem_id'], 'fa:check-circle-o green');
- $this->cartgrid->addQuickAction('Delete', new TDataGridAction(array($this, 'onDelete')), 'id', 'fa:trash red');
- // create the datagrid model
- $this->datagrid->createModel();
- $this->cartgrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // creates the page structure using a table
- $table2 = new TTable;
- $row2=$table2->addRow();
- $cell2=$row2->addCell('');
- $cell2->width= 4;
- $row2->addMultiCell($this->datagrid, $this->cartgrid);
- $hbox = new THBox;
- $hbox->add($table2)->style.='vertical-align:top';
- $save_button = TButton::create('save', array($this, 'onSearch'), _t('Save'), 'fa:save green');
- $new_button = TButton::create('new', array($this, 'onDelete'), _t('Clear'), 'fa:eraser red');
- // define form fields
- $this->form->addField($save_button);
- $this->form->addField($new_button);
- $panel_master->addFooter( THBox::pack($save_button, $new_button) );
- // create the page container
- $container = new TVBox;
- $container->style = 'width: 100%';
- $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- $frame_product->add($hbox);
- $frame_product->add($this->pageNavigation);
- parent::add($container);
- }
- /**
- * Put a product inside the cart
- */
- public function onSelect($param)
- {
- // get the cart objects from session
- //$cart_objects = TSession::getValue('del_objects'); var_dump($cart_objects);
- TTransaction::open('marca');
- $product = new Embarque($param['key']); // load the product
- $del_objects[$product->id] = $product; // add the product inside the array
- //var_dump($cart_objects);
- //$object->viagem_id = '';
- //$object->store();
- TSession::setValue('del_objects', $del_objects); // put the array back to the session
- TTransaction::close();
- // reload datagrids
- $this->onReload( func_get_arg(0) );
- }
- public static function onChangecarro($param)
- {
- $recarga = TSession::getValue('recarga');
- }
- public static function onChangeAction($param)
- {
- //$recarga = TSession::getValue('recarga');
- $criteria1 = new TCriteria;
- $criteria1->add(new TFilter('(DATE(DATA_INI))', '=', $recarga->saida));
- $criteria1->add(new TFilter('cidade_id', '=', $recarga->cidade_id));
- TDBCombo::reloadFromModel('form_embarque', 'carro_id', 'marca', 'Viagem', 'id', '{carro->modelo}', null, $criteria1, false);
- }
- /**
- * Remove a product from the cart
- */
- public function onDelete($param)
- {
- $data = $this->form->getData();
- // get the cart objects from session
- $del_objects = TSession::getValue('del_objects');
- unset($del_objects[$param['key']]); // remove the product from the array
- TSession::setValue('del_objects', $del_objects); // put the array back to the session
- $this->form->setData($data);
- // reload datagrids
- $this->onReload( func_get_arg(0) );
- }
- /**
- * method onSearch()
- * Register the filter in the session when the user performs a search
- */
- function onSearch()
- {
- // get the search form data
- $data = $this->form->getData();
- // check if the user has filled the form
- if ($data->saida)
- {
- // creates a filter using what the user has typed
- $filter = new TFilter('saida', 'like', "%{$data->saida}%");
- // stores the filter in the session
- TSession::setValue('filter1', $filter);
- $object = new stdClass();
- $object->saida = $data->saida;
- $object->cidade_id = $data->cidade_id;
- $object->carro_id = $data->carro_id;
- TSession::setValue('recarga', $object);
- }
- else
- {
- TSession::setValue('filter1', NULL);
- //TSession::setValue('dtsaida', '');
- }
- // fill the form with data again
- $this->form->setData($data);
- $param=array();
- $param['offset'] =0;
- $param['first_page']=1;
- $this->onReload($param);
- }
- /**
- * method onReload()
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'samples'
- TTransaction::open('marca');
- $recarga = TSession::getValue('recarga');
- // creates a repository for Product
- $repository = new TRepository('Embarque');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- $criteria->setProperty('order', 'saida');
- $criteria->add(new TFilter('cidade_id', '=', $recarga->cidade_id));
- if (TSession::getValue('filter1'))
- {
- // add the filter stored in the session to the criteria
- $criteria->add(TSession::getValue('filter1'));
- }
- // load the objects according to criteria
- $products = $repository->load($criteria);
- $this->datagrid->clear();
- if ($products)
- {
- foreach ($products as $product)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($product);
- }
- }
- $this->cartgrid->clear();
- $del_objects = TSession::getValue('del_objects');
- if ($del_objects)
- {
- foreach ($del_objects as $object)
- {
- $this->cartgrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count= $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * method show()
- * Shows the page
- */
- function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded)
- {
- $this->onReload( func_get_arg(0) );
- }
- parent::show();
- }
- }
Tenho usado loadPage, exemplo, tenho um TDBRadio, conforme a seleção faço um loadPage carregando na grid somente o id do grupo selecionado no TDBRadio.
Estou com o mesmo problema, você ja conseguiu resolver?