LJ
Meu Form não vai para a funcao onSearch !!!
Pessoal , estou com muita dificuldade nesta pagina. criei um form e tambem uma página com replace html.
quero que ao clicar no botao Buscar, ele vá para a função onSearch.
Outro erro que acontece é que a imagem do evento esta aparecendo 2x quando vou para a proxima pagina do pageNavigation.
quero que ao clicar no botao Buscar, ele vá para a função onSearch.
Outro erro que acontece é que a imagem do evento esta aparecendo 2x quando vou para a proxima pagina do pageNavigation.
- <?php
- class FrontCategoria extends TPage
- {
- /**
- * Constructor method
- */
- //public $busca;
- private $html;
- private $pageNavigation;
- private $form;
- public function __construct()
- {
- parent::__construct();
- // load the styles
- TPage::include_css('app/resources/css/animate.css');
- TPage::include_css('app/resources/css/bootstrap.min.css');
- TPage::include_js('app/resources/js/jquery-2.2.0.min.js');
- TPage::include_js('app/resources/js/bootstrap.min.js');
- TPage::include_js('app/resources/js/wow.min.js');
- TPage::include_css('app/resources/categoria.css');
- $this->form = new TQuickForm;
- $this->form->class = 'tform';
- $this->form->setFormTitle('Evento');
- // create the form fields
- $nome = new TEntry('nome');
- $dataevento = new TDate('dataevento');
- $busca = new TEntry('busca');
- //$imagem->setEditable( FALSE );
- $nome->setEditable( FALSE );
- $dataevento->setEditable( FALSE );
- $this->frame = new TElement('div');
- $this->frame->id = 'photo_frame';
- $this->frame->style = 'width:140px;height:auto;min-height:140px;border:1px solid gray;padding:4px;';
- $row = $this->form->addRow();
- $row->addCell('');
- $row->addCell($this->frame);
- $this->form->addQuickField('Nome', $nome, 200);
- $this->form->addQuickField('Data', $dataevento, 100);
- $this->form->addQuickField('Número de Peito', $busca, 100);
- // define the form action
- $this->form->addQuickAction('Buscar', new TAction(array($this, 'onSearch')), 'fa:check-circle-o green');
- // create the HTML Renderer
- $this->html = new THtmlRenderer('app/resources/categoria.html');
- // define replacements for the main section
- // Produtos
- $replace = array();
- $this->html->enableSection('main', $replace);
- $this->enableManagement();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->add($this->form);
- $vbox->add($this->html);
- $vbox->add($this->pageNavigation);
- parent::add($vbox);
- }
- /**
- * Enable or not the 'manage' section
- */
- public function enableManagement()
- {
- if (is_array(TSession::getValue('cart_items')) AND count(TSession::getValue('cart_items')) > 0)
- {
- $this->html->enableSection('manage');
- }
- }
- /**
- * Executed when the user clicks at click to buy button
- */
- public function onComprar( $param )
- {
- $cart_items = TSession::getValue('cart_items');
- $i=count($cart_items);
- $cart_items[$i]['produto_id'] = $param['produto_id'] ;
- $cart_items[$i]['preco_id'] = $param['preco_id'] ;
- TSession::setValue('cart_items', $cart_items);
- new TMessage('info','Voce inseriu um produto no carrinho de compras');
- //$i++;
- $this->enableManagement();
- // acrescentar no carrinho visual
- }
- function onEdit( $param )
- {
- TSession::setValue('categoria', $param['key']);
- }
- /**
- * Fill the html template with objects
- */
- public function onReload( $param = NULL )
- {
- try
- {
- $limit = 16;
- // recarrega o form
- TTransaction::open('ecommerce');
- $categoria= new Categoria(TSession::getValue('categoria'));
- $categoria->dataevento = TDate::date2br($categoria->dataevento);
- if ((isset($param['busca'])) AND ($param['busca'])){
- $filter = new TFilter('busca', 'like', "%-{$param['busca']}-%");
- TSession::setValue('busca_filter1', $filter);
- $busca = TSession::setValue('busca', $param['busca']);
- new TMessage('info','118');
- }else{
- TSession::setValue('busca_filter1', NULL);
- $busca = TSession::setValue('busca', '');
- }
- $obj = new stdClass();
- $obj->dataevento = $categoria->dataevento;
- $obj->nome = $categoria->nome;
- $obj->busca = $busca;
- $this->form->setData($obj);
- if ($categoria)
- {
- $imagem = new TImage($categoria->imagem);
- $imagem->style = 'width: 100%';
- $this->frame->add($imagem);
- }
- // recareca a pagina dos produtos
- $criteria = new TCriteria;
- $criteria->add(new TFilter('categoria_id','=',TSession::getValue('categoria')));
- if (TSession::getValue('busca_filter1'))
- {
- $criteria->add(TSession::getValue('busca_filter1'));
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- $produtos_todos = Produto::getObjects($criteria);
- $criteria->resetProperties(); // reset the criteria for record count
- $count= Produto::countObjects($criteria);
- $replace = array();
- if($produtos_todos)
- {
- $i=0;
- foreach ($produtos_todos as $produto_categoria)
- {
- $replace['produto'][$i]['id']= $produto_categoria->id;
- $replace['produto'][$i]['imagem']= $produto_categoria->imagem;
- //programar nome da corrida
- $replace['produto'][$i]['evento']= 'nome da corrida';
- $precos = $produto_categoria->getPrecos();
- $x=0;
- foreach ($precos as $preco)
- {
- $replace['produto'][$i]['preco'][$x]['id']= $produto_categoria->id;
- $replace['produto'][$i]['preco'][$x]['preco_id']=$preco->id;
- $replace['produto'][$i]['preco'][$x]['valor']=' R$ '.$preco->preco.' Tamanho: '.$preco->tamanho;
- $x++;
- }
- $i++;
- }
- TTransaction::close();
- }
- // replace the main section variables
- $this->html->enableSection('main', $replace);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- }
- }
- /**
- * Simulates an save button
- * Show the form content
- */
- function onSearch()
- {
- new TMessage('info','linha 210');
- $data = $this->form->getData(); // optional parameter: active record class
- // put the data back to the form
- //$this->form->setData($data);
- }
- public function show()
- {
- $this->onReload( func_get_arg(0) );
- parent::show();
- }
- }
- ?>
Criei uma classe ProductCatalogView2 , da mesma maneira que pretendo fazer acima e funciona, porem no meu exemplo nao funciona, podem colocar esta nova classe dentro do tutor que vai funcionar.
Ufa, Resolvido, fui substituindo os códigos e acabou funcionando.
quanto a imagem que aparecia 2 x , peguei um código meu antigo e deu certo.