/**
  * Class constructor
  * Creates the page and the registration form
  */
 function __construct()
 {
     parent::__construct();
     parent::setDatabase('esales');
     // defines the database
     parent::setActiveRecord('Pessoa');
     // defines the active record
     // creates the form
     $this->form = new TQuickForm('form_Pessoa');
     $this->form->class = 'tform';
     // CSS class
     $this->form->style = 'width: 500px';
     // define the form title
     $this->form->setFormTitle('Pessoa');
     // create the form fields
     $id = new TEntry('id');
     $nome = new TEntry('nome');
     $telefone = new TEntry('telefone');
     $email = new TEntry('email');
     $endereco = new TEntry('endereco');
     $numero = new TEntry('numero');
     $cidade_id = new TSeekButton('cidade_id');
     $cidade_id->addValidation('Cidade', new TRequiredValidator());
     $cidade_name = new TEntry('cidade_name');
     $obj = new TStandardSeek();
     $action = new TAction(array($obj, 'onSetup'));
     $action->setParameter('database', 'esales');
     $action->setParameter('parent', 'form_Pessoa');
     $action->setParameter('model', 'Cidade');
     $action->setParameter('display_field', 'descricao');
     $action->setParameter('receive_key', 'cidade_id');
     $action->setParameter('receive_field', 'cidade_name');
     $cidade_id->setAction($action);
     $cep = new TEntry('cep');
     $cpf_cnpj = new TEntry('cpf_cnpj');
     $tipo_pessoa = new TRadioGroup('tipo_pessoa');
     $tipo_pessoa->addItems(array('F' => 'Fisica', 'J' => 'Juridica'));
     // add the fields
     $this->form->addQuickField('Codigo', $id, 100);
     $this->form->addQuickField('Nome', $nome, 200);
     $this->form->addQuickField('Telefone', $telefone, 200);
     $this->form->addQuickField('Email', $email, 200);
     $this->form->addQuickField('Endereço', $endereco, 200);
     $this->form->addQuickField('Numero', $numero, 200);
     $this->form->addQuickFields('Cidade', array($cidade_id, $cidade_name), true);
     $this->form->addQuickField('CEP', $cep, 200);
     $this->form->addQuickField('CPF/CNPJ', $cpf_cnpj, 100);
     $this->form->addQuickField('Tipo de pessoa', $tipo_pessoa, 200);
     // create the form actions
     $this->form->addQuickAction('Salvar', new TAction(array($this, 'onSave')), 'ico_save.png');
     $this->form->addQuickAction('Novo', new TAction(array($this, 'onEdit')), 'ico_new.png');
     // add the form to the page
     parent::add($this->form);
 }
 /**
  * Class constructor
  * Creates the page and the registration form
  */
 function __construct()
 {
     parent::__construct();
     // creates the form
     $this->form = new TForm('form_customer');
     // creates a table
     $table_data = new TTable();
     $table_contact = new TTable();
     $table_skill = new TTable();
     $notebook = new TNotebook(500, 250);
     // add the notebook inside the form
     $this->form->add($notebook);
     $notebook->appendPage('Registration Data', $table_data);
     $notebook->appendPage('Contact (composition)', $table_contact);
     $notebook->appendPage('Skill (aggregation)', $table_skill);
     // create the form fields
     $code = new TEntry('id');
     $name = new TEntry('name');
     $address = new TEntry('address');
     $phone = new TEntry('phone');
     $city_id = new TSeekButton('city_id');
     $city_name = new TEntry('city_name');
     $birthdate = new TDate('birthdate');
     $email = new TEntry('email');
     $gender = new TRadioGroup('gender');
     $status = new TCombo('status');
     $contacts_list = new TMultiField('contacts_list');
     $category_id = new TDBCombo('category_id', 'samples', 'Category', 'id', 'name');
     // add field validators
     $name->addValidation('Name', new TRequiredValidator());
     $city_id->addValidation('City', new TRequiredValidator());
     $birthdate->addValidation('Birthdate', new TRequiredValidator());
     $category_id->addValidation('Category', new TRequiredValidator());
     $obj = new CitySeek();
     $city_id->setAction(new TAction(array($obj, 'onReload')));
     $itemGender = array();
     $itemGender['M'] = 'Male';
     $itemGender['F'] = 'Female';
     // add the combo options
     $gender->addItems($itemGender);
     $gender->setLayout('horizontal');
     $itemStatus = array();
     $itemStatus['S'] = 'Single';
     $itemStatus['C'] = 'Committed';
     $itemStatus['M'] = 'Married';
     $status->addItems($itemStatus);
     // define some properties for the form fields
     $code->setEditable(FALSE);
     $code->setSize(100);
     $city_id->setSize(100);
     $city_name->setSize(150);
     $city_name->setEditable(FALSE);
     $name->setSize(320);
     $address->setSize(320);
     $phone->setSize(120);
     $email->setSize(160);
     $birthdate->setSize(90);
     $status->setSize(120);
     $category_id->setSize(120);
     // add a row for the field code
     $table_data->addRowSet(new TLabel('Code:'), $code);
     $table_data->addRowSet(new TLabel('Name:'), $name);
     $table_data->addRowSet(new TLabel('Address:'), $address);
     $table_data->addRowSet(new TLabel('City:'), array($city_id, new TLabel('Name:'), $city_name));
     $table_data->addRowSet(new TLabel('Phone:'), array($phone, new TLabel('BirthDate:'), $birthdate));
     $table_data->addRowSet(new TLabel('Status:'), array($status, new TLabel('Email:'), $email));
     $table_data->addRowSet(new TLabel('Category:'), array($category_id, new TLabel('Gender:'), $gender));
     $row = $table_contact->addRow();
     $cell = $row->addCell(new TLabel('<b>Contact</b>'));
     $cell->valign = 'top';
     // add two fields inside the multifield in the second sheet
     $contacts_list->setHeight(100);
     $contacts_list->setClass('Contact');
     // define the returning class
     $contacts_list->addField('type', 'Contact Type: ', new TEntry('type'), 200);
     $contacts_list->addField('value', 'Contact Value: ', new TEntry('value'), 200);
     $row = $table_contact->addRow();
     $row->addCell($contacts_list);
     // create the radio button for the skills list
     $skill_list = new TDBCheckGroup('skill_list', 'samples', 'Skill', 'id', 'name');
     $table_skill->addRow()->addCell($lbl = new TLabel('Skills'));
     $table_skill->addRow()->addCell($skill_list);
     $lbl->setFontStyle('b');
     // create an action button
     $button1 = new TButton('action1');
     $button1->setAction(new TAction(array($this, 'onSave')), 'Save');
     $button1->setImage('ico_save.png');
     // create an action button (go to list)
     $button2 = new TButton('list');
     $button2->setAction(new TAction(array('CustomerDataGridView', 'onReload')), 'Go to Listing');
     $button2->setImage('ico_datagrid.gif');
     // define wich are the form fields
     $this->form->setFields(array($code, $name, $address, $phone, $city_id, $city_name, $birthdate, $email, $gender, $status, $category_id, $contacts_list, $skill_list, $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', 'CustomerDataGridView'));
     $vbox->add($this->form);
     $vbox->add($subtable);
     // add the form inside the page
     parent::add($vbox);
 }