EN
TDBSeekButton Customizado para um table
Ola,
Tenho um table montado para meus itens de produtos vendidos, estou tentando alimenta-lo usando um TseekButton, mas não estou conseguindo utilizar ele com variaveis vetor, alguem teria uma luz?
Tenho um table montado para meus itens de produtos vendidos, estou tentando alimenta-lo usando um TseekButton, mas não estou conseguindo utilizar ele com variaveis vetor, alguem teria uma luz?
- <?php
- <?php
- class OServicosViewForm extends TPage {
- private $form;
- /**
- * Constructor
- */
- public function __construct() {
- parent::__construct();
- // create form and table container
- $this->form = new TForm;
- $table = new TTable;
- $table->addSection('thead');
- $table->addRowSet(new TLabel('<b>Prod.ID</b>'), new TLabel('<b>Prod.Descr</b>'), new TLabel('<b>Qtdade</b>'), new TLabel('<b>V.Unit</b>'), new TLabel('<b>Total</b>'));
- $this->form->add($table);
- $table->addSection('tbody');
- $produto_id = new TSeekButton('produto_id[]');
- $produto_id->setSize(120);
- $obj = new ProdutosViewSeek;
- $action = new TAction(array($obj, 'onReload'));
- $produto_id->setAction($action);
- $produto_ds = new TEntry('produto_ds[]');
- $produto_ds->setSize(120);
- $produto_ds->setEditable(false);
- $produto_qt = new TEntry('produto_qt[]');
- $produto_qt->setSize(120);
- $produto_vu = new TEntry('produto_vu[]');
- $produto_vu->setSize(120);
- $produto_tt = new TEntry('produto_tt[]');
- $produto_tt->setSize(120);
- $produto_tt->setEditable(false);
- $this->form->addField($produto_id);
- $this->form->addField($produto_ds);
- $this->form->addField($produto_qt);
- $this->form->addField($produto_vu);
- $this->form->addField($produto_tt);
- // create delete button
- $del = new TImage('fa:trash-o red');
- $del->onclick = 'ttable_remove_row(this)';
- $table->addRowSet($produto_id, $produto_ds, $produto_qt, $produto_vu, $produto_tt, $del);
- // create add button
- $add = new TButton('clone');
- $add->setLabel('Add');
- $add->setImage('fa:plus-circle green');
- $add->addFunction('ttable_clone_previous_row(this)');
- // create save button
- $save = TButton::create('save', array($this, 'onSave'), 'Save', 'fa:save blue');
- $this->form->addField($save);
- // add buttons in table
- $table->addSection('tfoot');
- //$table->addRowSet([$add, $save]);
- $table->addRowSet([$add]);
- //$panel = new TPanelGroup('Manual field list');
- //$panel->add($this->form);
- // wrap the page content using vertical box
- $vbox = new TVBox;
- //$vbox->add($panel);
- $vbox = new TVBox;
- $vbox->add($this->form);
- parent::add($vbox);
- }
- /**
- * Test save
- */
- public static function onSave($param) {
- // show form values inside a window
- $win = TWindow::create('test', 0.6, 0.8);
- $win->add('<pre>' . str_replace("\n", '<br>', print_r($param, true)) . '</pre>');
- $win->show();
- }
- }
- ?>
- <?php
- <?php
- /**
- * City Seek
- *
- * @version 1.0
- * @package samples
- * @subpackage tutor
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class ProdutosViewSeek extends TWindow {
- private $form; // form
- private $datagrid; // datagrid
- private $pageNavigation;
- private $loaded;
- /**
- * Class constructor
- * Creates the page, the search form and the listing
- */
- public function __construct() {
- parent::__construct();
- parent::setSize(700, 500);
- parent::setTitle('Pesquisa Registro');
- new TSession;
- // creates the form
- $this->form = new TQuickForm('form_search_produtos');
- $this->form->class = 'tform';
- $this->form->setFormTitle('Produtos');
- // create the form fields
- $descricao = new TEntry('descricao');
- $descricao->setValue(TSession::getValue('descricao'));
- $this->form->addQuickField('Descrição', $descricao, 200);
- // define the form action
- $this->form->addQuickAction('Pesquisa', new TAction(array($this, 'onSearch')), 'ico_find.png');
- // creates a DataGrid
- $this->datagrid = new TQuickGrid;
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->setHeight(230);
- // creates the datagrid columns
- $this->datagrid->addQuickColumn('Id', 'id', 'right', 40);
- $this->datagrid->addQuickColumn('Descrição', 'descricao', 'left', 340);
- $this->datagrid->addQuickColumn('Valor', 'valor', 'left', 340);
- // creates two datagrid actions
- $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this, 'onSelect')), 'id', 'ico_apply.png');
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // creates a container
- $container = new TVBox;
- $container->style = 'width: 100%';
- $container->add($this->form);
- $container->add($this->datagrid);
- $container->add($this->pageNavigation);
- // add the container inside the page
- parent::add($container);
- }
- /**
- * method onSearch()
- * Register the filter in the session when the user performs a search
- */
- function onSearch() {
- // get the search form data
- $data = $this->form->getData();
- // check if the user has filled the form
- if (isset($data->descricao)) {
- // creates a filter using what the user has typed
- $filter = new TFilter('descricao', 'like', "%{$data->descricao}%");
- // stores the filter in the session
- TSession::setValue('produto_filter', $filter);
- TSession::setValue('descricao', $data->descricao);
- // fill the form with data again
- $this->form->setData($data);
- }
- // redefine the parameters for reload method
- $param = array();
- $param['offset'] = 0;
- $param['first_page'] = 1;
- $this->onReload($param);
- }
- /**
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL) {
- try {
- // open a transaction with database 'samples'
- TTransaction::open('produtos');
- // creates a repository for City
- $repository = new TRepository('Produtos');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- // default order
- if (!isset($param['order'])) {
- $param['order'] = 'id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if (TSession::getValue('produto_filter')) {
- // add the filter stored in the session to the criteria
- $criteria->add(TSession::getValue('produto_filter'));
- }
- // load the objects according to the criteria
- $produtos = $repository->load($criteria);
- $this->datagrid->clear();
- if ($produtos) {
- foreach ($produtos as $produto) {
- // add the object inside the datagrid
- $this->datagrid->addItem($produto);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count = $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- } catch (Exception $e) { // in case of exception
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Executed when the user chooses the record
- */
- public function onSelect($param) {
- try {
- $key = $param['key'];
- TTransaction::open('produtos');
- // load the active record
- $produto = new Produtos($key);
- // closes the transaction
- TTransaction::close();
- $object = new StdClass;
- $object->produto_id[] = $produto->id;
- $object->produto_ds[] = $produto->descricao;
- $object->produto_qt[] = 1;
- $object->produto_vu[] = $produto->valor;
- $object->produto_tt[] = $produto->valor;
- TForm::sendData('form_OServicos', $object);
- parent::closeWindow(); // closes the window
- } catch (Exception $e) { // em caso de exceção
- // clear fields
- $object = new StdClass;
- $object->produto_id = ''; //$produto->id;
- $object->produto_ds = ''; //$produto->descricao;
- $object->produto_qt = ''; //1;
- $object->produto_vu = ''; //$produto->valor;
- $object->produto_tt = ''; //$produto->valor;
- TForm::sendData('form_OServicos', $object);
- // undo pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Shows the page
- */
- function show() {
- // if the datagrid was not loaded yet
- if (!$this->loaded) {
- $this->onReload();
- }
- parent::show();
- }
- }
- ?>
Eduardo, sugiro usar outro componente para isso, veja:
adianti.com.br/framework_files/tutor/index.php?class=SaleMultiValueF
O SeekButton não transmite informações do campo original, por isso fica difícil identificar quais o campos deve preencher em um form vetorial.