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
Estou tentando substituir os checkgroups ( Grupos) da tela de usuários para SelectionList porém os items não selecionados, alguem pode me ajuda
- <?php
- class SystemUserForm extends TPage
- {
- protected $form; // form
- protected $program_list;
- protected $datagrid;
- protected $loaded;
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- parent::include_css('app/resources/builder.css');
- parent::include_css('app/resources/blue_modificado.css');
- parent::include_css('app/resources/custom-table.css');
- $organizacao_id = TSession::getValue('organizacion_id'); // pega id da empresa
- // creates the form
- $this->form = new BootstrapFormBuilder('form_System_user');
- $this->form->setFormTitle( _t('User') );
- // create the form fields
- $lbl_id = new TLabel('Id');
- $lbl_name = new TLabel(_t('Name'));
- //$lbl_login = new TLabel(_t('Login'));
- $lbl_password = new TLabel(_t('Password'));
- $lbl_confirm_password = new TLabel(_t('Password confirmation'));
- $lbl_email = new TLabel(_t('Email'));
- $lbl_unit = new TLabel(_t('Main unit'));
- $lbl_front_page = new TLabel(_t('Front page'));
- $lbl_id->class = 'lbl_text';
- $lbl_name->class = 'lbl_text';
- //$lbl_login->class = 'lbl_text';
- $lbl_password->class = 'lbl_text';
- $lbl_confirm_password->class = 'lbl_text';
- $lbl_email->class = 'lbl_text';
- $lbl_unit->class = 'lbl_text';
- $lbl_front_page->class = 'lbl_text';
- $id = new TEntry('id');
- $name = new TEntry('name');
- //$login = new TEntry('login');
- $password = new TPassword('password');
- $repassword = new TPassword('repassword');
- $email = new TEntry('email');
- $filter1 = new TCriteria;
- $filter1->add(new TFilter('organizacao_id','=',$organizacao_id));
- $unit_id = new TDBCombo('system_unit_id','permission','SystemOrganization','id','name');
- $program_id = new ">TDBSeekButton('program_id', 'permission', 'form_System_user', 'SystemProgram', 'name', 'program_id', 'program_name');
- $program_name = new TEntry('program_name');
- //alterado para grids
- //$groups = new TDBCheckGroup('groups','permission','SystemGroup','id','name');
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue('_selected_objects') );
- // creates a DataGrid
- $this->datagrid = new TDataGrid;
- $this->datagrid->style = 'width: 100%';
- // creates the datagrid columns
- $column_id = new TDataGridColumn('id', 'Id', 'left');
- $column_name = new TDataGridColumn('name', _t('Name'), 'left');
- $column_description = new TDataGridColumn('description', _t('Description'), 'left');
- // add the columns to the DataGrid
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_name);
- $this->datagrid->addColumn($column_description);
- // creates the datagrid actions
- $action1 = new TDataGridAction(array($this, 'onSelect'));
- $action1->setUseButton(TRUE);
- $action1->setButtonClass('btn btn-default');
- $action1->setLabel(AdiantiCoreTranslator::translate('Select'));
- $action1->setImage('fa:check-circle-o blue');
- $action1->setField('id');
- // add the actions to the datagrid
- $this->datagrid->addAction($action1);
- // create the datagrid model
- $this->datagrid->createModel();
- // create the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- $container_grid = new TVBox;
- $container_grid->add($this->datagrid);
- $container_grid->add($this->pageNavigation);
- $frontpage_id = new "> ">TDBSeekButton('frontpage_id', 'permission', 'form_System_user', 'SystemProgram', 'name', 'frontpage_id', 'frontpage_name');
- $frontpage_name = new TEntry('frontpage_name');
- $filter = new TCriteria;
- $filter->add(new TFilter('organizacao_id','<','0'));
- $organizacao = new TDBCheckGroup('organizacao','centinel','Organizacao','id','juridica_nome','id',$filter);
- $units = new TDBCheckGroup('units','permission','SystemUnit','id','name');
- $organizacao->setLayout('horizontal');
- if ($organizacao->getLabels())
- {
- foreach ($units->getLabels() as $label)
- {
- $label->setSize(200);
- }
- }
- $units->setLayout('horizontal');
- if ($units->getLabels())
- {
- foreach ($units->getLabels() as $label)
- {
- $label->setSize(200);
- }
- }
- //alterado para grids
- /*
- $groups->setLayout('horizontal');
- if ($groups->getLabels())
- {
- foreach ($groups->getLabels() as $label)
- {
- $label->setSize(200);
- }
- }
- */
- $btn = $this->form->addAction( _t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addAction( _t('Clear'), new TAction(array($this, 'onEdit')), 'fa:eraser red');
- $this->form->addAction( _t('Back'), new TAction(array('SystemUserList','onReload')), 'fa:arrow-circle-o-left blue');
- $add_button = TButton::create('add', array($this,'onAddProgram'), _t('Add'), 'fa:plus green');
- $this->form->addField($program_id);
- $this->form->addField($program_name);
- $this->form->addField($add_button);
- $this->program_list = new TQuickGrid;
- $this->program_list->setHeight(180);
- $this->program_list->makeScrollable();
- $this->program_list->style='width: 100%';
- $this->program_list->id = 'program_list';
- $this->program_list->disableDefaultClick();
- $this->program_list->addQuickColumn('', 'delete', 'center', '5%');
- $this->program_list->addQuickColumn('Id', 'id', 'left', '10%');
- $this->program_list->addQuickColumn(_t('Program'), 'name', 'left', '85%');
- $this->program_list->createModel();
- $hbox = new THBox;
- $hbox->add($program_id);
- $hbox->add($program_name, 'display:initial');
- $hbox->add($add_button);
- $hbox->style = 'margin: 4px';
- $vbox = new TVBox;
- $vbox->style='width:100%';
- $vbox->add( $hbox );
- $vbox->add($this->program_list);
- // define the sizes
- $id->setSize('50%');
- $name->setSize('100%');
- //$login->setSize('100%');
- $password->setSize('100%');
- $repassword->setSize('100%');
- $email->setSize('37.5%');
- $unit_id->setSize('100%');
- $frontpage_id->setSize('60');
- $frontpage_name->setSize('calc(100% - 60px)');
- $program_id->setSize('30');
- $program_name->setSize('calc(100% - 200px)');
- // outros
- $id->setEditable(false);
- $program_name->setEditable(false);
- $frontpage_name->setEditable(false);
- // validations
- $name->addValidation(_t('Name'), new TRequiredValidator);
- //$login->addValidation('Login', new TRequiredValidator);
- $email->addValidation('Email', new TEmailValidator);
- $this->form->addFields( [$lbl_id], [$id], [$lbl_name], [$name] );
- $this->form->addFields( [$lbl_email], [$email] );
- $this->form->addFields( [$lbl_unit], [$unit_id], [$lbl_front_page], [$frontpage_id, $frontpage_name] );
- $this->form->addFields( [$lbl_password], [$password], [$lbl_confirm_password], [$repassword] );
- $this->form->addFields( [new TFormSeparator('')]);
- /*
- $this->form->addFields( [new TFormSeparator('')]);
- $dados_empresa = new TLabel(_t('Company'));
- $dados_empresa->class ='lbl_titulo';
- $this->form->addContent( [$dados_empresa] );
- $this->form->addFields( [$organizacao] );
- */
- // $this->form->addFields( [new TFormSeparator(_t('Units'))] );
- $dados_unit = new TLabel(_t('Units'));
- $dados_unit->class ='lbl_titulo';
- $this->form->addContent( [$dados_unit] );
- $this->form->addFields( [$units] );
- $this->form->addFields( [new TFormSeparator('')] );
- $dados_grupo = new TLabel(_t('Groups'));
- $dados_grupo->class ='lbl_titulo';
- $this->form->addContent( [$dados_grupo] );
- //$this->form->addFields( [$groups] );
- $this->form->addFields( [$container_grid] );
- $this->form->addFields( [new TFormSeparator(_t('Programs'))] );
- $this->form->addFields( [$vbox] );
- $container = new TVBox;
- $container->style = 'width: 90%';
- $container->add(new TXMLBreadCrumb('menu.xml', 'SystemUserList'));
- $container->add($this->form);
- // add the container to the page
- parent::add($container);
- }
- /**
- * Save the object reference in session
- */
- public function onSelect($param)
- {
- // get the selected objects from session
- $selected_objects = TSession::getValue(__CLASS__.'_selected_objects');
- TTransaction::open('permission');
- $object = new SystemGroup($param['id']); // load the object
- if (isset($selected_objects[$object->id]))
- {
- unset($selected_objects[$object->id]);
- }
- else
- {
- $selected_objects[$object->id] = $object->toArray(); // add the object inside the array
- }
- TSession::setValue(__CLASS__.'_selected_objects', $selected_objects); // put the array back to the session
- TTransaction::close();
- // reload datagrids
- $this->onReload( func_get_arg(0) );
- }
- function onReload($param = NULL){
- try{
- // open a transaction with database 'samples'
- TTransaction::open('permission');
- // creates a repository for Product
- $repository = new TRepository('SystemGroup');
- $limit = 5;
- // 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);
- $criteria->setProperty('order', 'description');
- // load the objects according to criteria
- $objects = $repository->load($criteria);
- //print_r($objects);
- $this->datagrid->clear();
- if ($objects)
- {
- 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){
- new TMessage('error',$e->getMessage());
- TTransaction::rollback();
- }
- }
- function show(){
- // check if the datagrid is already loaded
- if (!$this->loaded){
- $this->onReload( func_get_arg(0) );
- }
- parent::show();
- }
- ?>
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.
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
adianti.com.br/framework_files/tutor/index.php?class=ContainerScroll