Ajuda com TSeekButton Estou utilizando o componente TSeekButton e se clicar na "lupa" a tela funciona corretamente. A tela que estou com este problema é uma tela de contatos onde possuo uma outra tabela de tipos de contatos. O problema é que ao entrar no formulário de contato, eu ja tenho o codigo do tipo de contato cadastrado. Mas nao aparece a descricao do tipo de contato na tela (conforme imagem anexada) S...
NP
Ajuda com TSeekButton  
Fechado
Estou utilizando o componente TSeekButton e se clicar na "lupa" a tela funciona corretamente.
A tela que estou com este problema é uma tela de contatos onde possuo uma outra tabela de tipos de contatos.

O problema é que ao entrar no formulário de contato, eu ja tenho o codigo do tipo de contato cadastrado. Mas nao aparece a descricao do tipo de contato na tela (conforme imagem anexada)

Se eu clico no campo "Tipo Contato" e saio deste campo atraves da tecla TAB (exit), ai aparece a descricao do tipo de contato certinho.

Eu peguei as classes CustomerDataGridView , CustomerFormView e CitySeek e adaptei conforme as minhas tabelas.

Alguém tem alguma dica para me ajudar ? Pois ja olhei o exemplo da classe "CustomerFormView" (tutor) e tambem a classe "CitySeek" e não consegui achar nenhuma diferença.

A sequencia de execução é a seguinte:

1-) Entro na primeira tela do Grid (ContatoDataGridView)
2-) Seleciono um registro e clico no botao "editar" , é chamada a classe "ContatoFormView"

É nesta classe "ContatoFormView" que não aparece a descrição do Tipo de Contato.

