Botão de busca abrir TInputDialog Bom dia Galera eu tenho o seguinte código: ...
WS
Botão de busca abrir TInputDialog  
Fechado
Bom dia Galera eu tenho o seguinte código:
 
  1. <?php
  2. /**
  3. * FinBancoList2 Listing
  4. * @author <your name here>
  5. */
  6. class FinBancoList extends TPage
  7. {
  8. private $form; // form
  9. private $datagrid; // listing
  10. private $pageNavigation;
  11. private $formgrid;
  12. private $loaded;
  13. private $deleteButton;
  14. /**
  15. * Class constructor
  16. * Creates the page, the form and the listing
  17. */
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. // creates the form
  22. $this->form = new TQuickForm('form_search_FinBanco');
  23. $this->form->class = 'tform'; // change CSS class
  24. $this->form = new BootstrapFormWrapper($this->form);
  25. $this->form->style = 'display: table;width:100%'; // change style
  26. $this->form->setFormTitle('FinBanco');
  27. // create the form fields
  28. 2420 = new TEntry('id');
  29. $nome = new TEntry('nome');
  30. // add the fields
  31. $this->form->addQuickField('Id', 2420, 200 );
  32. $this->form->addQuickField('Nome', $nome, 100 );
  33. // keep the form filled during navigation with session data
  34. $this->form->setData( TSession::getValue('FinBanco_filter_data') );
  35. // add the search form actions
  36. $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  37. $this->form->addQuickAction(_t('New'), new TAction(array('FinBancoForm', 'onEdit')), 'bs:plus-sign green');
  38. // creates a Datagrid
  39. $this->datagrid = new TDataGrid;
  40. $this->datagrid = new BootstrapDatagridWrapper($this->datagrid);
  41. $this->datagrid->style = 'width: 100%';
  42. $this->datagrid->setHeight(320);
  43. // $this->datagrid->datatable = 'true';
  44. // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  45. // creates the datagrid columns
  46. $column_id = new TDataGridColumn('id', 'Id', 'right');
  47. $column_nome = new TDataGridColumn('nome', 'Nome', 'left');
  48. $column_numero = new TDataGridColumn('numero', 'Numero', 'left');
  49. $column_site = new TDataGridColumn('site', 'Site', 'left');
  50. // add the columns to the DataGrid
  51. $this->datagrid->addColumn($column_id);
  52. $this->datagrid->addColumn($column_nome);
  53. $this->datagrid->addColumn($column_numero);
  54. $this->datagrid->addColumn($column_site);
  55. // create EDIT action
  56. $action_edit = new TDataGridAction(array('FinBancoForm', 'onEdit'));
  57. $action_edit->setUseButton(TRUE);
  58. $action_edit->setButtonClass('btn btn-default');
  59. $action_edit->setLabel(_t('Edit'));
  60. $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  61. $action_edit->setField('id');
  62. $this->datagrid->addAction($action_edit);
  63. // create DELETE action
  64. $action_del = new TDataGridAction(array($this, 'onDelete'));
  65. $action_del->setUseButton(TRUE);
  66. $action_del->setButtonClass('btn btn-default');
  67. $action_del->setLabel(_t('Delete'));
  68. $action_del->setImage('fa:trash-o red fa-lg');
  69. $action_del->setField('id');
  70. $this->datagrid->addAction($action_del);
  71. // create the datagrid model
  72. $this->datagrid->createModel();
  73. // creates the page navigation
  74. $this->pageNavigation = new TPageNavigation;
  75. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  76. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  77. // vertical box container
  78. $container = new TVBox;
  79. $container->style = 'width: 90%';
  80. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  81. $container->add(TPanelGroup::pack('Title', $this->form));
  82. $container->add($this->datagrid);
  83. $container->add($this->pageNavigation);
  84. parent::add($container);
  85. }
  86. /**
  87. * Inline record editing
  88. * @param $param Array containing:
  89. * key: object ID value
  90. * field name: object attribute to be updated
  91. * value: new attribute content
  92. */
  93. public function onInlineEdit($param)
  94. {
  95. try
  96. {
  97. // get the parameter $key
  98. $field = $param['field'];
  99. $key = $param['key'];
  100. $value = $param['value'];
  101. TTransaction::open('educacional'); // open a transaction with database
  102. $object = new FinBanco($key); // instantiates the Active Record
  103. $object->{$field} = $value;
  104. $object->store(); // update the object in the database
  105. TTransaction::close(); // close the transaction
  106. $this->onReload($param); // reload the listing
  107. new TMessage('info', "Record Updated");
  108. }
  109. catch (Exception $e) // in case of exception
  110. {
  111. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  112. TTransaction::rollback(); // undo all pending operations
  113. }
  114. }
  115. /**
  116. * Register the filter in the session
  117. */
  118. public function onSearch()
  119. {
  120. // get the search form data
  121. $data = $this->form->getData();
  122. // clear session filters
  123. TSession::setValue('FinBancoList_filter_id', NULL);
  124. TSession::setValue('FinBancoList_filter_nome', NULL);
  125. if (isset($data->id) AND ($data->id)) {
  126. $filter = new TFilter('id', '=', "$data->id"); // create the filter
  127. TSession::setValue('FinBancoList_filter_id', $filter); // stores the filter in the session
  128. }
  129. if (isset($data->nome) AND ($data->nome)) {
  130. $filter = new TFilter('nome', 'like', "%{$data->nome}%"); // create the filter
  131. TSession::setValue('FinBancoList_filter_nome', $filter); // stores the filter in the session
  132. }
  133. // fill the form with data again
  134. $this->form->setData($data);
  135. // keep the search data in the session
  136. TSession::setValue('FinBanco_filter_data', $data);
  137. $param=array();
  138. $param['offset'] =0;
  139. $param['first_page']=1;
  140. $this->onReload($param);
  141. }
  142. /**
  143. * Load the datagrid with data
  144. */
  145. public function onReload($param = NULL)
  146. {
  147. try
  148. {
  149. // open a transaction with database 'educacional'
  150. TTransaction::open('educacional');
  151. // creates a repository for FinBanco
  152. $repository = new TRepository('FinBanco');
  153. $limit = 10;
  154. // creates a criteria
  155. $criteria = new TCriteria;
  156. // default order
  157. if (empty($param['order']))
  158. {
  159. $param['order'] = 'id';
  160. $param['direction'] = 'asc';
  161. }
  162. $criteria->setProperties($param); // order, offset
  163. $criteria->setProperty('limit', $limit);
  164. if (TSession::getValue('FinBancoList_filter_id')) {
  165. $criteria->add(TSession::getValue('FinBancoList_filter_id')); // add the session filter
  166. }
  167. if (TSession::getValue('FinBancoList_filter_nome')) {
  168. $criteria->add(TSession::getValue('FinBancoList_filter_nome')); // add the session filter
  169. }
  170. // load the objects according to criteria
  171. $objects = $repository->load($criteria, FALSE);
  172. if (is_callable($this->transformCallback))
  173. {
  174. call_user_func($this->transformCallback, $objects, $param);
  175. }
  176. $this->datagrid->clear();
  177. if ($objects)
  178. {
  179. // iterate the collection of active records
  180. foreach ($objects as $object)
  181. {
  182. // add the object inside the datagrid
  183. $this->datagrid->addItem($object);
  184. }
  185. }
  186. // reset the criteria for record count
  187. $criteria->resetProperties();
  188. $count= $repository->count($criteria);
  189. $this->pageNavigation->setCount($count); // count of records
  190. $this->pageNavigation->setProperties($param); // order, page
  191. $this->pageNavigation->setLimit($limit); // limit
  192. // close the transaction
  193. TTransaction::close();
  194. $this->loaded = true;
  195. }
  196. catch (Exception $e) // in case of exception
  197. {
  198. // shows the exception error message
  199. new TMessage('error', $e->getMessage());
  200. // undo all pending operations
  201. TTransaction::rollback();
  202. }
  203. }
  204. /**
  205. * Ask before deletion
  206. */
  207. public function onDelete($param)
  208. {
  209. // define the delete action
  210. $action = new TAction(array($this, 'Delete'));
  211. $action->setParameters($param); // pass the key parameter ahead
  212. // shows a dialog to the user
  213. new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  214. }
  215. /**
  216. * Delete a record
  217. */
  218. public function Delete($param)
  219. {
  220. try
  221. {
  222. $key=$param['key']; // get the parameter $key
  223. TTransaction::open('educacional'); // open a transaction with database
  224. $object = new FinBanco($key, FALSE); // instantiates the Active Record
  225. $object->delete(); // deletes the object from the database
  226. TTransaction::close(); // close the transaction
  227. $this->onReload( $param ); // reload the listing
  228. new TMessage('info', AdiantiCoreTranslator::translate('Record deleted')); // success message
  229. }
  230. catch (Exception $e) // in case of exception
  231. {
  232. new TMessage('error', $e->getMessage()); // shows the exception error message
  233. TTransaction::rollback(); // undo all pending operations
  234. }
  235. }
  236. /**
  237. * method show()
  238. * Shows the page
  239. */
  240. public function show()
  241. {
  242. // check if the datagrid is already loaded
  243. if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
  244. {
  245. if (func_num_args() > 0)
  246. {
  247. $this->onReload( func_get_arg(0) );
  248. }
  249. else
  250. {
  251. $this->onReload();
  252. }
  253. }
  254. parent::show();
  255. }
  256. }
  257. ?>

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

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 (9)


