Cadastro de clientes - não consigo criar aba contatos Boa noite, estou estudando o sistema e agora estou fazendo uma tela de cadastro de clientes, porém não consigo colocar a aba contatos, estou me baseando no exemplos do tutor. segue como fica a tela e o codigo: ...
WF
Cadastro de clientes - não consigo criar aba contatos  
Boa noite, estou estudando o sistema e agora estou fazendo uma tela de cadastro de clientes, porém não consigo colocar a aba contatos, estou me baseando no exemplos do tutor.

segue como fica a tela e o codigo:

 
  1. <?php
  2. /**
  3. * cadastro_unidade Form
  4. * @author <your name here>
  5. */
  6. class cadastro_unidade extends TPage
  7. {
  8. //protected $form; // form
  9. private $form; // form
  10. private $contacts;
  11. /**
  12. * Form constructor
  13. * @param $param Request
  14. */
  15. public function __construct( $param )
  16. {
  17. parent::__construct();
  18. // creates the form
  19. $this->form = new BootstrapFormBuilder('form_unidade');
  20. $this->form->setFormTitle('unidade');
  21. $this->form->setFieldSizes('100%');
  22. // Campos da Aba Endereco
  23. $this->form->appendPage('Endereço');
  24. // create the form fields
  25. $id = new TEntry('id');
  26. $siglaunidade = new TEntry('siglaunidade');
  27. $rzsocial = new TEntry('rzsocial');
  28. $nomefantasia = new TEntry('nomefantasia');
  29. $email = new TEntry('email');
  30. $telefone = new TEntry('telefone');
  31. $telefoneadm = new TEntry('telefoneadm');
  32. $cep = new TEntry('cep');
  33. $endereco = new TEntry('endereco');
  34. $numero = new TEntry('numero');
  35. $complemento = new TEntry('complemento');
  36. $uf = new TEntry('uf');
  37. $cidade = new TEntry('cidade');
  38. $bairro = new TEntry('bairro');
  39. $cnae = new TEntry('cnae');
  40. // add the fields
  41. $row = $this->form->addFields( [ new TLabel('Código'), $id ],
  42. [ new TLabel('Sigla da Unidade'), $siglaunidade ],
  43. [ new TLabel('Razão Social'), $rzsocial ] );
  44. $row->layout = ['col-sm-2', 'col-sm-4', 'col-sm-6' ];
  45. $row = $this->form->addFields( [ new TLabel('Nome Fantasia'), $nomefantasia ],
  46. [ new TLabel('Email'), $email ] );
  47. $row->layout = ['col-sm-6', 'col-sm-6' ];
  48. $row = $this->form->addFields( [ new TLabel('Telefone 1'), $telefone ],
  49. [ new TLabel('Telefone 2'), $telefoneadm ] );
  50. $row->layout = ['col-sm-6', 'col-sm-6' ];
  51. $row = $this->form->addFields( [ new TLabel('CEP'), $cep ],
  52. [ new TLabel('Endereço'), $endereco ],
  53. [ new TLabel('Número'), $numero ] );
  54. $row->layout = ['col-sm-3', 'col-sm-6', 'col-sm-3' ];
  55. $row = $this->form->addFields( [ new TLabel('Complemento'), $complemento ],
  56. [ new TLabel('U.F'), $uf ] );
  57. $row->layout = ['col-sm-9', 'col-sm-3' ];
  58. $row = $this->form->addFields( [ new TLabel('Cidade'), $cidade ],
  59. [ new TLabel('Bairro'), $bairro ],
  60. [ new TLabel('CNAE'), $cnae ] );
  61. $row->layout = ['col-sm-3', 'col-sm-6', 'col-sm-3' ];
  62. // Campos da aba Documentos
  63. $this->form->appendPage('Documentos');
  64. // create the form fields
  65. $cnpj = new TEntry('cnpj');
  66. $ie = new TEntry('ie');
  67. $im = new TEntry('im');
  68. $portedaempresa = new TEntry('portedaempresa');
  69. $emitedocfiscal = new TCombo('emitedocfiscal');
  70. $optasn = new TCombo('optasn');
  71. //Campo Simples Nacional
  72. $itemoptasn = array();
  73. $itemoptasn ['Sim']='Sim';
  74. $itemoptasn ['Não']='Não';
  75. $optasn->addItems($itemoptasn);
  76. //Campo emite documento fiscal
  77. $itememitedocfiscal = array();
  78. $itememitedocfiscal ['Sim']='Sim';
  79. $itememitedocfiscal ['Não']='Não';
  80. $emitedocfiscal->addItems($itememitedocfiscal);
  81. // Exibe os campos da aba documentos
  82. $row = $this->form->addFields( [ new TLabel('CNPJ'), $cnpj ],
  83. [ new TLabel('I.E'), $ie ],
  84. [ new TLabel('I.M'), $im ] );
  85. $row->layout = ['col-sm-4', 'col-sm-4', 'col-sm-4' ];
  86. $row = $this->form->addFields( [ new TLabel('Porte da Empresa'), $portedaempresa ],
  87. [ new TLabel('Emite documento fiscal?'),$emitedocfiscal ],
  88. [ new TLabel('Optante do Simples?'), $optasn ] );
  89. $row->layout = ['col-sm-4', 'col-sm-4', 'col-sm-4' ];
  90. //$this->form->appendPage('Skills');
  91. //$skill_list = new TDBCheckGroup('skill_list', 'samples', 'Skill', 'id', 'name');
  92. //$this->form->addFields( [ new TLabel('Skill') ], [ $skill_list ] );
  93. //validação de campos
  94. $siglaunidade->addValidation('Sigla da unidade', new TRequiredValidator);
  95. $siglaunidade->addValidation('Sigla da unidade', new TMaxLengthValidator,array(10));
  96. $rzsocial ->addValidation('Razão Social', new TRequiredValidator);
  97. $nomefantasia->addValidation('Nome Fantasia', new TRequiredValidator);
  98. $cnpj ->addValidation('CNPJ', new TCNPJValidator);
  99. $email ->addValidation('E-mail', new TEmailValidator);
  100. $cep ->addValidation('C.E.P', new TRequiredValidator);
  101. $endereco ->addValidation('Endereço', new TRequiredValidator);
  102. $numero ->addValidation('Número', new TRequiredValidator);
  103. $numero ->addValidation('Número', new TMaxLengthValidator,array(10));
  104. $uf ->addValidation('U.F', new TRequiredValidator);
  105. $uf ->addValidation('U.F', new TMaxLengthValidator,array(2));
  106. $cidade ->addValidation('Cidade', new TRequiredValidator);
  107. $bairro ->addValidation('Bairro', new TRequiredValidator);
  108. $portedaempresa->addValidation('Porte da empresa', new TRequiredValidator);
  109. $portedaempresa->addValidation('Porte da empresa', new TMaxLengthValidator,array(10));
  110. $emitedocfiscal->addValidation('Emite documento fiscal', new TRequiredValidator);
  111. $optasn ->addValidation('Optante do Simples Nacional', new TRequiredValidator);
  112. if (!empty($id))
  113. {
  114. $id->setEditable(FALSE);
  115. }
  116. /** samples
  117. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  118. $fieldX->setSize( '100%' ); // set size
  119. **/
  120. $this->form->appendPage('Contacts');
  121. $contact_type = new TEntry('contact_type[]');
  122. $contact_type->setSize('100%');
  123. $contact_value = new TEntry('contact_value[]');
  124. $contact_value->setSize('100%');
  125. $this->contacts = new TFieldList;
  126. $this->contacts->addField( '<b>Type</b>', $contact_type, ['width' => '50%']);
  127. $this->contacts->addField( '<b>Value</b>', $contact_value, ['width' => '50%']);
  128. $this->form->addField($contact_type);
  129. $this->form->addField($contact_value);
  130. $this->contacts->enableSorting();
  131. $this->form->addContent( [ new TLabel('Contacts') ], [ $this->contacts ] );
  132. // create the form actions
  133. $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
  134. $btn->class = 'btn btn-sm btn-primary';
  135. $this->form->addAction(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
  136. // vertical box container
  137. $container = new TVBox;
  138. $container->style = 'width: 90%';
  139. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  140. $container->add($this->form);
  141. parent::add($container);
  142. }
  143. /**
  144. * Save form data
  145. * @param $param Request
  146. */
  147. public function onSave( $param )
  148. {
  149. try
  150. {
  151. TTransaction::open('banco'); // open a transaction
  152. /**
  153. // Enable Debug logger for SQL operations inside the transaction
  154. TTransaction::setLogger(new TLoggerSTD); // standard output
  155. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  156. **/
  157. $this->form->validate(); // validate form data
  158. $data = $this->form->getData(); // get form data as array
  159. $object = new unidade; // create an empty object
  160. $object->fromArray( (array) $data); // load the object with data
  161. $object->store(); // save the object
  162. // get the generated id
  163. $data->id = $object->id;
  164. $this->form->setData($data); // fill form data
  165. TTransaction::close(); // close the transaction
  166. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  167. }
  168. catch (Exception $e) // in case of exception
  169. {
  170. new TMessage('error', $e->getMessage()); // shows the exception error message
  171. $this->form->setData( $this->form->getData() ); // keep form data
  172. TTransaction::rollback(); // undo all pending operations
  173. }
  174. }
  175. /**
  176. * Clear form data
  177. * @param $param Request
  178. */
  179. public function onClear( $param )
  180. {
  181. $this->form->clear(TRUE);
  182. }
  183. /**
  184. * Load object to form data
  185. * @param $param Request
  186. */
  187. public function onEdit( $param )
  188. {
  189. try
  190. {
  191. if (isset($param['key']))
  192. {
  193. $key = $param['key']; // get the parameter $key
  194. TTransaction::open('banco'); // open a transaction
  195. $object = new unidade($key); // instantiates the Active Record
  196. $this->form->setData($object); // fill the form
  197. TTransaction::close(); // close the transaction
  198. }
  199. else
  200. {
  201. $this->form->clear(TRUE);
  202. }
  203. }
  204. catch (Exception $e) // in case of exception
  205. {
  206. new TMessage('error', $e->getMessage()); // shows the exception error message
  207. TTransaction::rollback(); // undo all pending operations
  208. }
  209. }
  210. }

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)


JS

Wempar Ferreira,

Adicione este código no método onClear

$this->contacts->addHeader();

$this->contacts->addDetail( new stdClass );

$this->contacts->addCloneAction();
WF

Entendi o que esta faltando, obrigado.