abaixo segue o codigo php da classe ContatoFormView:

 
  1. <?php
  2. /**
  3. * ContatoFormView
  4. */
  5. class ContatoFormView extends TPage
  6. {
  7. private $form; // form
  8. /**
  9. * Class constructor
  10. * Creates the page and the registration form
  11. */
  12. function __construct()
  13. {
  14. parent::__construct();
  15. // creates the form
  16. $this->form = new TForm('form_contato');
  17. // creates a table
  18. $table_data = new TTable;
  19. $table_telefones = new TTable;
  20. $table_emails = new TTable;
  21. $notebook = new TNotebook(500, 250);
  22. // add the notebook inside the form
  23. $this->form->add($notebook);
  24. $notebook->appendPage('Registrar Dados', $table_data);
  25. $notebook->appendPage('Contato (telefones)', $table_telefones);
  26. $notebook->appendPage('Contato (e-mail)', $table_emails);
  27. // create the form fields
  28. $contato_id = new TEntry('contato_id');
  29. $tipo_contato_id = new TSeekButton('tipo_contato_id');
  30. $tipocontato_nome = new TEntry('tipocontato_nome');
  31. $nome_contato = new TEntry('nome_contato');
  32. $endereco = new TEntry('endereco');
  33. $bairro = new TEntry('bairro');
  34. $cep = new TEntry('cep');
  35. $cidade = new TEntry('cidade');
  36. $uf = new TEntry('uf');
  37. $ponto_referencia = new TEntry('ponto_referencia');
  38. $observacoes = new TEntry('observacoes');
  39. $responsavel_id = new TEntry('responsavel_id');
  40. $dt_inclusao = new TDate('dt_inclusao');
  41. $status = new TCombo('status');
  42. $telefone_comercial = new TEntry('telefone_comercial');
  43. $telefone_residencial = new TEntry('telefone_residencial');
  44. $telefone_contato = new TEntry('telefone_contato');
  45. $telefone_celular = new TEntry('telefone_celular');
  46. $telefone_consultorio = new TEntry('telefone_consultorio');
  47. $email_comercial = new TEntry('email_comercial');
  48. $email_contato = new TEntry('email_contato');
  49. $email_particular = new TEntry('email_particular');
  50. $responsavel_id->setValue(TSession::getValue('login')); // Buscar o login do usuario logado - 21/06/2016
  51. $responsavel_id->setEditable(false);
  52. /* ---------------------------------------------------------------------------------*/
  53. $dt_inclusao->setValue( date('Y/m/d', mktime(0, 0, 0, date("m") , date("d"), date("Y")) ));
  54. $contato_id->setEditable(false);
  55. $cbo_stat = array();
  56. $cbo_stat['AT'] = 'Ativo';
  57. $cbo_stat['IN'] = 'Inativo';
  58. $cbo_stat['CA'] = 'Cancelado';
  59. $cbo_stat['EX'] = 'Excluido';
  60. $status->addItems($cbo_stat);
  61. $status->setValue('AT');
  62. /* ---------------------------------------------------------------------------------*/
  63. // add field validators
  64. $nome_contato->addValidation('Nome Contato', new TRequiredValidator);
  65. $tipo_contato_id->addValidation('Tipo do Contato', new TRequiredValidator);
  66. //--------------------------------------------------------------------------//
  67. //----------[ Aqui é onde se busca o Tipo de Contato ]----------------------//
  68. //--------------------------------------------------------------------------//
  69. $obj = new TipoContatoSeek;
  70. $tipo_contato_id->setAction(new TAction(array($obj, 'onReload')));
  71. //--------------------------------------------------------------------------//
  72. // define the action for city_id1
  73. //$obj = new TipoContatoSeek;
  74. //$action = new TAction(array($obj, 'onReload'));
  75. //$tipo_contato_id->setAction($action);
  76. //--------------------------------------------------------------------------//
  77. // Define o Comprimento e largura
  78. $contato_id->setSize(40);
  79. $tipo_contato_id->setSize(50);
  80. $tipocontato_nome->setSize(327);
  81. $nome_contato->setSize(400);
  82. $endereco->setSize(400);
  83. $bairro->setSize(300);
  84. $cep->setSize(150);
  85. $cidade->setSize(400);
  86. $uf->setSize(40);
  87. $ponto_referencia->setSize(400);
  88. $observacoes->setSize(400);
  89. $telefone_comercial->setSize(160);
  90. $telefone_residencial->setSize(160);
  91. $telefone_contato->setSize(160);
  92. $telefone_celular->setSize(160);
  93. $telefone_consultorio->setSize(160);
  94. $email_comercial->setSize(300);
  95. $email_contato->setSize(300);
  96. $email_particular->setSize(300);
  97. // add a row for the field code
  98. $table_data->addRowSet(new TLabel('ID:'), $contato_id);
  99. $table_data->addRowSet(new TLabel('Tipo Contato:'), array($tipo_contato_id, new TLabel('Nome:'),$tipocontato_nome));
  100. $table_data->addRowSet(new TLabel('Nome Contato:'), $nome_contato);
  101. $table_data->addRowSet(new TLabel('Endereco:'), array($endereco, new TLabel('Bairro:'), $bairro));
  102. $table_data->addRowSet(new TLabel('Cidade:'), array($cidade, new TLabel('Cep:'), $cep, new TLabel('UF:'), $uf));
  103. $table_data->addRowSet(new TLabel('Ponto Referencia:'), $ponto_referencia);
  104. $table_data->addRowSet(new TLabel('Observacoes:'), $observacoes);
  105. $table_data->addRowSet(new TLabel('Status:'), $status);
  106. $contato_id->setEditable(FALSE);
  107. $tipocontato_nome->setEditable(FALSE);
  108. $row = $table_telefones->addRow();
  109. $cell = $row->addCell(new TLabel('<b>Numeros de Telefones</b>'));
  110. $cell->valign = 'top';
  111. // add two fields inside the multifield in the second sheet
  112. $table_telefones->addRowSet(new TLabel('Comercial:'), $telefone_comercial);
  113. $table_telefones->addRowSet(new TLabel('Residencial:'), $telefone_residencial);
  114. $table_telefones->addRowSet(new TLabel('Celular:'), $telefone_celular);
  115. $table_telefones->addRowSet(new TLabel('Consultorio:'), $telefone_consultorio);
  116. $table_telefones->addRowSet(new TLabel('Contato:'), $telefone_contato);
  117. $row = $table_emails->addRow();
  118. $cell = $row->addCell(new TLabel('<b>E-mails para Contato</b>'));
  119. $cell->valign = 'top';
  120. // add two fields inside the multifield in the second sheet
  121. $table_emails->addRowSet(new TLabel('Comercial:'), $email_comercial);
  122. $table_emails->addRowSet(new TLabel('Particular:'), $email_particular);
  123. $table_emails->addRowSet(new TLabel('Contato:'), $email_contato);
  124. // create an action button
  125. $button1=new TButton('button1');
  126. $button1->setAction(new TAction(array($this, 'onSave')), 'Salvar');
  127. $button1->setImage('ico_save.png');
  128. // create an action button (go to list)
  129. $button2=new TButton('button2');
  130. $button2->setAction(new TAction(array('ContatoDataGridView', 'onReload')), 'Retorna');
  131. $button2->setImage('ico_datagrid.gif');
  132. $this->form->setFields(array($contato_id, $tipo_contato_id, $tipocontato_nome,
  133. $nome_contato, $endereco, $bairro, $cep, $cidade,
  134. $uf, $ponto_referencia, $telefone_comercial, $telefone_residencial,
  135. $telefone_contato, $telefone_celular, $telefone_consultorio,
  136. $email_comercial, $email_contato, $email_particular,
  137. $observacoes, $dt_inclusao, $responsavel_id, $status, $button1, $button2));
  138. $subtable = new TTable;
  139. $row = $subtable->addRow();
  140. $row->addCell($button1);
  141. $row->addCell($button2);
  142. // wrap the page content
  143. $vbox = new TVBox;
  144. $vbox->add(new TXMLBreadCrumb('menu.xml', 'ContatoDataGridView'));
  145. $vbox->add($this->form);
  146. $vbox->add($subtable);
  147. // add the form inside the page
  148. parent::add($vbox);
  149. }
  150. /**
  151. * method onSave
  152. * Executed whenever the user clicks at the save button
  153. */
  154. function onSave()
  155. {
  156. try
  157. {
  158. // open a transaction with database 'sgp'
  159. TTransaction::open('sgp');
  160. $this->form->validate();
  161. // read the form data and instantiates an Active Record
  162. $Contato = $this->form->getData('Contato');
  163. if ($Contato->contacts_list)
  164. {
  165. foreach ($Contato->contacts_list as $contact)
  166. {
  167. // add the contact to the Contato
  168. $Contato->addContact($contact);
  169. }
  170. }
  171. if ($Contato->skill_list)
  172. {
  173. foreach ($Contato->skill_list as $skill_id)
  174. {
  175. // add the skill to the Contato
  176. $Contato->addSkill(new Skill($skill_id));
  177. }
  178. }
  179. // stores the object in the database
  180. $Contato->store();
  181. $this->form->setData($Contato);
  182. // shows the success message
  183. new TMessage('info', 'Record saved');
  184. TTransaction::close(); // close the transaction
  185. }
  186. catch (Exception $e) // in case of exception
  187. {
  188. // shows the exception error message
  189. new TMessage('error', '<b>Error</b>: ' . $e->getMessage());
  190. // undo all pending operations
  191. TTransaction::rollback();
  192. }
  193. }
  194. /**
  195. * method onEdit
  196. * Edit a record data
  197. */
  198. function onEdit($param)
  199. {
  200. try
  201. {
  202. if (isset($param['key']))
  203. {
  204. // open a transaction with database 'sgp'
  205. TTransaction::open('sgp');
  206. // load the Active Record according to its ID
  207. $Contato = new Contato($param['key']);
  208. // load the contacts (composition)
  209. //////$Contato->contacts_list = $Contato->Contatos();
  210. // load the skills (aggregation)
  211. $skills = $Contato->getContatos();
  212. $skill_list = array();
  213. if ($skills)
  214. {
  215. foreach ($skills as $skill)
  216. {
  217. $skill_list[] = $skill->contato_id;
  218. }
  219. }
  220. $Contato->skill_list = $skill_list;
  221. // fill the form with the active record data
  222. $this->form->setData($Contato);
  223. // close the transaction
  224. TTransaction::close();
  225. }
  226. else
  227. {
  228. $this->form->clear();
  229. }
  230. }
  231. catch (Exception $e) // in case of exception
  232. {
  233. // shows the exception error message
  234. new TMessage('error', '<b>Error</b>' . $e->getMessage());
  235. // undo all pending operations
  236. TTransaction::rollback();
  237. }
  238. }
  239. }
  240. ?>


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