NR

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:
 
  1. <?php
  2. public function onSearch($param)
  3. {
  4. // get the search form data
  5. //$data = $this->form->getData();
  6. // clear session filters
  7. TSession::setValue('FinBancoList_filter_id', NULL);
  8. TSession::setValue('FinBancoList_filter_nome', NULL);
  9. if (isset($param['id']) AND ($param['id'])) {
  10. $filter = new TFilter('id', '=', $param['id']); // create the filter
  11. TSession::setValue('FinBancoList_filter_id', $filter); // stores the filter in the session
  12. }
  13. if (isset($param['nome']) AND ($param['nome'])) {
  14. $filter = new TFilter('nome', 'like', "%{$param['nome']}%"); // create the filter
  15. TSession::setValue('FinBancoList_filter_nome', $filter); // stores the filter in the session
  16. }
  17. // fill the form with data again
  18. //$this->form->setData($data);
  19. // keep the search data in the session
  20. //TSession::setValue('FinBanco_filter_data', $data);
  21. $param=array();
  22. $param['offset'] =0;
  23. $param['first_page']=1;
  24. $this->onReload($param);
  25. }
  26. ?>
WS

Nataniel, funcionou do jeito que você me passou, muito simples. Olha só eu criei o código>
 
  1. <?php
  2. public function onFilter($param=null)
  3. {
  4. // creates the form
  5. $this->form = new TQuickForm('form_search_FinBanco');
  6. $this->form->class = 'tform'; // change CSS class
  7. $this->form = new BootstrapFormWrapper($this->form);
  8. $this->form->style = 'display: table;width:100%'; // change style
  9. $this->form->setFormTitle('FinBanco');
  10. // create the form fields
  11. $id = new TEntry('id');
  12. $nome = new TEntry('nome');
  13. // add the fields
  14. $this->form->addQuickField('Id', $id, 200 );
  15. $this->form->addQuickField('Nome', $nome, 100 );
  16. // keep the form filled during navigation with session data
  17. $this->form->setData( TSession::getValue('FinBanco_filter_data') );
  18. // add the search form actions
  19. $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  20. // vertical box container
  21. $container = new TVBox;
  22. $container->style = 'width: 90%';
  23. $container->add(TPanelGroup::pack('Title', $this->form));
  24. $window = TWindow::create('Title', 0.5, 0.5);
  25. $window->add($container);
  26. $window->show();
  27. }
  28. ?>

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
 
  1. <?php TWindow::closeWindow(); ?>
