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 ...
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

///////////////////////////////////////////////////////////////////////

 
  1. <?php
  2. class EmbarqueList extends TPage
  3. {
  4. private $form; // search form
  5. private $datagrid; // listing
  6. private $total;
  7. private $cartgrid;
  8. private $pageNavigation;
  9. private $loaded;
  10. /**
  11. * Class constructor
  12. * Creates the page, the search form and the listing
  13. */
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. new TSession;
  18. // creates the form
  19. $this->form = new TForm('form_embarque');
  20. $panel_master = new TPanelGroup( 'Pesquisar' );
  21. $vbox = new TVBox;
  22. $vbox->style = 'width: 100%';
  23. $this->form->add($panel_master);
  24. $panel_master->add($vbox);
  25. $frame_general = new TFrame;
  26. $frame_general->class = 'tframe tframe-custom';
  27. $frame_general->style = 'background:whiteSmoke';
  28. $table_general = new TTable;
  29. $table_general->width = '100%';
  30. $frame_general->add($table_general);
  31. $frame_product = new TFrame;
  32. $frame_product->class = 'tframe tframe-custom';
  33. $vbox->add( $frame_general );
  34. $vbox->add( $frame_product );
  35. //$customer_id = new TDBSeekButton('cidade_id', 'marca', $this->form->getName(), 'ViewViagem', 'name', 'cidade_id', 'cidade_id');
  36. //$customer_name = new TEntry('customer_name');
  37. // create the form fields
  38. $date = new TDate('saida');
  39. $date->setMask('dd/mm/yyyy');
  40. $date->setDatabaseMask('yyyy-mm-dd');
  41. $gdata = TSession::getValue('recarga');
  42. $criteria2 = new TCriteria;
  43. $criteria2->add(new TFilter('(DATE(DATA_INI))', '=', $gdata->saida));
  44. $cidade = new TDBCombo('cidade_id', 'marca', 'ViewViagem', 'cidade_id', '{cidade->nome}', null, $criteria2);
  45. $cidade->enableSearch();
  46. //$cidade->setChangeAction(new TAction(array($this, 'onChangeAction')));
  47. $criteria1 = new TCriteria;
  48. $criteria1->add(new TFilter('(DATE(DATA_INI))', '=', $gdata->saida));
  49. $criteria1->add(new TFilter('cidade_id', '=', $gdata->cidade_id));
  50. $viagem = new TDBCombo('carro_id', 'marca', 'Viagem', 'id', '{carro->modelo}', null, $criteria1);
  51. $viagem->enableSearch();
  52. //$viagem->setChangeAction(new TAction(array($this, 'onChangecarro')));
  53. $date->setSize(100);
  54. $cidade->setSize(350);
  55. $viagem->setSize(350);
  56. $this->form->addField($date);
  57. //$this->form->addField($customer_id);
  58. //$this->form->addField($customer_name);
  59. //$this->form->addField($cidade);
  60. $this->form->addField($cidade);
  61. $this->form->addField($viagem);
  62. $table_general->addRowSet( $label_date = new TLabel('Data (*)'), $date );
  63. $table_general->addRowSet( $label_cidade = new TLabel('Cidade (*)'), $cidade );
  64. $table_general->addRowSet( $label_viagem = new TLabel('Carro (*)'), $viagem );
  65. $label_date->setFontColor('#FF0000');
  66. // creates a DataGrid
  67. $this->datagrid = new TQuickGrid;
  68. $this->cartgrid = new TQuickGrid;
  69. // creates the datagrid columns
  70. $this->datagrid->addQuickColumn('Paciente/Acompanhante', '{paciente->NOME_PAC}', 'left', 280);
  71. $this->datagrid->addQuickColumn('Estabelecimento', '{estabelecimento->cnes->NOME_FANTA}', 'left', 280);
  72. $this->cartgrid->addQuickColumn('Paciente/Acompanhante', '{paciente->NOME_PAC}', 'left', 280);
  73. $this->cartgrid->addQuickColumn('Estabelecimento', '{estabelecimento->cnes->NOME_FANTA}', 'left', 280);
  74. // creates datagrid actions
  75. $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this, 'onSelect')), ['id','cidade_id', 'viagem_id'], 'fa:check-circle-o green');
  76. $this->cartgrid->addQuickAction('Delete', new TDataGridAction(array($this, 'onDelete')), 'id', 'fa:trash red');
  77. // create the datagrid model
  78. $this->datagrid->createModel();
  79. $this->cartgrid->createModel();
  80. // creates the page navigation
  81. $this->pageNavigation = new TPageNavigation;
  82. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  83. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  84. // creates the page structure using a table
  85. $table2 = new TTable;
  86. $row2=$table2->addRow();
  87. $cell2=$row2->addCell('');
  88. $cell2->width= 4;
  89. $row2->addMultiCell($this->datagrid, $this->cartgrid);
  90. $hbox = new THBox;
  91. $hbox->add($table2)->style.='vertical-align:top';
  92. $save_button = TButton::create('save', array($this, 'onSearch'), _t('Save'), 'fa:save green');
  93. $new_button = TButton::create('new', array($this, 'onDelete'), _t('Clear'), 'fa:eraser red');
  94. // define form fields
  95. $this->form->addField($save_button);
  96. $this->form->addField($new_button);
  97. $panel_master->addFooter( THBox::pack($save_button, $new_button) );
  98. // create the page container
  99. $container = new TVBox;
  100. $container->style = 'width: 100%';
  101. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  102. $container->add($this->form);
  103. $frame_product->add($hbox);
  104. $frame_product->add($this->pageNavigation);
  105. parent::add($container);
  106. }
  107. /**
  108. * Put a product inside the cart
  109. */
  110. public function onSelect($param)
  111. {
  112. // get the cart objects from session
  113. //$cart_objects = TSession::getValue('del_objects'); var_dump($cart_objects);
  114. TTransaction::open('marca');
  115. $product = new Embarque($param['key']); // load the product
  116. $del_objects[$product->id] = $product; // add the product inside the array
  117. //var_dump($cart_objects);
  118. //$object->viagem_id = '';
  119. //$object->store();
  120. TSession::setValue('del_objects', $del_objects); // put the array back to the session
  121. TTransaction::close();
  122. // reload datagrids
  123. $this->onReload( func_get_arg(0) );
  124. }
  125. public static function onChangecarro($param)
  126. {
  127. $recarga = TSession::getValue('recarga');
  128. }
  129. public static function onChangeAction($param)
  130. {
  131. //$recarga = TSession::getValue('recarga');
  132. $criteria1 = new TCriteria;
  133. $criteria1->add(new TFilter('(DATE(DATA_INI))', '=', $recarga->saida));
  134. $criteria1->add(new TFilter('cidade_id', '=', $recarga->cidade_id));
  135. TDBCombo::reloadFromModel('form_embarque', 'carro_id', 'marca', 'Viagem', 'id', '{carro->modelo}', null, $criteria1, false);
  136. }
  137. /**
  138. * Remove a product from the cart
  139. */
  140. public function onDelete($param)
  141. {
  142. $data = $this->form->getData();
  143. // get the cart objects from session
  144. $del_objects = TSession::getValue('del_objects');
  145. unset($del_objects[$param['key']]); // remove the product from the array
  146. TSession::setValue('del_objects', $del_objects); // put the array back to the session
  147. $this->form->setData($data);
  148. // reload datagrids
  149. $this->onReload( func_get_arg(0) );
  150. }
  151. /**
  152. * method onSearch()
  153. * Register the filter in the session when the user performs a search
  154. */
  155. function onSearch()
  156. {
  157. // get the search form data
  158. $data = $this->form->getData();
  159. // check if the user has filled the form
  160. if ($data->saida)
  161. {
  162. // creates a filter using what the user has typed
  163. $filter = new TFilter('saida', 'like', "%{$data->saida}%");
  164. // stores the filter in the session
  165. TSession::setValue('filter1', $filter);
  166. $object = new stdClass();
  167. $object->saida = $data->saida;
  168. $object->cidade_id = $data->cidade_id;
  169. $object->carro_id = $data->carro_id;
  170. TSession::setValue('recarga', $object);
  171. }
  172. else
  173. {
  174. TSession::setValue('filter1', NULL);
  175. //TSession::setValue('dtsaida', '');
  176. }
  177. // fill the form with data again
  178. $this->form->setData($data);
  179. $param=array();
  180. $param['offset'] =0;
  181. $param['first_page']=1;
  182. $this->onReload($param);
  183. }
  184. /**
  185. * method onReload()
  186. * Load the datagrid with the database objects
  187. */
  188. function onReload($param = NULL)
  189. {
  190. try
  191. {
  192. // open a transaction with database 'samples'
  193. TTransaction::open('marca');
  194. $recarga = TSession::getValue('recarga');
  195. // creates a repository for Product
  196. $repository = new TRepository('Embarque');
  197. $limit = 10;
  198. // creates a criteria
  199. $criteria = new TCriteria;
  200. $criteria->setProperties($param); // order, offset
  201. $criteria->setProperty('limit', $limit);
  202. $criteria->setProperty('order', 'saida');
  203. $criteria->add(new TFilter('cidade_id', '=', $recarga->cidade_id));
  204. if (TSession::getValue('filter1'))
  205. {
  206. // add the filter stored in the session to the criteria
  207. $criteria->add(TSession::getValue('filter1'));
  208. }
  209. // load the objects according to criteria
  210. $products = $repository->load($criteria);
  211. $this->datagrid->clear();
  212. if ($products)
  213. {
  214. foreach ($products as $product)
  215. {
  216. // add the object inside the datagrid
  217. $this->datagrid->addItem($product);
  218. }
  219. }
  220. $this->cartgrid->clear();
  221. $del_objects = TSession::getValue('del_objects');
  222. if ($del_objects)
  223. {
  224. foreach ($del_objects as $object)
  225. {
  226. $this->cartgrid->addItem($object);
  227. }
  228. }
  229. // reset the criteria for record count
  230. $criteria->resetProperties();
  231. $count= $repository->count($criteria);
  232. $this->pageNavigation->setCount($count); // count of records
  233. $this->pageNavigation->setProperties($param); // order, page
  234. $this->pageNavigation->setLimit($limit); // limit
  235. // close the transaction
  236. TTransaction::close();
  237. $this->loaded = true;
  238. }
  239. catch (Exception $e) // in case of exception
  240. {
  241. // shows the exception error message
  242. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  243. // undo all pending operations
  244. TTransaction::rollback();
  245. }
  246. }
  247. /**
  248. * method show()
  249. * Shows the page
  250. */
  251. function show()
  252. {
  253. // check if the datagrid is already loaded
  254. if (!$this->loaded)
  255. {
  256. $this->onReload( func_get_arg(0) );
  257. }
  258. parent::show();
  259. }
  260. }

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (2)


MR

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.


 
  1. <?php
  2. public static function onGrupo($param)
  3. {
  4. $parametros = array();
  5. $parametros['key'] = $param['grupo'];
  6. TApplication::loadPage('ProdutoList', 'onReload', $parametros);
  7. }
  8. ?>
SF

Estou com o mesmo problema, você ja conseguiu resolver?