TWindow é Responsivo? Tenho um sistema feito no framework 4.0. Estou migrando para o framework 5.5 por ele ser responsivo. Uso o Studio Pro e nele temos a opção de criar [New auxiliar Form]. Alguns dos meus formulários auxiliares estão extendendo de TWindow, geralmente campos com combobox tem um botão ao lado para cadastro rápido por parte do usuário final. Porém não estou conseguindo deixar os formulários q...
JJ
TWindow é Responsivo?  
Tenho um sistema feito no framework 4.0. Estou migrando para o framework 5.5 por ele ser responsivo. Uso o Studio Pro e nele temos a opção de criar [New auxiliar Form]. Alguns dos meus formulários auxiliares estão extendendo de TWindow, geralmente campos com combobox tem um botão ao lado para cadastro rápido por parte do usuário final. Porém não estou conseguindo deixar os formulários que extende do TWindow responsivo. Mudei o form de TQuickForm para BootstrapFormBuilder. Alterei o addQuickFields para addFields. Alterei o Datagrid pelo BootstrapDatagridWrapper(new TDataGrid); Quando altero um formulário que extende de TPage funciona perfeitamente, ou seja o formulário fica responsivo. Porém com o TWindows fica estranho principalmente no celular. Alguém já enfrentou está dificuldade? E o TWindow é responsivo?

