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


Agora, no onEdit pegue o valor da $key:

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