Item da SelectionList não são selecionados Ola, Estou tentando substituir os checkgroups ( Grupos) da tela de usuários para SelectionList porém os items não selecionados, alguem pode me ajuda ...
RB
Item da SelectionList não são selecionados  
Ola,

Estou tentando substituir os checkgroups ( Grupos) da tela de usuários para SelectionList porém os items não selecionados, alguem pode me ajuda


 
  1. <?php
  2. class SystemUserForm extends TPage
  3. {
  4. protected $form; // form
  5. protected $program_list;
  6. protected $datagrid;
  7. protected $loaded;
  8. /**
  9. * Class constructor
  10. * Creates the page and the registration form
  11. */
  12. function __construct()
  13. {
  14. parent::__construct();
  15. parent::include_css('app/resources/builder.css');
  16. parent::include_css('app/resources/blue_modificado.css');
  17. parent::include_css('app/resources/custom-table.css');
  18. $organizacao_id = TSession::getValue('organizacion_id'); // pega id da empresa
  19. // creates the form
  20. $this->form = new BootstrapFormBuilder('form_System_user');
  21. $this->form->setFormTitle( _t('User') );
  22. // create the form fields
  23. $lbl_id = new TLabel('Id');
  24. $lbl_name = new TLabel(_t('Name'));
  25. //$lbl_login = new TLabel(_t('Login'));
  26. $lbl_password = new TLabel(_t('Password'));
  27. $lbl_confirm_password = new TLabel(_t('Password confirmation'));
  28. $lbl_email = new TLabel(_t('Email'));
  29. $lbl_unit = new TLabel(_t('Main unit'));
  30. $lbl_front_page = new TLabel(_t('Front page'));
  31. $lbl_id->class = 'lbl_text';
  32. $lbl_name->class = 'lbl_text';
  33. //$lbl_login->class = 'lbl_text';
  34. $lbl_password->class = 'lbl_text';
  35. $lbl_confirm_password->class = 'lbl_text';
  36. $lbl_email->class = 'lbl_text';
  37. $lbl_unit->class = 'lbl_text';
  38. $lbl_front_page->class = 'lbl_text';
  39. $id = new TEntry('id');
  40. $name = new TEntry('name');
  41. //$login = new TEntry('login');
  42. $password = new TPassword('password');
  43. $repassword = new TPassword('repassword');
  44. $email = new TEntry('email');
  45. $filter1 = new TCriteria;
  46. $filter1->add(new TFilter('organizacao_id','=',$organizacao_id));
  47. $unit_id = new TDBCombo('system_unit_id','permission','SystemOrganization','id','name');
  48. $program_id = new ">TDBSeekButton('program_id', 'permission', 'form_System_user', 'SystemProgram', 'name', 'program_id', 'program_name');
  49. $program_name = new TEntry('program_name');
  50. //alterado para grids
  51. //$groups = new TDBCheckGroup('groups','permission','SystemGroup','id','name');
  52. // keep the form filled during navigation with session data
  53. $this->form->setData( TSession::getValue('_selected_objects') );
  54. // creates a DataGrid
  55. $this->datagrid = new TDataGrid;
  56. $this->datagrid->style = 'width: 100%';
  57. // creates the datagrid columns
  58. $column_id = new TDataGridColumn('id', 'Id', 'left');
  59. $column_name = new TDataGridColumn('name', _t('Name'), 'left');
  60. $column_description = new TDataGridColumn('description', _t('Description'), 'left');
  61. // add the columns to the DataGrid
  62. $this->datagrid->addColumn($column_id);
  63. $this->datagrid->addColumn($column_name);
  64. $this->datagrid->addColumn($column_description);
  65. // creates the datagrid actions
  66. $action1 = new TDataGridAction(array($this, 'onSelect'));
  67. $action1->setUseButton(TRUE);
  68. $action1->setButtonClass('btn btn-default');
  69. $action1->setLabel(AdiantiCoreTranslator::translate('Select'));
  70. $action1->setImage('fa:check-circle-o blue');
  71. $action1->setField('id');
  72. // add the actions to the datagrid
  73. $this->datagrid->addAction($action1);
  74. // create the datagrid model
  75. $this->datagrid->createModel();
  76. // create the page navigation
  77. $this->pageNavigation = new TPageNavigation;
  78. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  79. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  80. $container_grid = new TVBox;
  81. $container_grid->add($this->datagrid);
  82. $container_grid->add($this->pageNavigation);
  83. $frontpage_id = new ">">TDBSeekButton('frontpage_id', 'permission', 'form_System_user', 'SystemProgram', 'name', 'frontpage_id', 'frontpage_name');
  84. $frontpage_name = new TEntry('frontpage_name');
  85. $filter = new TCriteria;
  86. $filter->add(new TFilter('organizacao_id','<','0'));
  87. $organizacao = new TDBCheckGroup('organizacao','centinel','Organizacao','id','juridica_nome','id',$filter);
  88. $units = new TDBCheckGroup('units','permission','SystemUnit','id','name');
  89. $organizacao->setLayout('horizontal');
  90. if ($organizacao->getLabels())
  91. {
  92. foreach ($units->getLabels() as $label)
  93. {
  94. $label->setSize(200);
  95. }
  96. }
  97. $units->setLayout('horizontal');
  98. if ($units->getLabels())
  99. {
  100. foreach ($units->getLabels() as $label)
  101. {
  102. $label->setSize(200);
  103. }
  104. }
  105. //alterado para grids
  106. /*
  107. $groups->setLayout('horizontal');
  108. if ($groups->getLabels())
  109. {
  110. foreach ($groups->getLabels() as $label)
  111. {
  112. $label->setSize(200);
  113. }
  114. }
  115. */
  116. $btn = $this->form->addAction( _t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  117. $btn->class = 'btn btn-sm btn-primary';
  118. $this->form->addAction( _t('Clear'), new TAction(array($this, 'onEdit')), 'fa:eraser red');
  119. $this->form->addAction( _t('Back'), new TAction(array('SystemUserList','onReload')), 'fa:arrow-circle-o-left blue');
  120. $add_button = TButton::create('add', array($this,'onAddProgram'), _t('Add'), 'fa:plus green');
  121. $this->form->addField($program_id);
  122. $this->form->addField($program_name);
  123. $this->form->addField($add_button);
  124. $this->program_list = new TQuickGrid;
  125. $this->program_list->setHeight(180);
  126. $this->program_list->makeScrollable();
  127. $this->program_list->style='width: 100%';
  128. $this->program_list->id = 'program_list';
  129. $this->program_list->disableDefaultClick();
  130. $this->program_list->addQuickColumn('', 'delete', 'center', '5%');
  131. $this->program_list->addQuickColumn('Id', 'id', 'left', '10%');
  132. $this->program_list->addQuickColumn(_t('Program'), 'name', 'left', '85%');
  133. $this->program_list->createModel();
  134. $hbox = new THBox;
  135. $hbox->add($program_id);
  136. $hbox->add($program_name, 'display:initial');
  137. $hbox->add($add_button);
  138. $hbox->style = 'margin: 4px';
  139. $vbox = new TVBox;
  140. $vbox->style='width:100%';
  141. $vbox->add( $hbox );
  142. $vbox->add($this->program_list);
  143. // define the sizes
  144. $id->setSize('50%');
  145. $name->setSize('100%');
  146. //$login->setSize('100%');
  147. $password->setSize('100%');
  148. $repassword->setSize('100%');
  149. $email->setSize('37.5%');
  150. $unit_id->setSize('100%');
  151. $frontpage_id->setSize('60');
  152. $frontpage_name->setSize('calc(100% - 60px)');
  153. $program_id->setSize('30');
  154. $program_name->setSize('calc(100% - 200px)');
  155. // outros
  156. $id->setEditable(false);
  157. $program_name->setEditable(false);
  158. $frontpage_name->setEditable(false);
  159. // validations
  160. $name->addValidation(_t('Name'), new TRequiredValidator);
  161. //$login->addValidation('Login', new TRequiredValidator);
  162. $email->addValidation('Email', new TEmailValidator);
  163. $this->form->addFields( [$lbl_id], [$id], [$lbl_name], [$name] );
  164. $this->form->addFields( [$lbl_email], [$email] );
  165. $this->form->addFields( [$lbl_unit], [$unit_id], [$lbl_front_page], [$frontpage_id, $frontpage_name] );
  166. $this->form->addFields( [$lbl_password], [$password], [$lbl_confirm_password], [$repassword] );
  167. $this->form->addFields( [new TFormSeparator('')]);
  168. /*
  169. $this->form->addFields( [new TFormSeparator('')]);
  170. $dados_empresa = new TLabel(_t('Company'));
  171. $dados_empresa->class ='lbl_titulo';
  172. $this->form->addContent( [$dados_empresa] );
  173. $this->form->addFields( [$organizacao] );
  174. */
  175. // $this->form->addFields( [new TFormSeparator(_t('Units'))] );
  176. $dados_unit = new TLabel(_t('Units'));
  177. $dados_unit->class ='lbl_titulo';
  178. $this->form->addContent( [$dados_unit] );
  179. $this->form->addFields( [$units] );
  180. $this->form->addFields( [new TFormSeparator('')] );
  181. $dados_grupo = new TLabel(_t('Groups'));
  182. $dados_grupo->class ='lbl_titulo';
  183. $this->form->addContent( [$dados_grupo] );
  184. //$this->form->addFields( [$groups] );
  185. $this->form->addFields( [$container_grid] );
  186. $this->form->addFields( [new TFormSeparator(_t('Programs'))] );
  187. $this->form->addFields( [$vbox] );
  188. $container = new TVBox;
  189. $container->style = 'width: 90%';
  190. $container->add(new TXMLBreadCrumb('menu.xml', 'SystemUserList'));
  191. $container->add($this->form);
  192. // add the container to the page
  193. parent::add($container);
  194. }
  195. /**
  196. * Save the object reference in session
  197. */
  198. public function onSelect($param)
  199. {
  200. // get the selected objects from session
  201. $selected_objects = TSession::getValue(__CLASS__.'_selected_objects');
  202. TTransaction::open('permission');
  203. $object = new SystemGroup($param['id']); // load the object
  204. if (isset($selected_objects[$object->id]))
  205. {
  206. unset($selected_objects[$object->id]);
  207. }
  208. else
  209. {
  210. $selected_objects[$object->id] = $object->toArray(); // add the object inside the array
  211. }
  212. TSession::setValue(__CLASS__.'_selected_objects', $selected_objects); // put the array back to the session
  213. TTransaction::close();
  214. // reload datagrids
  215. $this->onReload( func_get_arg(0) );
  216. }
  217. function onReload($param = NULL){
  218. try{
  219. // open a transaction with database 'samples'
  220. TTransaction::open('permission');
  221. // creates a repository for Product
  222. $repository = new TRepository('SystemGroup');
  223. $limit = 5;
  224. // creates a criteria
  225. $criteria = new TCriteria;
  226. // default order
  227. if (empty($param['order']))
  228. {
  229. $param['order'] = 'id';
  230. $param['direction'] = 'asc';
  231. }
  232. $criteria->setProperties($param); // order, offset
  233. $criteria->setProperty('limit', $limit);
  234. $criteria->setProperty('order', 'description');
  235. // load the objects according to criteria
  236. $objects = $repository->load($criteria);
  237. //print_r($objects);
  238. $this->datagrid->clear();
  239. if ($objects)
  240. {
  241. foreach ($objects as $object)
  242. {
  243. // add the object inside the datagrid
  244. $this->datagrid->addItem($object);
  245. }
  246. }
  247. // reset the criteria for record count
  248. $criteria->resetProperties();
  249. $count = $repository->count($criteria);
  250. $this->pageNavigation->setCount($count); // count of records
  251. $this->pageNavigation->setProperties($param); // order, page
  252. $this->pageNavigation->setLimit($limit); // limit
  253. // close the transaction
  254. TTransaction::close();
  255. $this->loaded = true;
  256. }
  257. catch (Exception $e){
  258. new TMessage('error',$e->getMessage());
  259. TTransaction::rollback();
  260. }
  261. }
  262. function show(){
  263. // check if the datagrid is already loaded
  264. if (!$this->loaded){
  265. $this->onReload( func_get_arg(0) );
  266. }
  267. parent::show();
  268. }
  269. ?>

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


NR

Você está salvando os itens selecionados na sessão mas não está fazendo nada com esses itens. Imagino que sua ideia seja destacar as linhas selecionadas com outra cor. Essa parte não foi implementada. Veja:
adianti.com.br/framework_files/tutor/index.php?class=ProductSelectio

Além disso, após destacar as linhas, como você planeja preencher o formulário com os dados digitados anteriormente? Não esqueça que as ações da grid são feitas via get e não post. Mesma coisa para a paginação.

Particularmente acho que usar grid adiciona uma complexidade desnecessária nesse cadastro.
RB

Nataniel,

Na realidade queria melhorar a aparência, pois neste caso quando temos muitos grupos a tela fica muito grande

se tivesse como paginar este checks já ajudária.

Veja : sgo.net.br/index.php?class=PublicView&PHPSESSID=fe3378b19448aed8
NR

adianti.com.br/framework_files/tutor/index.php?class=ContainerScroll