Segue o código:
 
  1. <?php
  2. /**
  3. * CargoFormList Form List
  4. * @author <your name here>
  5. */
  6. class CargoFormList extends TWindow
  7. {
  8. protected $form; // form
  9. protected $datagrid; // datagrid
  10. protected $pageNavigation;
  11. protected $loaded;
  12. /**
  13. * Form constructor
  14. * @param $param Request
  15. */
  16. public function __construct( $param )
  17. {
  18. parent::__construct();
  19. $this->form = new BootstrapFormBuilder('form_Cargo');
  20. $this->form->setFormTitle('Cargo');
  21. // create the form fields
  22. $id = new TEntry('id');
  23. $nome = new TEntry('nome');
  24. // add the fields
  25. $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  26. $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
  27. // set sizes
  28. $id->setSize('100%');
  29. $nome->setSize('100%');
  30. if (!empty($id))
  31. {
  32. $id->setEditable(FALSE);
  33. }
  34. /** samples
  35. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  36. $fieldX->setSize( '100%' ); // set size
  37. **/
  38. // create the form actions
  39. $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
  40. $btn->class = 'btn btn-sm btn-primary';
  41. $this->form->addAction(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
  42. // creates a Datagrid
  43. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  44. $this->datagrid->style = 'width: 100%';
  45. // $this->datagrid->datatable = 'true';
  46. // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  47. // creates the datagrid columns
  48. $column_id = new TDataGridColumn('id', 'Id', 'left');
  49. $column_nome = new TDataGridColumn('nome', 'Nome', 'left');
  50. // add the columns to the DataGrid
  51. $this->datagrid->addColumn($column_id);
  52. $this->datagrid->addColumn($column_nome);
  53. // creates two datagrid actions
  54. $action1 = new TDataGridAction([$this, 'onEdit']);
  55. //$action1->setUseButton(TRUE);
  56. //$action1->setButtonClass('btn btn-default');
  57. $action1->setLabel(_t('Edit'));
  58. $action1->setImage('fa:pencil-square-o blue fa-lg');
  59. $action1->setField('id');
  60. $action2 = new TDataGridAction([$this, 'onDelete']);
  61. //$action2->setUseButton(TRUE);
  62. //$action2->setButtonClass('btn btn-default');
  63. $action2->setLabel(_t('Delete'));
  64. $action2->setImage('fa:trash-o red fa-lg');
  65. $action2->setField('id');
  66. // add the actions to the datagrid
  67. $this->datagrid->addAction($action1);
  68. $this->datagrid->addAction($action2);
  69. // create the datagrid model
  70. $this->datagrid->createModel();
  71. // creates the page navigation
  72. $this->pageNavigation = new TPageNavigation;
  73. $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
  74. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  75. // vertical box container
  76. $container = new TVBox;
  77. $container->style = 'width: 90%';
  78. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  79. $container->add($this->form);
  80. $container->add(TPanelGroup::pack('', $this->datagrid));
  81. $container->add($this->pageNavigation);
  82. parent::add($container);
  83. }
  84. /**
  85. * Load the datagrid with data
  86. */
  87. public function onReload($param = NULL)
  88. {
  89. try
  90. {
  91. // open a transaction with database 'sgu'
  92. TTransaction::open('sgu');
  93. // creates a repository for Cargo
  94. $repository = new TRepository('Cargo');
  95. $limit = 10;
  96. // creates a criteria
  97. $criteria = new TCriteria;
  98. // default order
  99. if (empty($param['order']))
  100. {
  101. $param['order'] = 'id';
  102. $param['direction'] = 'asc';
  103. }
  104. $criteria->setProperties($param); // order, offset
  105. $criteria->setProperty('limit', $limit);
  106. // load the objects according to criteria
  107. $objects = $repository->load($criteria, FALSE);
  108. $this->datagrid->clear();
  109. if ($objects)
  110. {
  111. // iterate the collection of active records
  112. foreach ($objects as $object)
  113. {
  114. // add the object inside the datagrid
  115. $this->datagrid->addItem($object);
  116. }
  117. }
  118. // reset the criteria for record count
  119. $criteria->resetProperties();
  120. $count= $repository->count($criteria);
  121. $this->pageNavigation->setCount($count); // count of records
  122. $this->pageNavigation->setProperties($param); // order, page
  123. $this->pageNavigation->setLimit($limit); // limit
  124. // close the transaction
  125. TTransaction::close();
  126. $this->loaded = true;
  127. }
  128. catch (Exception $e) // in case of exception
  129. {
  130. // shows the exception error message
  131. new TMessage('error', $e->getMessage());
  132. // undo all pending operations
  133. TTransaction::rollback();
  134. }
  135. }
  136. /**
  137. * Ask before deletion
  138. */
  139. public static function onDelete($param)
  140. {
  141. // define the delete action
  142. $action = new TAction([__CLASS__, 'Delete']);
  143. $action->setParameters($param); // pass the key parameter ahead
  144. // shows a dialog to the user
  145. new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  146. }
  147. /**
  148. * Delete a record
  149. */
  150. public static function Delete($param)
  151. {
  152. try
  153. {
  154. $key = $param['key']; // get the parameter $key
  155. TTransaction::open('sgu'); // open a transaction with database
  156. $object = new Cargo($key, FALSE); // instantiates the Active Record
  157. $object->delete(); // deletes the object from the database
  158. TTransaction::close(); // close the transaction
  159. $pos_action = new TAction([__CLASS__, 'onReload']);
  160. new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  161. }
  162. catch (Exception $e) // in case of exception
  163. {
  164. new TMessage('error', $e->getMessage()); // shows the exception error message
  165. TTransaction::rollback(); // undo all pending operations
  166. }
  167. }
  168. /**
  169. * Save form data
  170. * @param $param Request
  171. */
  172. public function onSave( $param )
  173. {
  174. try
  175. {
  176. TTransaction::open('sgu'); // open a transaction
  177. /**
  178. // Enable Debug logger for SQL operations inside the transaction
  179. TTransaction::setLogger(new TLoggerSTD); // standard output
  180. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  181. **/
  182. $this->form->validate(); // validate form data
  183. $data = $this->form->getData(); // get form data as array
  184. $object = new Cargo; // create an empty object
  185. $object->fromArray( (array) $data); // load the object with data
  186. $object->store(); // save the object
  187. // get the generated id
  188. $data->id = $object->id;
  189. $this->form->setData($data); // fill form data
  190. TTransaction::close(); // close the transaction
  191. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); // success message
  192. $this->onReload(); // reload the listing
  193. }
  194. catch (Exception $e) // in case of exception
  195. {
  196. new TMessage('error', $e->getMessage()); // shows the exception error message
  197. $this->form->setData( $this->form->getData() ); // keep form data
  198. TTransaction::rollback(); // undo all pending operations
  199. }
  200. }
  201. /**
  202. * Clear form data
  203. * @param $param Request
  204. */
  205. public function onClear( $param )
  206. {
  207. $this->form->clear(TRUE);
  208. }
  209. /**
  210. * Load object to form data
  211. * @param $param Request
  212. */
  213. public function onEdit( $param )
  214. {
  215. try
  216. {
  217. if (isset($param['key']))
  218. {
  219. $key = $param['key']; // get the parameter $key
  220. TTransaction::open('sgu'); // open a transaction
  221. $object = new Cargo($key); // instantiates the Active Record
  222. $this->form->setData($object); // fill the form
  223. TTransaction::close(); // close the transaction
  224. }
  225. else
  226. {
  227. $this->form->clear(TRUE);
  228. }
  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 $_GET['method'] !== 'onReload') )
  244. {
  245. $this->onReload( func_get_arg(0) );
  246. }
  247. parent::show();
  248. }
  249. }
  250. ?>


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


