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:
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:
- <?php
- /**
- * ContatoFormView
- */
- class ContatoFormView extends TPage
- {
- private $form; // form
-
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new TForm('form_contato');
-
- // creates a table
- $table_data = new TTable;
- $table_telefones = new TTable;
- $table_emails = new TTable;
-
- $notebook = new TNotebook(500, 250);
- // add the notebook inside the form
- $this->form->add($notebook);
-
- $notebook->appendPage('Registrar Dados', $table_data);
- $notebook->appendPage('Contato (telefones)', $table_telefones);
- $notebook->appendPage('Contato (e-mail)', $table_emails);
-
- // create the form fields
- $contato_id = new TEntry('contato_id');
- $tipo_contato_id = new TSeekButton('tipo_contato_id');
- $tipocontato_nome = new TEntry('tipocontato_nome');
- $nome_contato = new TEntry('nome_contato');
- $endereco = new TEntry('endereco');
- $bairro = new TEntry('bairro');
- $cep = new TEntry('cep');
- $cidade = new TEntry('cidade');
- $uf = new TEntry('uf');
- $ponto_referencia = new TEntry('ponto_referencia');
- $observacoes = new TEntry('observacoes');
- $responsavel_id = new TEntry('responsavel_id');
- $dt_inclusao = new TDate('dt_inclusao');
- $status = new TCombo('status');
-
- $telefone_comercial = new TEntry('telefone_comercial');
- $telefone_residencial = new TEntry('telefone_residencial');
- $telefone_contato = new TEntry('telefone_contato');
- $telefone_celular = new TEntry('telefone_celular');
- $telefone_consultorio = new TEntry('telefone_consultorio');
- $email_comercial = new TEntry('email_comercial');
- $email_contato = new TEntry('email_contato');
- $email_particular = new TEntry('email_particular');
-
- $responsavel_id->setValue(TSession::getValue('login')); // Buscar o login do usuario logado - 21/06/2016
- $responsavel_id->setEditable(false);
- /* ---------------------------------------------------------------------------------*/
- $dt_inclusao->setValue( date('Y/m/d', mktime(0, 0, 0, date("m") , date("d"), date("Y")) ));
- $contato_id->setEditable(false);
- $cbo_stat = array();
- $cbo_stat['AT'] = 'Ativo';
- $cbo_stat['IN'] = 'Inativo';
- $cbo_stat['CA'] = 'Cancelado';
- $cbo_stat['EX'] = 'Excluido';
- $status->addItems($cbo_stat);
- $status->setValue('AT');
- /* ---------------------------------------------------------------------------------*/
-
- // add field validators
- $nome_contato->addValidation('Nome Contato', new TRequiredValidator);
- $tipo_contato_id->addValidation('Tipo do Contato', new TRequiredValidator);
-
- //--------------------------------------------------------------------------//
- //----------[ Aqui é onde se busca o Tipo de Contato ]----------------------//
- //--------------------------------------------------------------------------//
- $obj = new TipoContatoSeek;
- $tipo_contato_id->setAction(new TAction(array($obj, 'onReload')));
- //--------------------------------------------------------------------------//
- // define the action for city_id1
- //$obj = new TipoContatoSeek;
- //$action = new TAction(array($obj, 'onReload'));
- //$tipo_contato_id->setAction($action);
- //--------------------------------------------------------------------------//
- // Define o Comprimento e largura
- $contato_id->setSize(40);
- $tipo_contato_id->setSize(50);
- $tipocontato_nome->setSize(327);
- $nome_contato->setSize(400);
- $endereco->setSize(400);
- $bairro->setSize(300);
- $cep->setSize(150);
- $cidade->setSize(400);
- $uf->setSize(40);
- $ponto_referencia->setSize(400);
- $observacoes->setSize(400);
-
- $telefone_comercial->setSize(160);
- $telefone_residencial->setSize(160);
- $telefone_contato->setSize(160);
- $telefone_celular->setSize(160);
- $telefone_consultorio->setSize(160);
- $email_comercial->setSize(300);
- $email_contato->setSize(300);
- $email_particular->setSize(300);
-
- // add a row for the field code
- $table_data->addRowSet(new TLabel('ID:'), $contato_id);
- $table_data->addRowSet(new TLabel('Tipo Contato:'), array($tipo_contato_id, new TLabel('Nome:'),$tipocontato_nome));
- $table_data->addRowSet(new TLabel('Nome Contato:'), $nome_contato);
- $table_data->addRowSet(new TLabel('Endereco:'), array($endereco, new TLabel('Bairro:'), $bairro));
- $table_data->addRowSet(new TLabel('Cidade:'), array($cidade, new TLabel('Cep:'), $cep, new TLabel('UF:'), $uf));
- $table_data->addRowSet(new TLabel('Ponto Referencia:'), $ponto_referencia);
- $table_data->addRowSet(new TLabel('Observacoes:'), $observacoes);
- $table_data->addRowSet(new TLabel('Status:'), $status);
- $contato_id->setEditable(FALSE);
- $tipocontato_nome->setEditable(FALSE);
-
- $row = $table_telefones->addRow();
- $cell = $row->addCell(new TLabel('<b>Numeros de Telefones</b>'));
- $cell->valign = 'top';
-
- // add two fields inside the multifield in the second sheet
- $table_telefones->addRowSet(new TLabel('Comercial:'), $telefone_comercial);
- $table_telefones->addRowSet(new TLabel('Residencial:'), $telefone_residencial);
- $table_telefones->addRowSet(new TLabel('Celular:'), $telefone_celular);
- $table_telefones->addRowSet(new TLabel('Consultorio:'), $telefone_consultorio);
- $table_telefones->addRowSet(new TLabel('Contato:'), $telefone_contato);
- $row = $table_emails->addRow();
- $cell = $row->addCell(new TLabel('<b>E-mails para Contato</b>'));
- $cell->valign = 'top';
-
- // add two fields inside the multifield in the second sheet
- $table_emails->addRowSet(new TLabel('Comercial:'), $email_comercial);
- $table_emails->addRowSet(new TLabel('Particular:'), $email_particular);
- $table_emails->addRowSet(new TLabel('Contato:'), $email_contato);
-
- // create an action button
- $button1=new TButton('button1');
- $button1->setAction(new TAction(array($this, 'onSave')), 'Salvar');
- $button1->setImage('ico_save.png');
-
- // create an action button (go to list)
- $button2=new TButton('button2');
- $button2->setAction(new TAction(array('ContatoDataGridView', 'onReload')), 'Retorna');
- $button2->setImage('ico_datagrid.gif');
-
- $this->form->setFields(array($contato_id, $tipo_contato_id, $tipocontato_nome,
- $nome_contato, $endereco, $bairro, $cep, $cidade,
- $uf, $ponto_referencia, $telefone_comercial, $telefone_residencial,
- $telefone_contato, $telefone_celular, $telefone_consultorio,
- $email_comercial, $email_contato, $email_particular,
- $observacoes, $dt_inclusao, $responsavel_id, $status, $button1, $button2));
- $subtable = new TTable;
- $row = $subtable->addRow();
- $row->addCell($button1);
- $row->addCell($button2);
-
- // wrap the page content
- $vbox = new TVBox;
- $vbox->add(new TXMLBreadCrumb('menu.xml', 'ContatoDataGridView'));
- $vbox->add($this->form);
- $vbox->add($subtable);
-
- // add the form inside the page
- parent::add($vbox);
- }
-
- /**
- * method onSave
- * Executed whenever the user clicks at the save button
- */
- function onSave()
- {
- try
- {
- // open a transaction with database 'sgp'
- TTransaction::open('sgp');
- $this->form->validate();
- // read the form data and instantiates an Active Record
- $Contato = $this->form->getData('Contato');
-
- if ($Contato->contacts_list)
- {
- foreach ($Contato->contacts_list as $contact)
- {
- // add the contact to the Contato
- $Contato->addContact($contact);
- }
- }
-
- if ($Contato->skill_list)
- {
- foreach ($Contato->skill_list as $skill_id)
- {
- // add the skill to the Contato
- $Contato->addSkill(new Skill($skill_id));
- }
- }
- // stores the object in the database
- $Contato->store();
- $this->form->setData($Contato);
-
- // shows the success message
- new TMessage('info', 'Record saved');
-
- TTransaction::close(); // close the transaction
- }
- 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 onEdit
- * Edit a record data
- */
- function onEdit($param)
- {
- try
- {
- if (isset($param['key']))
- {
- // open a transaction with database 'sgp'
- TTransaction::open('sgp');
-
- // load the Active Record according to its ID
- $Contato = new Contato($param['key']);
-
- // load the contacts (composition)
- //////$Contato->contacts_list = $Contato->Contatos();
-
- // load the skills (aggregation)
- $skills = $Contato->getContatos();
- $skill_list = array();
- if ($skills)
- {
- foreach ($skills as $skill)
- {
- $skill_list[] = $skill->contato_id;
- }
- }
- $Contato->skill_list = $skill_list;
-
- // fill the form with the active record data
- $this->form->setData($Contato);
-
- // 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();
- }
- }
- }
- ?>
Ola Nilton
mas não encontrei nenhuma ligação no seu codigo com a tabela tipos_contatos.
Tenta assim:
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:
Nilton, crie a seguinte função no model Contato
Só confirme que a função get_tipo_contato já exista no model Contato.
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.
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