WS
Botão de busca abrir TInputDialog
Fechado
Bom dia Galera eu tenho o seguinte código:
Nessa listagem ele mostra dois campo para efetuar uma busca rápida, preciso fazer com quem eu tenho um botão chamado (BUSCAR) ao clicar no botão buscar ele irá abrir um TWindow ou um TInputDialog e irá mostrar o formulário de busca que esta em anexo, depois que o usuário buscar ele fechará esse Twindow ou Dialog e irá mostrar o resultado na página FinBancoList... Alguém pode me ajudar ??... desde já agradeço..
Sky: willian.tecnologia@hotmail.com
- <?php
- /**
- * FinBancoList2 Listing
- * @author <your name here>
- */
- class FinBancoList extends TPage
- {
- private $form; // form
- private $datagrid; // listing
- private $pageNavigation;
- private $formgrid;
- private $loaded;
- private $deleteButton;
-
- /**
- * Class constructor
- * Creates the page, the form and the listing
- */
- public function __construct()
- {
- parent::__construct();
-
- // creates the form
- $this->form = new TQuickForm('form_search_FinBanco');
- $this->form->class = 'tform'; // change CSS class
- $this->form = new BootstrapFormWrapper($this->form);
- $this->form->style = 'display: table;width:100%'; // change style
- $this->form->setFormTitle('FinBanco');
-
- // create the form fields
- 2420 = new TEntry('id');
- $nome = new TEntry('nome');
- // add the fields
- $this->form->addQuickField('Id', 2420, 200 );
- $this->form->addQuickField('Nome', $nome, 100 );
-
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue('FinBanco_filter_data') );
-
- // add the search form actions
- $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
- $this->form->addQuickAction(_t('New'), new TAction(array('FinBancoForm', 'onEdit')), 'bs:plus-sign green');
-
- // creates a Datagrid
- $this->datagrid = new TDataGrid;
- $this->datagrid = new BootstrapDatagridWrapper($this->datagrid);
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->setHeight(320);
- // $this->datagrid->datatable = 'true';
- // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
-
- // creates the datagrid columns
- $column_id = new TDataGridColumn('id', 'Id', 'right');
- $column_nome = new TDataGridColumn('nome', 'Nome', 'left');
- $column_numero = new TDataGridColumn('numero', 'Numero', 'left');
- $column_site = new TDataGridColumn('site', 'Site', 'left');
- // add the columns to the DataGrid
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_nome);
- $this->datagrid->addColumn($column_numero);
- $this->datagrid->addColumn($column_site);
-
- // create EDIT action
- $action_edit = new TDataGridAction(array('FinBancoForm', 'onEdit'));
- $action_edit->setUseButton(TRUE);
- $action_edit->setButtonClass('btn btn-default');
- $action_edit->setLabel(_t('Edit'));
- $action_edit->setImage('fa:pencil-square-o blue fa-lg');
- $action_edit->setField('id');
- $this->datagrid->addAction($action_edit);
-
- // create DELETE action
- $action_del = new TDataGridAction(array($this, 'onDelete'));
- $action_del->setUseButton(TRUE);
- $action_del->setButtonClass('btn btn-default');
- $action_del->setLabel(_t('Delete'));
- $action_del->setImage('fa:trash-o red fa-lg');
- $action_del->setField('id');
- $this->datagrid->addAction($action_del);
-
- // 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());
-
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add(TPanelGroup::pack('Title', $this->form));
- $container->add($this->datagrid);
- $container->add($this->pageNavigation);
-
- parent::add($container);
- }
-
- /**
- * Inline record editing
- * @param $param Array containing:
- * key: object ID value
- * field name: object attribute to be updated
- * value: new attribute content
- */
- public function onInlineEdit($param)
- {
- try
- {
- // get the parameter $key
- $field = $param['field'];
- $key = $param['key'];
- $value = $param['value'];
-
- TTransaction::open('educacional'); // open a transaction with database
- $object = new FinBanco($key); // instantiates the Active Record
- $object->{$field} = $value;
- $object->store(); // update the object in the database
- TTransaction::close(); // close the transaction
-
- $this->onReload($param); // reload the listing
- new TMessage('info', "Record Updated");
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
-
- /**
- * Register the filter in the session
- */
- public function onSearch()
- {
- // get the search form data
- $data = $this->form->getData();
-
- // clear session filters
- TSession::setValue('FinBancoList_filter_id', NULL);
- TSession::setValue('FinBancoList_filter_nome', NULL);
- if (isset($data->id) AND ($data->id)) {
- $filter = new TFilter('id', '=', "$data->id"); // create the filter
- TSession::setValue('FinBancoList_filter_id', $filter); // stores the filter in the session
- }
- if (isset($data->nome) AND ($data->nome)) {
- $filter = new TFilter('nome', 'like', "%{$data->nome}%"); // create the filter
- TSession::setValue('FinBancoList_filter_nome', $filter); // stores the filter in the session
- }
-
- // fill the form with data again
- $this->form->setData($data);
-
- // keep the search data in the session
- TSession::setValue('FinBanco_filter_data', $data);
-
- $param=array();
- $param['offset'] =0;
- $param['first_page']=1;
- $this->onReload($param);
- }
-
- /**
- * Load the datagrid with data
- */
- public function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'educacional'
- TTransaction::open('educacional');
-
- // creates a repository for FinBanco
- $repository = new TRepository('FinBanco');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
-
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
-
- if (TSession::getValue('FinBancoList_filter_id')) {
- $criteria->add(TSession::getValue('FinBancoList_filter_id')); // add the session filter
- }
- if (TSession::getValue('FinBancoList_filter_nome')) {
- $criteria->add(TSession::getValue('FinBancoList_filter_nome')); // add the session filter
- }
-
- // load the objects according to criteria
- $objects = $repository->load($criteria, FALSE);
-
- if (is_callable($this->transformCallback))
- {
- call_user_func($this->transformCallback, $objects, $param);
- }
-
- $this->datagrid->clear();
- if ($objects)
- {
- // iterate the collection of active records
- foreach ($objects as $object)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
-
- // 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();
- }
- }
-
- /**
- * Ask before deletion
- */
- public function onDelete($param)
- {
- // define the delete action
- $action = new TAction(array($this, 'Delete'));
- $action->setParameters($param); // pass the key parameter ahead
-
- // shows a dialog to the user
- new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
-
- /**
- * Delete a record
- */
- public function Delete($param)
- {
- try
- {
- $key=$param['key']; // get the parameter $key
- TTransaction::open('educacional'); // open a transaction with database
- $object = new FinBanco($key, FALSE); // instantiates the Active Record
- $object->delete(); // deletes the object from the database
- TTransaction::close(); // close the transaction
- $this->onReload( $param ); // reload the listing
- new TMessage('info', AdiantiCoreTranslator::translate('Record deleted')); // success message
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
-
-
- /**
- * method show()
- * Shows the page
- */
- public function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
- {
- if (func_num_args() > 0)
- {
- $this->onReload( func_get_arg(0) );
- }
- else
- {
- $this->onReload();
- }
- }
- parent::show();
- }
- }
- ?>
Nessa listagem ele mostra dois campo para efetuar uma busca rápida, preciso fazer com quem eu tenho um botão chamado (BUSCAR) ao clicar no botão buscar ele irá abrir um TWindow ou um TInputDialog e irá mostrar o formulário de busca que esta em anexo, depois que o usuário buscar ele fechará esse Twindow ou Dialog e irá mostrar o resultado na página FinBancoList... Alguém pode me ajudar ??... desde já agradeço..
Sky: willian.tecnologia@hotmail.com
Willian, faça com que a ação do botão de busca da TWindow chame a função onSearch da classe pai. Depois modifique a onSearch, ficando mais ou menos parecida com isso:
Nataniel, funcionou do jeito que você me passou, muito simples. Olha só eu criei o código>
Ao clicar no botão buscar ele abre essa TWindow, no TWindow ele tem os campos nomes que depois fazem a busca entrando nesse metodo que você me passou e na página PAI ele mostra o conteúdo filtrado, porém ele esta ficando com o TWindow aberto. Tente colocar o
Mudei o código para ficar assim:
no OnSearch peço para fechar o window :
Mais na verdade ele joga o código do OnFilter para dentro da página PAI.
Sim Willian, sua lógica está correta, mas o TWindow quando criado através da função create tem um comportamento diferenciado e não é afetado pela função closeWindow.
Você pode utilizar o TInputDialog no lugar e assim a janela automaticamente será fechada ao clicar no botão de busca ou pode alterar a parte final do seu código, adicionando javascript para fechar a janela:
Mais esse comando setTimeout eu coloco um tempo pra ele ficar aberto.
Serio que o Twindow não tem como fecha-lo?...
Willian, para fechar o TWindow criado pela função create é aquele código que postei acima. O setTimeout nesse caso é necessário para que a janela não seja fechada antes dos dados do formulário serem capturados e enviados para a janela pai. Se quiser testar aí, pode retirar o setTimeout e deixar só :
Você vai ver que a janela será fechada, mas os dados do formulário de busca não serão enviados para o formulário pai e a busca não será executada.
Estou quase xingando já, não consegui pegar a lógica ainda. Vou colocar todo meu código aqui:
Já pedir 2 dias com isso e to ficando de cara comigo mesmo jah, na minha lógica, ao carregar esse código tem o botão FIND que vai para o onFilter, esse onFilter é o responsável por abrir o TWINDOW, depois ele chama o onSearch que faz o processo de busca dentro do banco pelo TFILTER, pergunto: o que tenho que fazer dentro desse código para que essa &&¨$@# de TWINDOWS venha a fechar.
Me desculpa pelo nervoso, é que ta me tirando do sério...rsrs..
Desde de já agradeço...</Willian>
Nataniel você é o cara, muito obrigado pela dica, eu já tinha mudando para o inputDialog....rsrs... mais voltei ao TWINDOW...
VLw..
Se tiver skype add ai: willian.tecnologia@hotmail.com
Abraços..