Chamar outra aplicação pelo botão editar de FormSeek Olá Fiz um FormSeek e criei um botão confirmar que é automático e outro de editar? gostaria de chamar uma aplicação qualquer clicando no botão Editar que aciona o OnEdit, nete method onEdit Coloquei: TApplication::loadPage('CadTransportadoraForm'); Não funcionou, nada acontece. Ari...
AF
Chamar outra aplicação pelo botão editar de FormSeek  
Olá

Fiz um FormSeek e criei um botão confirmar que é automático e outro de editar?

gostaria de chamar uma aplicação qualquer clicando no botão Editar que aciona o OnEdit, nete method onEdit

Coloquei: TApplication::loadPage('CadTransportadoraForm');

Não funcionou, nada acontece.

Ari

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


FF

Tente assim:
 
  1. <?php
  2. AdiantiCoreApplication::loadPage('SuaClasse', 'SeuMétodo');
  3. ?>
AF

Grato, vou tentar e retorno.

Ari
AF

Olá Fabio

Gerei uma classe conforme abaixo, herdando de TWindow

Clicando no OK fecha a TWindow e a tela fica em branco, nada acontece

 
  1. <?php
  2. /**
  3. * ClienteSeek Listing
  4. * @author <your name here>
  5. */
  6. class ClienteSeek extends TWindow
  7. {
  8. private $form; // form
  9. private $datagrid; // listing
  10. private $pageNavigation;
  11. private $formgrid;
  12. private $loaded;
  13. /**
  14. * Class constructor
  15. * Creates the page, the form and the listing
  16. */
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. parent::setTitle( AdiantiCoreTranslator::translate('Search record') );
  21. parent::setSize(0.99, 0.99);
  22. // creates the form
  23. $this->form = new TQuickForm('form_search_Cliente');
  24. $this->form->class = 'tform'; // change CSS class
  25. $this->form->style = 'display: table; width:30%'; // change style
  26. $this->form->setFormTitle('Pesquisa de Cliente / Fornecedores ');
  27. // create the form fields
  28. $GUERRA = new TEntry('GUERRA');
  29. $CLIENTE = new TEntry('CLIENTE');
  30. $CONTATO = new TEntry('CONTATO');
  31. $CIDADE = new TEntry('CIDADE');
  32. $ESTADO = new TEntry('ESTADO');
  33. // add the fields
  34. $this->form->addQuickField('Apelido', $GUERRA , '40%' );
  35. $this->form->addQuickField('Cliente', $CLIENTE, '40%' );
  36. $this->form->addQuickField('Contato', $CONTATO, '40%' );
  37. $this->form->addQuickFields('Cidade', [ $CIDADE, $l1 = new TLabel('UF'), $ESTADO ] );
  38. $GUERRA->setSize(200);
  39. $CLIENTE->setSize(300);
  40. $CONTATO->setSize(300);
  41. $CIDADE->setSize(200);
  42. $ESTADO->setSize(50);
  43. // keep the form filled during navigation with session data
  44. $this->form->setData( TSession::getValue('Cliente_filter_data') );
  45. // add the search form actions
  46. $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  47. $this->form->addQuickAction( 'Limpar', new TAction(array($this, 'onClear' )), 'bs:plus-sign green');
  48. $this->form->addQuickAction( 'Fechar', new TAction(array($this, 'onExit' )), 'ico_close.png');
  49. TScript::create('$("#my_table tr:eq(0) th:eq(0)").text("Selecionar");');
  50. // creates a DataGrid
  51. $this->datagrid = new TDataGrid;
  52. $this->datagrid->id = 'my_table';
  53. $this->datagrid->style = 'width: 100%';
  54. $this->datagrid->datatable = 'true';
  55. // creates the datagrid columns
  56. $column_CODCLI = new TDataGridColumn('CODCLI', 'Codigo', 'right');
  57. $column_GUERRA = new TDataGridColumn('GUERRA', 'Guerra', 'left');
  58. $column_CLIENTE = new TDataGridColumn('CLIENTE', 'Cliente', 'left');
  59. $column_TELEFONE = new TDataGridColumn('TELEFONE', 'Telefone', 'left');
  60. $column_CONTATO = new TDataGridColumn('CONTATO', 'Contato', 'left');
  61. $column_ENDERFAT = new TDataGridColumn('ENDERFAT', 'Endereco', 'left');
  62. $column_BAIRRO = new TDataGridColumn('BAIRRO', 'Bairro', 'left');
  63. $column_CIDADE = new TDataGridColumn('CIDADE', 'Cidade', 'left');
  64. $column_ESTADO = new TDataGridColumn('ESTADO', 'Estado', 'left');
  65. // add the columns to the DataGrid
  66. $this->datagrid->addColumn($column_CODCLI);
  67. $this->datagrid->addColumn($column_GUERRA);
  68. $this->datagrid->addColumn($column_CLIENTE);
  69. $this->datagrid->addColumn($column_CONTATO);
  70. $this->datagrid->addColumn($column_ENDERFAT);
  71. $this->datagrid->addColumn($column_BAIRRO);
  72. $this->datagrid->addColumn($column_CIDADE);
  73. $this->datagrid->addColumn($column_ESTADO);
  74. // create EDIT action
  75. $action_select = new TDataGridAction(array($this, 'onSelect'));
  76. $action_select->setUseButton(TRUE);
  77. $action_select->setLabel('Ok');
  78. $action_select->setImage('fa:hand-pointer-o green');
  79. $action_select->setField('CODCLI');
  80. $this->datagrid->addAction($action_select);
  81. // create the datagrid model
  82. $this->datagrid->createModel();
  83. // creates the page navigation
  84. $this->pageNavigation = new TPageNavigation;
  85. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  86. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  87. // vertical box container
  88. $container = new TVBox;
  89. $container->style = 'width: 90%';
  90. $container->add(TPanelGroup::pack('Registro(s) encontrado(s)', $this->datagrid, $this->pageNavigation));
  91. parent::add($this->form);
  92. parent::add($container);
  93. }
  94. /**
  95. * Register the filter in the session
  96. */
  97. public function onSearch()
  98. {
  99. // get the search form data
  100. $data = $this->form->getData();
  101. // clear session filters
  102. TSession::setValue('ClienteSeek_filter_GUERRA', NULL);
  103. TSession::setValue('ClienteSeek_filter_CLIENTE', NULL);
  104. TSession::setValue('ClienteSeek_filter_CIDADE', NULL);
  105. TSession::setValue('ClienteSeek_filter_ESTADO', NULL);
  106. if (isset($data->GUERRA) AND ($data->GUERRA)) {
  107. $filter = new TFilter('GUERRA', 'like', "%{$data->GUERRA}%"); // create the filter
  108. TSession::setValue('ClienteSeek_filter_GUERRA', $filter); // stores the filter in the session
  109. }
  110. if (isset($data->CLIENTE) AND ($data->CLIENTE)) {
  111. $filter = new TFilter('CLIENTE', 'like', "%{$data->CLIENTE}%"); // create the filter
  112. TSession::setValue('ClienteSeek_filter_CLIENTE', $filter); // stores the filter in the session
  113. }
  114. if (isset($data->CIDADE) AND ($data->CIDADE)) {
  115. $filter = new TFilter('CIDADE', 'like', "%{$data->CIDADE}%"); // create the filter
  116. TSession::setValue('ClienteSeek_filter_CIDADE', $filter); // stores the filter in the session
  117. }
  118. if (isset($data->ESTADO) AND ($data->ESTADO)) {
  119. $filter = new TFilter('ESTADO', 'like', "%{$data->ESTADO}%"); // create the filter
  120. TSession::setValue('ClienteSeek_filter_ESTADO', $filter); // stores the filter in the session
  121. }
  122. // fill the form with data again
  123. $this->form->setData($data);
  124. // keep the search data in the session
  125. TSession::setValue('Cliente_filter_data', $data);
  126. $param=array();
  127. $param['offset'] =0;
  128. $param['first_page']=1;
  129. $this->onReload($param);
  130. }
  131. /**
  132. * Load the datagrid with data
  133. */
  134. public function onReload($param = NULL)
  135. {
  136. try
  137. {
  138. // open a transaction with database 'sisrev'
  139. TTransaction::open('sisrev');
  140. // creates a repository for Cliente
  141. $repository = new TRepository('Cliente');
  142. $limit = 6;
  143. // creates a criteria
  144. $criteria = new TCriteria;
  145. // default order
  146. if (empty($param['order']))
  147. {
  148. $param['order'] = 'CODCLI';
  149. $param['direction'] = 'asc';
  150. }
  151. $criteria->setProperties($param); // order, offset
  152. $criteria->setProperty('limit', $limit);
  153. if (TSession::getValue('ClienteSeek_filter_GUERRA')) {
  154. $criteria->add(TSession::getValue('ClienteSeek_filter_GUERRA')); // add the session filter
  155. }
  156. if (TSession::getValue('ClienteSeek_filter_CLIENTE')) {
  157. $criteria->add(TSession::getValue('ClienteSeek_filter_CLIENTE')); // add the session filter
  158. }
  159. if (TSession::getValue('ClienteSeek_filter_CIDADE')) {
  160. $criteria->add(TSession::getValue('ClienteSeek_filter_CIDADE')); // add the session filter
  161. }
  162. if (TSession::getValue('ClienteSeek_filter_ESTADO')) {
  163. $criteria->add(TSession::getValue('ClienteSeek_filter_ESTADO')); // add the session filter
  164. }
  165. // load the objects according to criteria
  166. $objects = $repository->load($criteria, FALSE);
  167. if (is_callable($this->transformCallback))
  168. {
  169. call_user_func($this->transformCallback, $objects, $param);
  170. }
  171. $this->datagrid->clear();
  172. if ($objects)
  173. {
  174. // iterate the collection of active records
  175. foreach ($objects as $object)
  176. {
  177. // add the object inside the datagrid
  178. $this->datagrid->addItem($object);
  179. }
  180. }
  181. // reset the criteria for record count
  182. $criteria->resetProperties();
  183. $count= $repository->count($criteria);
  184. $this->pageNavigation->setCount($count); // count of records
  185. $this->pageNavigation->setProperties($param); // order, page
  186. $this->pageNavigation->setLimit($limit); // limit
  187. // close the transaction
  188. TTransaction::close();
  189. $this->loaded = true;
  190. }
  191. catch (Exception $e) // in case of exception
  192. {
  193. // shows the exception error message
  194. new TMessage('error', $e->getMessage());
  195. // undo all pending operations
  196. TTransaction::rollback();
  197. }
  198. }
  199. /**
  200. * Executed when the user chooses the record
  201. */
  202. public static function onSelect($param)
  203. {
  204. try
  205. {
  206. $key = $param['key'];
  207. TTransaction::open('sisrev');
  208. // load the active record
  209. $object = Cliente::find($key);
  210. $param['codcli'] = $object->codcli;
  211. // closes the transaction
  212. TTransaction::close();
  213. AdiantiCoreApplication::loadPage('CadastroClienteForm', 'onEdit', $param);
  214. parent::closeWindow();
  215. }
  216. catch (Exception $e)
  217. {
  218. $send = new StdClass;
  219. $param['codcli'] = 0;
  220. AdiantiCoreApplication::loadPage('CadastroClienteForm', 'onEdit', $param);
  221. // undo pending operations
  222. TTransaction::rollback();
  223. }
  224. }
  225. /**
  226. * method show()
  227. * Shows the page
  228. */
  229. public function show()
  230. {
  231. // check if the datagrid is already loaded
  232. if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
  233. {
  234. if (func_num_args() > 0)
  235. {
  236. $this->onReload( func_get_arg(0) );
  237. }
  238. else
  239. {
  240. $this->onReload();
  241. }
  242. }
  243. parent::show();
  244. }
  245. /**
  246. * Clear form data
  247. * @param $param Request
  248. */
  249. public function onClear( $param )
  250. {
  251. $this->form->clear(TRUE);
  252. }
  253. /**
  254. * onExit form data
  255. * @param $param Request
  256. */
  257. public function onExit( $param )
  258. {
  259. parent::closeWindow();
  260. }
  261. }
  262. </code>