dentro do onSearch mais ele não funciona, esta certo minha lógica?....
WS

Mudei o código para ficar assim:
 
  1. <?php
  2. protected $window;
  3. $this->window = TWindow::create('Title', 0.5, 0.5);
  4. $this->window->add($container);
  5. $this->window->show();
  6. ?>

no OnSearch peço para fechar o window :
 
  1. <?php
  2. $this->window->closeWindow();
  3. ?>


Mais na verdade ele joga o código do OnFilter para dentro da página PAI.
NR

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:
 
  1. <?php
  2. $bt_busca = $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  3. $window = TWindow::create('Title', 0.5, 0.5);
  4. $bt_busca->addFunction("setTimeout(function(){ $( '#{$window->get(0)->getId()}').remove();},100);");
  5. // vertical box container
  6. $container = new TVBox;
  7. $container->style = 'width: 90%';
  8. $container->add(TPanelGroup::pack('Title', $this->form));
  9. $window->add($container);
  10. $window->show();
  11. ?>
WS

Mais esse comando setTimeout eu coloco um tempo pra ele ficar aberto.

Serio que o Twindow não tem como fecha-lo?...
NR

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ó :
 
  1. <?php
  2. $bt_busca->addFunction("$( '#{$window->get(0)->getId()}').remove();");
  3. ?>

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.
WS