JJ

Vou compartilhar o que utilizei como solução. Não ficou 100% responsivo mais já está bom.
Minha solução envolve:
1-) obter o código do Mobile Detect encontrando em: mobiledetect.net/
Baixei a versão 2.8.33
Eu adicionei o código na pasta app/lib

2-) Obter a classe Detect Device encontado em: https://detectdevice.com/#download
Baixei a versão 1.0.4
Copie o codigo detect.php e colei na mesma pasta do mobile Detect
Alterei o nome de detect.php para Detect.class.php assim a classe é reconhecida automoticamente.
coloquei o arquivo js na pasta app/include

3-) Adicione o codigo js no arquivo libraries.html no theme3
<!-- Application custom Javascript (Optional) --> <script src="app/lib/include/application.js?appver=505" type="text/javascript"></script> <script src="app/lib/include/detect.js" type="text/javascript"></script> <script src="app/lib/include/fuse/fuse.min.js?appver=505" type="text/javascript"></script>


4-) Adicionei no final do arquivo init.php o código:
// detect how is the device Detect::init();



Para finalizar inseri o código para verificar qual é o dispositivo do cliente e ajustar o setSize do TWindow para cada caso:

// Any mobile device (phones or tablets) if (Detect::isMobile()) { parent::setSize(300,800); } // Any phone device if (Detect::isPhone()) { parent::setSize(300,800); } // Any tablet device if (Detect::isTablet()) { parent::setSize(700,800); }