</your>
FF

remova o $param da linha 260...
Altere de:
 
  1. <?php
  2. AdiantiCoreApplication::loadPage('CadastroClienteForm', 'onEdit', $param);
  3. ?>

para:
 
  1. <?php
  2. AdiantiCoreApplication::loadPage('CadastroClienteForm', 'onEdit');
  3. ?>
AF

OK

retirando o $param fecha a TWindow e abre o CadastroClienteForm

em branco não posiciona no registro.

Ari
AF

Este é o onEdit da Classe CadastroClienteForm

/** * method onEdit() * Executed whenever the user clicks at the edit button da datagrid */ function onEdit($param) { try { if (isset($param['key'])) { // get the parameter $key $key=$param['key']; // open a transaction with database 'sisrev' TTransaction::open('sisrev'); // instantiates object Transp $object = new Transp($key); // fill the form with the active record data $this->form->setData($object); // close the transaction TTransaction::close(); } else { $this->form->clear(); } } 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(); } }
AF

Postando novamente

este é o method onEdit da Classe CadastroClienteForm

/** * method onEdit() * Executed whenever the user clicks at the edit button da datagrid */ function onEdit($param) { try { if (isset($param['key'])) { // get the parameter $key $key=$param['key']; // open a transaction with database 'sisrev' TTransaction::open('sisrev'); // instantiates object Transp $object = new Transp($key); // fill the form with the active record data $this->form->setData($object); // close the transaction TTransaction::close(); } else { $this->form->clear(); } } 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(); } }
AF

[code]
/**
* method onEdit()
* Executed whenever the user clicks at the edit button da datagrid
*/
function onEdit($param)
{
try
{
if (isset($param['key']))
{
// get the parameter $key
$key=$param['key'];

// open a transaction with database 'sisrev'
TTransaction::open('sisrev');

// instantiates object Transp
$object = new Transp($key);

// fill the form with the active record data
$this->form->setData($object);

// close the transaction
TTransaction::close();
}
else
{
$this->form->clear();
}
}
catch (Exception $e) // in case of exception
{
// shows the exception error message
new TMessage('error', 'Error ' . $e->getMessage());

// undo all pending operations
TTransaction::rollback();
}
}
[/code]
FF

Você pode salvar o $key do onSelect numa variável de sessão e pegá-la do outro lado...

Assim:

 
  1. <?php
  2. public static function onSelect($param)
  3. {
  4. try
  5. {
  6. $key = $param['key'];
  7. TSession::setValue('idRegistro', $key); // salvando na variável de sessão
  8. TTransaction::open('sisrev');
  9. // load the active record
  10. $object = Cliente::find($key);
  11. $param['codcli'] = $object->codcli;
  12. // closes the transaction
  13. TTransaction::close();
  14. AdiantiCoreApplication::loadPage('CadastroClienteForm', 'onEdit', $param);
  15. parent::closeWindow();
  16. }
  17. catch (Exception $e)
  18. {
  19. $send = new StdClass;
  20. $param['codcli'] = 0;
  21. AdiantiCoreApplication::loadPage('CadastroClienteForm', 'onEdit', $param);
  22. // undo pending operations
  23. TTransaction::rollback();
  24. }
  25. }
  26. ?>


Agora, no onEdit pegue o valor da $key:

 
  1. <?php
  2. function onEdit($param)
  3. {
  4. try
  5. {
  6. //if (isset($param['key']))
  7. if ( isset( TSession::getValue('idRegistro') ) )
  8. {
  9. // get the parameter $key
  10. //$key=$param['key'];
  11. $key=TSession::getValue('idRegistro'); // pegando o valor da $key armazenada na variável de sessão
  12. // open a transaction with database 'sisrev'
  13. TTransaction::open('sisrev');
  14. // instantiates object Transp
  15. $object = new Transp($key);
  16. // fill the form with the active record data
  17. $this->form->setData($object);
  18. // close the transaction
  19. TTransaction::close();
  20. }
  21. else
  22. {
  23. $this->form->clear();
  24. }
  25. }
  26. catch (Exception $e) // in case of exception
  27. {
  28. // shows the exception error message
  29. new TMessage('error', 'Error ' . $e->getMessage());
  30. // undo all pending operations
  31. TTransaction::rollback();
  32. }
  33. }
  34. No entanto, isso só servirá para quando vc for chamar esse método clicando no botão OK da outra classe.
  35. Caso for chamar esse método através dessa mesma classe, terá que adaptar o código para que atenda as duas situações.
  36. Recomendo que crie um método específico para atender apenas quando clicar no botão OK, e deixe o onEdit na forma original.
FF

ops... lá na linha 19 do onSelect, retire o $param...
FF

Ari desculpe mais uma vez.. corrigindo:
na linha 8 :
if ( TSession::getValue('idRegistro') <> '' )
AF

Fabio,

com esta últimas modificações, funcionou !

Grato