[DÚVIDA] Como não mostrar no [Show Results] a Tela inicial Bom dia, estou usando o Tutorial como exemplo para mostrar o resultado de alguns itens selecionados na minha template, porém quando clico no botão Show Results o TWindow mostra, junto ao novo Datagrid criado, a tela em que estava selecionando os itens com o Form e o outro Datagrid da lista. Usei o código do Tutorial, que funciona perfeitamente (ele não carrega a tela de busca junto no Show...
MS
[DÚVIDA] Como não mostrar no [Show Results] a Tela inicial  
Bom dia, estou usando o Tutorial como exemplo para mostrar o resultado de alguns itens selecionados na minha template, porém quando clico no botão Show Results o TWindow mostra, junto ao novo Datagrid criado, a tela em que estava selecionando os itens com o Form e o outro Datagrid da lista.

Usei o código do Tutorial, que funciona perfeitamente (ele não carrega a tela de busca junto no Show Results, apenas o Datagrid novo com os dados selecionados), e modifiquei com minha Database e TRecord.

Alguém sabe o porquê do meu TWindow está carregando a página de seleção junto com o resultado?


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)


AW

Posta os fontes.
MS

 
  1. <?php
  2. class Image1 extends TStandardList
  3. {
  4. protected $form; // search form
  5. protected $datagrid; // listing
  6. protected $pageNavigation;
  7. /**
  8. * Page constructor
  9. */
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. parent::setDatabase('sample');
  14. parent::setActiveRecord('Ds');
  15. parent::setDefaultOrder('id', 'asc');
  16. // filter (filter field, operator, form field)
  17. parent::addFilterField('descricao', 'like', 'descricao');
  18. // creates the form
  19. $this->form = new TQuickForm('form_search_Ds');
  20. $this->form->class = 'tform'; // change style
  21. $this->form->style = 'display: table;width:100%'; // change style
  22. $this->form->setFormTitle('Ds');
  23. $descricao = new TEntry('descricao');
  24. $this->form->addQuickField('Descrição', $descricao, 200 );
  25. // keep the form filled during navigation with session data
  26. $this->form->setData( TSession::getValue('Ds_filter_data') );
  27. // add the search form actions
  28. $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  29. $this->form->addQuickAction( 'Show results', new TAction(array($this, 'showResults')), 'fa:check-circle-o green' );
  30. // creates a DataGrid
  31. $this->datagrid = new TDataGrid;
  32. $this->datagrid->style = 'width: 100%';
  33. $this->datagrid->setHeight(320);
  34. // creates the datagrid columns
  35. $column_id = new TDataGridColumn('id', 'Id', 'left');
  36. $column_descricao = new TDataGridColumn('descricao', 'Descrição', 'left');
  37. //$column_sale_price = new TDataGridColumn('sale_price', 'Sale Price', 'left');
  38. // add the columns to the DataGrid
  39. $this->datagrid->addColumn($column_id);
  40. $this->datagrid->addColumn($column_descricao);
  41. //$this->datagrid->addColumn($column_sale_price);
  42. $column_id->setTransformer(array($this, 'formatRow') );
  43. // creates the datagrid actions
  44. $action1 = new TDataGridAction(array($this, 'onSelect'));
  45. $action1->setUseButton(TRUE);
  46. $action1->setButtonClass('btn btn-default');
  47. $action1->setLabel(AdiantiCoreTranslator::translate('Select'));
  48. $action1->setImage('fa:check-circle-o blue');
  49. $action1->setField('id');
  50. // add the actions to the datagrid
  51. $this->datagrid->addAction($action1);
  52. // create the datagrid model
  53. $this->datagrid->createModel();
  54. // create the page navigation
  55. $this->pageNavigation = new TPageNavigation;
  56. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  57. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  58. // vertical box container
  59. $container = new TVBox;
  60. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  61. $container->add($this->form);
  62. $container->add($this->datagrid);
  63. $container->add($this->pageNavigation);
  64. parent::add($container);
  65. }
  66. /**
  67. * Save the object reference in session
  68. */
  69. public function onSelect($param)
  70. {
  71. // get the selected objects from session
  72. $selected_objects = TSession::getValue(__CLASS__.'_selected_objects');
  73. TTransaction::open('samples');
  74. $object = new Product($param['id']); // load the object
  75. if (isset($selected_objects[$object->id]))
  76. {
  77. unset($selected_objects[$object->id]);
  78. }
  79. else
  80. {
  81. $selected_objects[$object->id] = $object->toArray(); // add the object inside the array
  82. }
  83. TSession::setValue(__CLASS__.'_selected_objects', $selected_objects); // put the array back to the session
  84. TTransaction::close();
  85. // reload datagrids
  86. $this->onReload( func_get_arg(0) );
  87. }
  88. /**
  89. * Highlight the selected rows
  90. */
  91. public function formatRow($value, $object, $row)
  92. {
  93. $selected_objects = TSession::getValue(__CLASS__.'_selected_objects');
  94. if ($selected_objects)
  95. {
  96. if (in_array( (int) $value, array_keys( $selected_objects ) ) )
  97. {
  98. $row->style = "background: #FFD965";
  99. }
  100. }
  101. return $value;
  102. }
  103. /**
  104. * Show selected records
  105. */
  106. public function showResults()
  107. {
  108. $datagrid = new BootstrapDatagridWrapper(new TQuickGrid);
  109. $datagrid->addQuickColumn('Id', 'id', 'left');
  110. $datagrid->addQuickColumn('Descrição', 'descricao', 'left');
  111. //$datagrid->addQuickColumn('Sale Price', 'sale_price', 'left');
  112. // create the datagrid model
  113. $datagrid->createModel();
  114. $selected_objects = TSession::getValue(__CLASS__.'_selected_objects');
  115. ksort($selected_objects);
  116. if ($selected_objects)
  117. {
  118. $datagrid->clear();
  119. foreach ($selected_objects as $selected_object)
  120. {
  121. $datagrid->addItem( (object) $selected_object );
  122. }
  123. }
  124. $win = TWindow::create('Results', 0.6, 0.6);
  125. $win->add($datagrid);
  126. $win->show();
  127. }
  128. }
  129. ?>
MS

Só editando mais: na linha 89 mudei o samples ->> sample e na linha 90 mudei o $object = new Product($param['id']) -> $object = new Ds($param['id']);

O programa roda normalmente, mas quando abro a Window ele carrega a pagina toda além dos itens selecionados e quando tento voltar pra agina ela some.
NR

Marcos, executei o código que passou e não tive nenhum problema aqui. Funcionou normal.

Que versão do framework você está usando?
MS

Estou usando o 4.0.0 Studio e Framework
NR

Crie um novo projeto no Studio e teste esse mesmo código nele. Vamos ver o que acontece.
MS

Nataniel, como sugerido foi feito em um novo projeto em até em uma nova máquina e funcionou normalmente. O problema é quando crio uma New Page (New records check list) no projeto antigo ele já vem com esse problema de carregar a Session junto na TWindow. Desconfia do que pode ser?
NR

Se funciona nos demais projetos deve ser algo com o projeto antigo. Houve algum tipo de modificação nesse projeto? Ele foi criado na versão 4 do framework ou foi criado em uma versão anterior e depois atualizado?
MS

Problema resolvido, Nataniel. Com certeza era algo no Projeto. Criei um novo e copiei os arquivos necessários para remodular no formato antigo e ter as classes antigas. Está funcionando perfeitamente.

Muito obrigado pela a ajuda!