Código Completo:

 
  1. <?php
  2. /**
  3. * CargoFormList Form List
  4. * @author <your name here>
  5. */
  6. class CargoFormList extends TWindow
  7. {
  8. protected $form; // form
  9. protected $datagrid; // datagrid
  10. protected $pageNavigation;
  11. protected $loaded;
  12. /**
  13. * Form constructor
  14. * @param $param Request
  15. */
  16. public function __construct( $param )
  17. {
  18. parent::__construct();
  19. // Any mobile device (phones or tablets)
  20. if (Detect::isMobile()) {
  21. parent::setSize(300,800);
  22. }
  23. // Any phone device
  24. if (Detect::isPhone()) {
  25. parent::setSize(300,800);
  26. }
  27. // Any tablet device
  28. if (Detect::isTablet()) {
  29. parent::setSize(700,800);
  30. }
  31. // creates the form
  32. //1 $this->form = new TQuickForm('form_Cargo');
  33. $this->form = new BootstrapFormBuilder('form_Cargo');
  34. //2 $this->form->class = 'tform'; // change CSS class
  35. //3 $this->form->style = 'display: table;width:100%'; // change style
  36. $this->form->setFormTitle(_t('Job title'));
  37. // create the form fields
  38. $id = new TEntry('id');
  39. $nome = new TEntry('nome');
  40. $nome->setMaxLength(100);
  41. $id->setEditable(false);
  42. // add the fields
  43. //4 $this->form->addQuickField('ID', $id, 100 );
  44. //4 $this->form->addQuickField(_t('Name'), $nome, 200 , new TRequiredValidator);
  45. $this->form->addFields( [ new TLabel('ID') ], [ $id ] );
  46. $this->form->addFields( [ new TLabel(_t('Name')) ], [ $nome ] );
  47. //5
  48. $nome->addValidation('Nome', new TRequiredValidator);
  49. //6
  50. $id->setSize('100%');
  51. $nome->setSize('100%');
  52. /** samples
  53. $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  54. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  55. $fieldX->setSize( 100, 40 ); // set size
  56. **/
  57. // create the form actions
  58. //7 $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  59. //7 $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
  60. $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
  61. $btn->class = 'btn btn-sm btn-primary';
  62. $this->form->addAction(_t('New'), new TAction([$this, 'onClear']), 'fa:eraser red');
  63. // $this->form->addAction('Fechar', new TAction(array([$this, 'onClose'],['id_modal'=>$this->form->getId()])), 'fa:exit green');
  64. // creates a Datagrid
  65. //8 $this->datagrid = new TDataGrid;
  66. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  67. ##LIST_DECORATOR##
  68. $this->datagrid->style = 'width: 100%';
  69. $this->datagrid->setHeight(320);
  70. //9 $this->datagrid->datatable = 'true';
  71. $this->datagrid->datatable = 'true';
  72. // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  73. // creates the datagrid columns
  74. $column_id = new TDataGridColumn('id', 'ID', 'left');
  75. $column_nome = new TDataGridColumn('nome', _t('Name'), 'left');
  76. // add the columns to the DataGrid
  77. $this->datagrid->addColumn($column_id);
  78. $this->datagrid->addColumn($column_nome);
  79. // creates two datagrid actions
  80. $action1 = new TDataGridAction(array($this, 'onEdit'));
  81. $action1->setUseButton(TRUE);
  82. $action1->setButtonClass('btn btn-default');
  83. $action1->setLabel(_t('Edit'));
  84. $action1->setImage('fa:pencil-square-o blue fa-lg');
  85. $action1->setField('id');
  86. $action2 = new TDataGridAction(array($this, 'onDelete'));
  87. $action2->setUseButton(TRUE);
  88. $action2->setButtonClass('btn btn-default');
  89. $action2->setLabel(_t('Delete'));
  90. $action2->setImage('fa:trash-o red fa-lg');
  91. $action2->setField('id');
  92. // add the actions to the datagrid
  93. $this->datagrid->addAction($action1);
  94. $this->datagrid->addAction($action2);
  95. // create the datagrid model
  96. $this->datagrid->createModel();
  97. // creates the page navigation
  98. $this->pageNavigation = new TPageNavigation;
  99. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  100. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  101. // vertical box container
  102. $container = new TVBox;
  103. $container->style = 'width: 90%';
  104. //10 $menu_file_name = AdiantiMenuBuilder::get_file_menu() ? AdiantiMenuBuilder::get_file_menu() : 'menu_pt.xml';
  105. //11 $container->add(new TXMLBreadCrumb($menu_file_name, __CLASS__));
  106. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  107. $container->add($this->form);
  108. $container->add($this->datagrid);
  109. $container->add($this->pageNavigation);
  110. parent::add($container);
  111. }
  112. /*public function onClose($param = NULL)
  113. {
  114. TScript::create("$('#{$param['id_modal']}').remove();");
  115. }*/
  116. /**
  117. * Load the datagrid with data
  118. */
  119. public function onReload($param = NULL)
  120. {
  121. try
  122. {
  123. // open a transaction with database 'sgu'
  124. TTransaction::open('sgu');
  125. // creates a repository for Cargo
  126. $repository = new TRepository('Cargo');
  127. $limit = 10;
  128. // creates a criteria
  129. $criteria = new TCriteria;
  130. // default order
  131. if (empty($param['order']))
  132. {
  133. $param['order'] = 'id';
  134. $param['direction'] = 'asc';
  135. }
  136. $criteria->setProperties($param); // order, offset
  137. $criteria->setProperty('limit', $limit);
  138. if (TSession::getValue('Cargo_filter'))
  139. {
  140. // add the filter stored in the session to the criteria
  141. $criteria->add(TSession::getValue('Cargo_filter'));
  142. }
  143. // load the objects according to criteria
  144. $objects = $repository->load($criteria, FALSE);
  145. $this->datagrid->clear();
  146. if ($objects)
  147. {
  148. // iterate the collection of active records
  149. foreach ($objects as $object)
  150. {
  151. // add the object inside the datagrid
  152. $this->datagrid->addItem($object);
  153. }
  154. }
  155. // reset the criteria for record count
  156. $criteria->resetProperties();
  157. $count= $repository->count($criteria);
  158. $this->pageNavigation->setCount($count); // count of records
  159. $this->pageNavigation->setProperties($param); // order, page
  160. $this->pageNavigation->setLimit($limit); // limit
  161. // close the transaction
  162. TTransaction::close();
  163. $this->loaded = true;
  164. }
  165. catch (Exception $e) // in case of exception
  166. {
  167. // shows the exception error message
  168. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  169. // undo all pending operations
  170. TTransaction::rollback();
  171. }
  172. }
  173. /**
  174. * Ask before deletion
  175. */
  176. public function onDelete($param)
  177. {
  178. // define the delete action
  179. $action = new TAction(array($this, 'Delete'));
  180. $action->setParameters($param); // pass the key parameter ahead
  181. // shows a dialog to the user
  182. new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  183. }
  184. /**
  185. * Delete a record
  186. */
  187. public function Delete($param)
  188. {
  189. try
  190. {
  191. $key=$param['key']; // get the parameter $key
  192. TTransaction::open('sgu'); // open a transaction with database
  193. $object = new Cargo($key, FALSE); // instantiates the Active Record
  194. $object->delete(); // deletes the object from the database
  195. TTransaction::close(); // close the transaction
  196. $this->onReload( $param ); // reload the listing
  197. new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted')); // success message
  198. }
  199. catch (Exception $e) // in case of exception
  200. {
  201. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  202. TTransaction::rollback(); // undo all pending operations
  203. }
  204. }
  205. /**
  206. * Save form data
  207. * @param $param Request
  208. */
  209. public function onSave( $param )
  210. {
  211. try
  212. {
  213. TTransaction::open('sgu'); // open a transaction
  214. /**
  215. // Enable Debug logger for SQL operations inside the transaction
  216. TTransaction::setLogger(new TLoggerSTD); // standard output
  217. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  218. **/
  219. $this->form->validate(); // validate form data
  220. $object = new Cargo; // create an empty object
  221. $data = $this->form->getData(); // get form data as array
  222. $object->fromArray( (array) $data); // load the object with data
  223. $object->store(); // save the object
  224. // get the generated id
  225. $data->id = $object->id;
  226. $this->form->setData($data); // fill form data
  227. TTransaction::close(); // close the transaction
  228. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); // success message
  229. $this->onReload(); // reload the listing
  230. }
  231. catch (Exception $e) // in case of exception
  232. {
  233. new TMessage('error', $e->getMessage()); // shows the exception error message
  234. $this->form->setData( $this->form->getData() ); // keep form data
  235. TTransaction::rollback(); // undo all pending operations
  236. }
  237. }
  238. /**
  239. * Clear form data
  240. * @param $param Request
  241. */
  242. public function onClear( $param )
  243. {
  244. $this->form->clear();
  245. }
  246. /**
  247. * Load object to form data
  248. * @param $param Request
  249. */
  250. public function onEdit( $param )
  251. {
  252. try
  253. {
  254. if (isset($param['key']))
  255. {
  256. $key = $param['key']; // get the parameter $key
  257. TTransaction::open('sgu'); // open a transaction
  258. $object = new Cargo($key); // instantiates the Active Record
  259. $this->form->setData($object); // fill the form
  260. TTransaction::close(); // close the transaction
  261. }
  262. else
  263. {
  264. $this->form->clear();
  265. }
  266. }
  267. catch (Exception $e) // in case of exception
  268. {
  269. new TMessage('error', $e->getMessage()); // shows the exception error message
  270. TTransaction::rollback(); // undo all pending operations
  271. }
  272. }
  273. /**
  274. * method show()
  275. * Shows the page
  276. */
  277. public function show()
  278. {
  279. // check if the datagrid is already loaded
  280. if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  281. {
  282. $this->onReload( func_get_arg(0) );
  283. }
  284. parent::show();
  285. }
  286. }
  287. ?>