Estou quase xingando já, não consegui pegar a lógica ainda. Vou colocar todo meu código aqui:
 
  1. <?php
  2. /**
  3. * FinBancoList Listing
  4. * @author <Willian Aquino>
  5. */
  6. use App\lib\Widget\Container\WPanelGroup;
  7. use App\lib\Widget\Container\WPanelWindow;
  8. use App\lib\Wrapper\WBootstrapFormWrapper;
  9. use App\lib\Widget\Form\WEntry;
  10. use App\lib\Widget\Wrapper\WQuickForm;
  11. use Adianti\Registry\TSession;
  12. use Adianti\Core\AdiantiCoreApplication;
  13. use Adianti\Widget\Base\TScript;
  14. class FinBancoList extends TPage
  15. {
  16. private $form; // form
  17. private $formFilter; // form
  18. private $datagrid; // listing
  19. private $pageNavigation;
  20. private $formgrid;
  21. private $loaded;
  22. private $deleteButton;
  23. protected $window;
  24. /**
  25. * Class constructor
  26. * Creates the page, the form and the listing
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. // creates the form
  32. $this->form = new WQuickForm('form_FinBanco');
  33. $this->form = new WBootstrapFormWrapper($this->form);
  34. // keep the form filled during navigation with session data
  35. $this->form->setData( TSession::getValue('FinBanco_filter_data') );
  36. // add the search form actions
  37. $this->form->addQuickActionPanel(_t('List'), new TAction(array($this, 'onList')), 'fa:th','btn green');
  38. $this->form->addQuickActionPanel(_t('Find'), new TAction(array($this, 'onFilter')), 'fa:search','btn green');
  39. $this->form->addQuickActionPanel(_t('New'), new TAction(array('FinBancoForm', 'onEdit')), 'bs:plus-sign', 'btn green');
  40. // creates a Datagrid
  41. $this->datagrid = new TDataGrid;
  42. $this->datagrid = new BootstrapDatagridWrapper($this->datagrid);
  43. $this->datagrid->style = 'width: 100%';
  44. $this->datagrid->setHeight(320);
  45. // creates the datagrid columns
  46. $column_id = new TDataGridColumn('id', 'Id', 'left');
  47. $column_nome = new TDataGridColumn('nome', 'Nome', 'left');
  48. $column_numero = new TDataGridColumn('numero', 'Numero', 'left');
  49. $column_status = new TDataGridColumn('status', 'Status', 'left');
  50. // add the columns to the DataGrid
  51. $this->datagrid->addColumn($column_id);
  52. $this->datagrid->addColumn($column_nome);
  53. $this->datagrid->addColumn($column_numero);
  54. $this->datagrid->addColumn($column_status);
  55. // creates the datagrid column actions
  56. $order_id = new TAction(array($this, 'onReload'));
  57. $order_id->setParameter('order', 'id');
  58. $column_id->setAction($order_id);
  59. $order_nome = new TAction(array($this, 'onReload'));
  60. $order_nome->setParameter('order', 'nome');
  61. $column_nome->setAction($order_nome);
  62. $order_numero = new TAction(array($this, 'onReload'));
  63. $order_numero->setParameter('order', 'numero');
  64. $column_numero->setAction($order_numero);
  65. $order_status = new TAction(array($this, 'onReload'));
  66. $order_status->setParameter('order', 'status');
  67. $column_status->setAction($order_status);
  68. // create EDIT action
  69. $action_edit = new TDataGridAction(array('FinBancoForm', 'onEdit'));
  70. $action_edit->setUseButton(TRUE);
  71. $action_edit->setButtonClass('btn blue');
  72. $action_edit->setLabel(_t('Edit'));
  73. $action_edit->setImage('fa:pencil-square-o fa-lg');
  74. $action_edit->setField('id');
  75. //$this->datagrid->addAction($action_edit);
  76. // create DELETE action
  77. $action_del = new TDataGridAction(array($this, 'onDelete'));
  78. $action_del->setUseButton(TRUE);
  79. $action_del->setButtonClass('btn blue');
  80. $action_del->setLabel(_t('Delete'));
  81. $action_del->setImage('fa:trash-o red fa-lg');
  82. $action_del->setField('id');
  83. $action_group = new TDataGridActionGroup('Opções', 'bs:th');
  84. //$action_group->addHeader(utf8_encode(_t('Actions')));
  85. $action_group->addAction($action_edit);
  86. $action_group->addAction($action_del);
  87. // add the actions to the datagrid
  88. $this->datagrid->addActionGroup($action_group);
  89. // create the datagrid model
  90. $this->datagrid->createModel();
  91. // creates the page navigation
  92. $this->pageNavigation = new TPageNavigation;
  93. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  94. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  95. // vertical box container
  96. $container = new TVBox;
  97. $container->style = 'width: 100%';
  98. $panelGroup = WPanelGroup::pack('Listagem de Banco', $this->form);
  99. $panelGroup->add($this->datagrid);
  100. $panelGroup->add($this->pageNavigation);
  101. $container->add($panelGroup);
  102. parent::add($container);
  103. }
  104. /**
  105. * Inline record editing
  106. * @param $param Array containing:
  107. * key: object ID value
  108. * field name: object attribute to be updated
  109. * value: new attribute content
  110. */
  111. /**
  112. * view all itens
  113. */
  114. public function onList()
  115. {
  116. TSession::delValue('FinBancoList_filter_id');
  117. TSession::delValue('FinBancoList_filter_nome');
  118. $this->onReload();
  119. }
  120. /**
  121. * Open an input dialog
  122. */
  123. public function onFilter($param=null)
  124. {
  125. // creates the form
  126. $this->form = new WQuickForm('form_search_FinBanco');
  127. $this->form = new WBootstrapFormWrapper($this->form);
  128. // create the form fields
  129. $nome = new WEntry('nome');
  130. $nome->{'placeholder'} = "ID ou NOME";
  131. $nome->setMaxLength(100);
  132. $nome->setIcon('fa fa-search');
  133. $nome->setValue(TSession::getValue('FinBanco_filter_data'));
  134. // add the fields
  135. $this->form->addQuickField('ID ou Nome', $nome, '100%' );
  136. // add the search form actions
  137. $this->form->addQuickAction(_t('Find'), new TAction(array('FinBancoList', 'onSearch')), 'fa:search');
  138. // vertical box container
  139. $container = new TVBox;
  140. $container->style = 'width: 100%';
  141. $container->add(WPanelWindow::pack($this->form));
  142. $this->window = TWindow::create('Buscar', 0.5, 250);
  143. $this->window->add($container);
  144. $this->window->show();
  145. /*$form = new TQuickForm('input_form');
  146. $form->style = 'padding:20px';
  147. $login = new TEntry('login');
  148. $form->addQuickField('Login', $login);
  149. $form->addQuickAction('Confirm 1', new TAction(array($this, 'onSearch')), 'ico_save.png');
  150. // show the input dialog
  151. new TInputDialog('Input dialog title', $login);
  152. */
  153. }
  154. /**
  155. * Register the filter in the session
  156. */
  157. public function onSearch($param)
  158. {
  159. TSession::delValue('FinBancoList_filter_id');
  160. TSession::delValue('FinBancoList_filter_nome');
  161. if (isset($param['nome']) AND ($param['nome'])) {
  162. if(is_numeric(trim($param['nome']))){
  163. $filter = new TFilter('id', '=', $param['nome']); // create the filter
  164. TSession::setValue('FinBancoList_filter_id', $filter); // stores the filter in the session
  165. }
  166. $filter = new TFilter('nome', 'like', "%{$param['nome']}%"); // create the filter
  167. TSession::setValue('FinBancoList_filter_nome', $filter); // stores the filter in the session
  168. }
  169. // keep the search data in the session
  170. TSession::setValue('FinBanco_filter_data', $param['nome']);
  171. $param=array();
  172. $param['offset'] =0;
  173. $param['first_page']=1;
  174. $this->onReload($param);
  175. }
  176. public function onInlineEdit($param)
  177. {
  178. try
  179. {
  180. // get the parameter $key
  181. $field = $param['field'];
  182. $key = $param['key'];
  183. $value = $param['value'];
  184. TTransaction::open('educacional'); // open a transaction with database
  185. $object = new FinBanco($key); // instantiates the Active Record
  186. $object->{$field} = $value;
  187. $object->store(); // update the object in the database
  188. TTransaction::close(); // close the transaction
  189. $this->onReload($param); // reload the listing
  190. new TMessage('info', "Record Updated");
  191. }
  192. catch (Exception $e) // in case of exception
  193. {
  194. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  195. TTransaction::rollback(); // undo all pending operations
  196. }
  197. }
  198. /**
  199. * Load the datagrid with data
  200. */
  201. public function onReload($param = NULL)
  202. {
  203. try
  204. {
  205. // open a transaction with database 'educacional'
  206. TTransaction::open('educacional');
  207. // creates a repository for FinBanco
  208. $repository = new TRepository('FinBanco');
  209. $limit = 10;
  210. // creates a criteria
  211. $criteria = new TCriteria;
  212. // default order
  213. if (empty($param['order']))
  214. {
  215. $param['order'] = 'id';
  216. $param['direction'] = 'asc';
  217. }
  218. $criteria->setProperties($param); // order, offset
  219. $criteria->setProperty('limit', $limit);
  220. if (TSession::getValue('FinBancoList_filter_id')) {
  221. $criteria->add(TSession::getValue('FinBancoList_filter_id', TExpression::OR_OPERATOR)); // add the session filter
  222. }
  223. if (TSession::getValue('FinBancoList_filter_nome')) {
  224. $criteria->add(TSession::getValue('FinBancoList_filter_nome'), TExpression::OR_OPERATOR); // add the session filter
  225. }
  226. // load the objects according to criteria
  227. $objects = $repository->load($criteria, FALSE);
  228. if (is_callable($this->transformCallback))
  229. {
  230. call_user_func($this->transformCallback, $objects, $param);
  231. }
  232. //var_dump($objects);
  233. $this->datagrid->clear();
  234. if ($objects)
  235. {
  236. // iterate the collection of active records
  237. foreach ($objects as $object)
  238. {
  239. // add the object inside the datagrid
  240. $this->datagrid->addItem($object);
  241. }
  242. }
  243. // reset the criteria for record count
  244. $criteria->resetProperties();
  245. $count= $repository->count($criteria);
  246. $this->pageNavigation->setCount($count); // count of records
  247. $this->pageNavigation->setProperties($param); // order, page
  248. $this->pageNavigation->setLimit($limit); // limit
  249. // close the transaction
  250. TTransaction::close();
  251. $this->loaded = true;
  252. }
  253. catch (Exception $e) // in case of exception
  254. {
  255. // shows the exception error message
  256. new TMessage('error', $e->getMessage());
  257. // undo all pending operations
  258. TTransaction::rollback();
  259. }
  260. }
  261. /**
  262. * Ask before deletion
  263. */
  264. public function onDelete($param)
  265. {
  266. // define the delete action
  267. $action = new TAction(array($this, 'Delete'));
  268. $action->setParameters($param); // pass the key parameter ahead
  269. // shows a dialog to the user
  270. new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  271. }
  272. /**
  273. * Delete a record
  274. */
  275. public function Delete($param)
  276. {
  277. try
  278. {
  279. $key=$param['key']; // get the parameter $key
  280. TTransaction::open('educacional'); // open a transaction with database
  281. $object = new FinBanco($key, FALSE); // instantiates the Active Record
  282. $object->delete(); // deletes the object from the database
  283. TTransaction::close(); // close the transaction
  284. $this->onReload( $param ); // reload the listing
  285. new TMessage('info', AdiantiCoreTranslator::translate('Record deleted')); // success message
  286. }
  287. catch (Exception $e) // in case of exception
  288. {
  289. new TMessage('error', $e->getMessage()); // shows the exception error message
  290. TTransaction::rollback(); // undo all pending operations
  291. }
  292. }
  293. /**
  294. * method show()
  295. * Shows the page
  296. */
  297. public function show()
  298. {
  299. // check if the datagrid is already loaded
  300. if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
  301. {
  302. if (func_num_args() > 0)
  303. {
  304. $this->onReload( func_get_arg(0) );
  305. }
  306. else
  307. {
  308. $this->onReload();
  309. }
  310. }
  311. parent::show();
  312. }
  313. }
  314. ?>



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>
NR

 
  1. <?php
  2. public function onFilter($param=null)
  3. {
  4. // creates the form
  5. $this->form = new WQuickForm('form_search_FinBanco');
  6. $this->form = new WBootstrapFormWrapper($this->form);
  7. // create the form fields
  8. $nome = new WEntry('nome');
  9. $nome->{'placeholder'} = "ID ou NOME";
  10. $nome->setMaxLength(100);
  11. $nome->setIcon('fa fa-search');
  12. $nome->setValue(TSession::getValue('FinBanco_filter_data'));
  13. // add the fields
  14. $this->form->addQuickField('ID ou Nome', $nome, '100%' );
  15. // add the search form actions
  16. $bt_busca = $this->form->addQuickAction(_t('Find'), new TAction(array('FinBancoList', 'onSearch')), 'fa:search');
  17. $this->window = TWindow::create('Buscar', 0.5, 250);
  18. $bt_busca->addFunction("setTimeout(function(){ $( '#{$this->window->get(0)->getId()}').remove();},100);");
  19. // vertical box container
  20. $container = new TVBox;
  21. $container->style = 'width: 100%';
  22. $container->add(WPanelWindow::pack($this->form));
  23. $this->window->add($container);
  24. $this->window->show();
  25. /*$form = new TQuickForm('input_form');
  26. $form->style = 'padding:20px';
  27. $login = new TEntry('login');
  28. $form->addQuickField('Login', $login);
  29. $form->addQuickAction('Confirm 1', new TAction(array($this, 'onSearch')), 'ico_save.png');
  30. // show the input dialog
  31. new TInputDialog('Input dialog title', $login);
  32. */
  33. }
  34. ?>
WS

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..