LA

Ola Nilton
mas não encontrei nenhuma ligação no seu codigo com a tabela tipos_contatos.

Tenta assim:
 
  1. <?php
  2. $tipo_contato_id = new ">TDBSeekButton('tipo_contato_id', 'conexao', 'form_contato', 'NomeDoModelDaTabelaTipos', 'descricao_tipo', 'id_tipo', 'tipocontato_nome');
  3. ?>
NP

Luis Alberto bom dia, obrigado pelo retorno.

Na Classe ContatoFormView estou fazendo esta chamada e abaixo segue a classe TipoContatoSeek (tenho duvidas se é somente isso, OK ?)
//--------------------------------------------------------------------------//
//----------[ Aqui é onde se busca o Tipo de Contato ]----------------------//
//--------------------------------------------------------------------------//
$obj = new TipoContatoSeek;
$tipo_contato_id->setAction(new TAction(array($obj, 'onReload')));
//--------------------------------------------------------------------------//

TipoContatoSeek:
 
  1. <?php
  2. /**
  3. * Tipo Contato Search Form
  4. * @author Nilton Prospero
  5. * @copyright Copyright (c) 2016 APMPS-DR. (http://www.apmps.org.br)
  6. */
  7. class TipoContatoSeek extends TWindow
  8. {
  9. private $form; // form
  10. private $datagrid; // datagrid
  11. private $pageNavigation;
  12. private $loaded;
  13. /**
  14. * Class constructor
  15. * Creates the page, the search form and the listing
  16. */
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. parent::setSize(700, 500);
  21. parent::setTitle('Busca Informacao');
  22. new TSession;
  23. // creates the form
  24. $this->form = new TQuickForm('form_search_tpcontato');
  25. $this->form->class = 'tform';
  26. $this->form->setFormTitle('Tipos de Contato');
  27. // create the form fields
  28. $name = new TEntry('name');
  29. $name->setValue(TSession::getValue('tipocontato_nome'));
  30. // add the form fields
  31. $this->form->addQuickField('Name', $name, 300);
  32. // define the form action
  33. $this->form->addQuickAction('Busca', new TAction(array($this, 'onSearch')), 'ico_find.png');
  34. // creates a DataGrid
  35. $this->datagrid = new TQuickGrid;
  36. $this->datagrid->style = 'width: 100%';
  37. $this->datagrid->setHeight(130);
  38. $this->datagrid->enablePopover('Tipo Contato', ' {descricao}');
  39. // creates the datagrid columns
  40. $this->datagrid->addQuickColumn('Id', 'tipo_contato_id', 'right', 40);
  41. $this->datagrid->addQuickColumn('Tipo Contato', 'descricao', 'left', 340);
  42. // creates two datagrid actions
  43. $this->datagrid->addQuickAction('Seleciona', new TDataGridAction(array($this, 'onSelect')), 'tipo_contato_id', 'ico_apply.png');
  44. // create the datagrid model
  45. $this->datagrid->createModel();
  46. // creates the page navigation
  47. $this->pageNavigation = new TPageNavigation;
  48. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  49. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  50. // creates a container
  51. $container = new TVBox;
  52. $container->style = 'width: 100%';
  53. $container->add($this->form);
  54. $container->add($this->datagrid);
  55. $container->add($this->pageNavigation);
  56. // add the container inside the page
  57. parent::add($container);
  58. }
  59. /**
  60. * method onSearch()
  61. * Register the filter in the session when the user performs a search
  62. */
  63. function onSearch()
  64. {
  65. // get the search form data
  66. $data = $this->form->getData();
  67. // check if the user has filled the form
  68. if (isset($data->name))
  69. {
  70. // creates a filter using what the user has typed
  71. $filter = new TFilter('descricao', 'like', "%{$data->name}%");
  72. // stores the filter in the session
  73. TSession::setValue('tpcontato_filter', $filter);
  74. TSession::setValue('tipocontato_nome', $data->name);
  75. // fill the form with data again
  76. $this->form->setData($data);
  77. }
  78. // redefine the parameters for reload method
  79. $param = array();
  80. $param['offset'] = 0;
  81. $param['first_page'] = 1;
  82. $this->onReload($param);
  83. }
  84. /**
  85. * Load the datagrid with the database objects
  86. */
  87. function onReload($param = NULL)
  88. {
  89. try
  90. {
  91. // open a transaction with database 'samples'
  92. TTransaction::open('sgp');
  93. // creates a repository for Tipos de Contato
  94. $repository = new TRepository('TipoContato');
  95. $limit = 10;
  96. // creates a criteria
  97. $criteria = new TCriteria;
  98. // default order
  99. if (!isset($param['order']))
  100. {
  101. $param['order'] = 'tipo_contato_id';
  102. $param['direction'] = 'asc';
  103. }
  104. $criteria->setProperties($param); // order, offset
  105. $criteria->setProperty('limit', $limit);
  106. if (TSession::getValue('tpcontato_filter'))
  107. {
  108. // add the filter stored in the session to the criteria
  109. $criteria->add(TSession::getValue('tpcontato_filter'));
  110. }
  111. // load the objects according to the criteria
  112. $tpcontato = $repository->load($criteria);
  113. $this->datagrid->clear();
  114. if ($tpcontato)
  115. {
  116. foreach ($tpcontato as $tpcontatos)
  117. {
  118. // add the object inside the datagrid
  119. $this->datagrid->addItem($tpcontatos);
  120. }
  121. }
  122. // reset the criteria for record count
  123. $criteria->resetProperties();
  124. $count = $repository->count($criteria);
  125. $this->pageNavigation->setCount($count); // count of records
  126. $this->pageNavigation->setProperties($param); // order, page
  127. $this->pageNavigation->setLimit($limit); // limit
  128. // close the transaction
  129. TTransaction::close();
  130. $this->loaded = true;
  131. }
  132. catch (Exception $e) // in case of exception
  133. {
  134. // shows the exception error message
  135. new TMessage('error', $e->getMessage());
  136. // undo all pending operations
  137. TTransaction::rollback();
  138. }
  139. }
  140. /**
  141. * Executed when the user chooses the record
  142. */
  143. public function onSelect($param)
  144. {
  145. try
  146. {
  147. $key = $param['key'];
  148. TTransaction::open('sgp');
  149. // load the active record
  150. $tipocontato = new TipoContato($key);
  151. // closes the transaction
  152. TTransaction::close();
  153. $object = new StdClass;
  154. $object->tipo_contato_id = $tipocontato->tipo_contato_id;
  155. $object->tipocontato_nome = $tipocontato->descricao;
  156. TForm::sendData('form_contato', $object);
  157. parent::closeWindow(); // close the window
  158. }
  159. catch (Exception $e) // em caso de exceção
  160. {
  161. // clear fields
  162. $object = new StdClass;
  163. $object->tipo_contato_id = '';
  164. $object->tipocontato_nome = '';
  165. TForm::sendData('form_contato', $object);
  166. // undo pending operations
  167. TTransaction::rollback();
  168. }
  169. }
  170. /**
  171. * Shows the page
  172. */
  173. function show()
  174. {
  175. // if the datagrid was not loaded yet
  176. if (!$this->loaded)
  177. {
  178. $this->onReload();
  179. }
  180. parent::show();
  181. }
  182. }
NR

Nilton, crie a seguinte função no model Contato
 
  1. <?php
  2. function get_tipocontato_nome()
  3. {
  4. return $this->get_tipo_contato()->descricao;
  5. }
  6. ?>

Só confirme que a função get_tipo_contato já exista no model Contato.
NP

Nataniel boa noite.

Muito obrigado pela resposta, funcionou direitinho.

Parabéns pelo conhecimento e obrigado pela ajuda

** E obrigado ao Luis Alberto também pela ajuda.

Grande abraço,
Nilton.
RS

desculpa Nataniel e Nilton poderiam me ajudar, estou com este problema com TSeeekButton, creio que é o mesmo B.O , no onEdit não traz o nome_cli fica em branco

 
  1. <?php
  2. $nome_cli = new TEntry('nome_cli');
  3. $nome_cli->setEditable(false);
  4. $cliente_id = new TSeekButton('cliente_id');
  5. $cliente_id->setAction( new TAction(['ClienteSeek', 'onReload']) );
  6. $cliente_id->setAuxiliar($nome_cli);
  7. ?>