</your>
JJ

Pessoal,

Acabo de descobri que o TWindow é responsivo:
Eu precisava era acrescentar estes códigos:

$this->form->style = 'display: table;width:100%'; // change style
parent::setSize(0.8, null);
parent::setProperty('class', 'window_modal');

Removi o que fiz acima para deixar mais fácil para futuras atualizações do framework.




 
  1. <?php
  2. /**
  3. * CargoFormList Form List
  4. * @author <your name here>
  5. */
  6. class CargoFormList extends TWindow
  7. {
  8. protected $form; // form
  9. protected $datagrid; // datagrid
  10. protected $pageNavigation;
  11. protected $loaded;
  12. /**
  13. * Form constructor
  14. * @param $param Request
  15. */
  16. public function __construct( $param )
  17. {
  18. parent::__construct();
  19. parent::setSize(0.8, null);
  20. // creates the form
  21. //1 $this->form = new TQuickForm('form_Cargo');
  22. $this->form = new BootstrapFormBuilder('form_Cargo');
  23. //2 $this->form->class = 'tform'; // change CSS class
  24. $this->form->style = 'display: table;width:100%'; // change style
  25. $this->form->setFormTitle(_t('Job title'));
  26. parent::setProperty('class', 'window_modal');
  27. // create the form fields
  28. $id = new TEntry('id');
  29. $nome = new TEntry('nome');
  30. $nome->setMaxLength(100);
  31. $id->setEditable(false);
  32. // add the fields
  33. //4 $this->form->addQuickField('ID', $id, 100 );
  34. //4 $this->form->addQuickField(_t('Name'), $nome, 200 , new TRequiredValidator);
  35. $this->form->addFields( [ new TLabel('ID') ], [ $id ] );
  36. $this->form->addFields( [ new TLabel(_t('Name')) ], [ $nome ] );
  37. //5
  38. $nome->addValidation('Nome', new TRequiredValidator);
  39. //6
  40. $id->setSize('100%');
  41. $nome->setSize('100%');
  42. /** samples
  43. $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  44. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  45. $fieldX->setSize( 100, 40 ); // set size
  46. **/
  47. // create the form actions
  48. //7 $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  49. //7 $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
  50. $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
  51. $btn->class = 'btn btn-sm btn-primary';
  52. $this->form->addAction(_t('New'), new TAction([$this, 'onClear']), 'fa:eraser red');
  53. // $this->form->addAction('Fechar', new TAction(array([$this, 'onClose'],['id_modal'=>$this->form->getId()])), 'fa:exit green');
  54. // creates a Datagrid
  55. //8 $this->datagrid = new TDataGrid;
  56. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  57. ##LIST_DECORATOR##
  58. $this->datagrid->style = 'width: 100%';
  59. $this->datagrid->setHeight(320);
  60. //9 $this->datagrid->datatable = 'true';
  61. $this->datagrid->datatable = 'true';
  62. // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  63. // creates the datagrid columns
  64. $column_id = new TDataGridColumn('id', 'ID', 'left');
  65. $column_nome = new TDataGridColumn('nome', _t('Name'), 'left');
  66. // add the columns to the DataGrid
  67. $this->datagrid->addColumn($column_id);
  68. $this->datagrid->addColumn($column_nome);
  69. // creates two datagrid actions
  70. $action1 = new TDataGridAction(array($this, 'onEdit'));
  71. $action1->setUseButton(TRUE);
  72. $action1->setButtonClass('btn btn-default');
  73. $action1->setLabel(_t('Edit'));
  74. $action1->setImage('fa:pencil-square-o blue fa-lg');
  75. $action1->setField('id');
  76. $action2 = new TDataGridAction(array($this, 'onDelete'));
  77. $action2->setUseButton(TRUE);
  78. $action2->setButtonClass('btn btn-default');
  79. $action2->setLabel(_t('Delete'));
  80. $action2->setImage('fa:trash-o red fa-lg');
  81. $action2->setField('id');
  82. // add the actions to the datagrid
  83. $this->datagrid->addAction($action1);
  84. $this->datagrid->addAction($action2);
  85. // create the datagrid model
  86. $this->datagrid->createModel();
  87. // creates the page navigation
  88. $this->pageNavigation = new TPageNavigation;
  89. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  90. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  91. // vertical box container
  92. $container = new TVBox;
  93. $container->style = 'width: 90%';
  94. //10 $menu_file_name = AdiantiMenuBuilder::get_file_menu() ? AdiantiMenuBuilder::get_file_menu() : 'menu_pt.xml';
  95. //11 $container->add(new TXMLBreadCrumb($menu_file_name, __CLASS__));
  96. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  97. $container->add($this->form);
  98. $container->add($this->datagrid);
  99. $container->add($this->pageNavigation);
  100. parent::add($container);
  101. }
  102. /*public function onClose($param = NULL)
  103. {
  104. TScript::create("$('#{$param['id_modal']}').remove();");
  105. }*/
  106. /**
  107. * Load the datagrid with data
  108. */
  109. public function onReload($param = NULL)
  110. {
  111. try
  112. {
  113. // open a transaction with database 'sgu'
  114. TTransaction::open('sgu');
  115. // creates a repository for Cargo
  116. $repository = new TRepository('Cargo');
  117. $limit = 10;
  118. // creates a criteria
  119. $criteria = new TCriteria;
  120. // default order
  121. if (empty($param['order']))
  122. {
  123. $param['order'] = 'id';
  124. $param['direction'] = 'asc';
  125. }
  126. $criteria->setProperties($param); // order, offset
  127. $criteria->setProperty('limit', $limit);
  128. if (TSession::getValue('Cargo_filter'))
  129. {
  130. // add the filter stored in the session to the criteria
  131. $criteria->add(TSession::getValue('Cargo_filter'));
  132. }
  133. // load the objects according to criteria
  134. $objects = $repository->load($criteria, FALSE);
  135. $this->datagrid->clear();
  136. if ($objects)
  137. {
  138. // iterate the collection of active records
  139. foreach ($objects as $object)
  140. {
  141. // add the object inside the datagrid
  142. $this->datagrid->addItem($object);
  143. }
  144. }
  145. // reset the criteria for record count
  146. $criteria->resetProperties();
  147. $count= $repository->count($criteria);
  148. $this->pageNavigation->setCount($count); // count of records
  149. $this->pageNavigation->setProperties($param); // order, page
  150. $this->pageNavigation->setLimit($limit); // limit
  151. // close the transaction
  152. TTransaction::close();
  153. $this->loaded = true;
  154. }
  155. catch (Exception $e) // in case of exception
  156. {
  157. // shows the exception error message
  158. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  159. // undo all pending operations
  160. TTransaction::rollback();
  161. }
  162. }
  163. /**
  164. * Ask before deletion
  165. */
  166. public function onDelete($param)
  167. {
  168. // define the delete action
  169. $action = new TAction(array($this, 'Delete'));
  170. $action->setParameters($param); // pass the key parameter ahead
  171. // shows a dialog to the user
  172. new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  173. }
  174. /**
  175. * Delete a record
  176. */
  177. public function Delete($param)
  178. {
  179. try
  180. {
  181. $key=$param['key']; // get the parameter $key
  182. TTransaction::open('sgu'); // open a transaction with database
  183. $object = new Cargo($key, FALSE); // instantiates the Active Record
  184. $object->delete(); // deletes the object from the database
  185. TTransaction::close(); // close the transaction
  186. $this->onReload( $param ); // reload the listing
  187. new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted')); // success message
  188. }
  189. catch (Exception $e) // in case of exception
  190. {
  191. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  192. TTransaction::rollback(); // undo all pending operations
  193. }
  194. }
  195. /**
  196. * Save form data
  197. * @param $param Request
  198. */
  199. public function onSave( $param )
  200. {
  201. try
  202. {
  203. TTransaction::open('sgu'); // open a transaction
  204. /**
  205. // Enable Debug logger for SQL operations inside the transaction
  206. TTransaction::setLogger(new TLoggerSTD); // standard output
  207. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  208. **/
  209. $this->form->validate(); // validate form data
  210. $object = new Cargo; // create an empty object
  211. $data = $this->form->getData(); // get form data as array
  212. $object->fromArray( (array) $data); // load the object with data
  213. $object->store(); // save the object
  214. // get the generated id
  215. $data->id = $object->id;
  216. $this->form->setData($data); // fill form data
  217. TTransaction::close(); // close the transaction
  218. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); // success message
  219. $this->onReload(); // reload the listing
  220. }
  221. catch (Exception $e) // in case of exception
  222. {
  223. new TMessage('error', $e->getMessage()); // shows the exception error message
  224. $this->form->setData( $this->form->getData() ); // keep form data
  225. TTransaction::rollback(); // undo all pending operations
  226. }
  227. }
  228. /**
  229. * Clear form data
  230. * @param $param Request
  231. */
  232. public function onClear( $param )
  233. {
  234. $this->form->clear();
  235. }
  236. /**
  237. * Load object to form data
  238. * @param $param Request
  239. */
  240. public function onEdit( $param )
  241. {
  242. try
  243. {
  244. if (isset($param['key']))
  245. {
  246. $key = $param['key']; // get the parameter $key
  247. TTransaction::open('sgu'); // open a transaction
  248. $object = new Cargo($key); // instantiates the Active Record
  249. $this->form->setData($object); // fill the form
  250. TTransaction::close(); // close the transaction
  251. }
  252. else
  253. {
  254. $this->form->clear();
  255. }
  256. }
  257. catch (Exception $e) // in case of exception
  258. {
  259. new TMessage('error', $e->getMessage()); // shows the exception error message
  260. TTransaction::rollback(); // undo all pending operations
  261. }
  262. }
  263. /**
  264. * method show()
  265. * Shows the page
  266. */
  267. public function show()
  268. {
  269. // check if the datagrid is already loaded
  270. if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  271. {
  272. $this->onReload( func_get_arg(0) );
  273. }
  274. parent::show();
  275. }
  276. }
  277. ?>


</your>