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

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 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