Пример #1
0
 /**
  * Adiciona o título do modal
  * @param stdClass $param
  * @return \br\gov\sial\core\output\screen\component\html\Modal
  */
 private function setTitle($param)
 {
     $header = H3::factory()->setContent($param->title)->attr('id', 'myModalLabel');
     $close = Button::factory('×')->addClass('close')->attr('aria-hidden', 'true')->attr('data-dismiss', 'modal')->attr('type', 'button');
     $this->_title = Div::factory()->addClass('modal-header')->add($close)->add($header);
     return $this;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  * @param stdClass $param{
  *    string filterTitle = NULL,
  *    string comboName,
  *    string[] comboData,
  *    string comboValue,
  *    string comboText
  * }
  * @return Div
  * */
 public function smartFilter(\stdClass $param)
 {
     # este componente eh formado de 3 partes:
     # 1 - entrada dos filtros
     # 2 - exibicao do resultado, grid
     # 3 - detalhamento de resultado, exibe todos os campos do registro selecionado
     #     na grid de resultado (parte #2)
     $seed = $this->safeToggle($param, 'id', rand(1, 999));
     $elmId = 'sf' . $seed;
     # container geral, que agrupa todo o component (filter, grid)
     $divSmartyFilter = Div::factory()->attr('id', 'containerSmartyFilter' . $seed);
     $divAlert = Div::factory()->attr('id', 'gridDivAlert');
     $divSmartyFilter->add($divAlert);
     # cria linha contendo
     $container = Div::factory()->addClass('input-prepend')->attr('id', $elmId);
     # criar wraper dos elementos de selecao
     $divGroup = Div::factory()->addClass('btn-group');
     # botao de seleciona de opcao de filtro
     $btnAction = new Button('opção', 'smartFilterBtnAction');
     $btnAction->addClass(array('btn', 'btnAction'))->attr('tabindex', -1);
     # botao dropdown
     $btnDropdown = Button::factory()->addClass(array('btn', 'dropdown-toggle'))->attr('tabindex', -1)->attr('data-toggle', 'dropdown')->add(Span::factory()->addClass('caret'));
     #opcao do menu dropdown
     $dropDownMenu = UL::factory()->addClass('dropdown-menu');
     # gera lista de opcao do menu
     foreach ($this->safeToggle($param, 'comboOptions', new \stdClass()) as $option) {
         $option = (object) $option;
         $text = $param->comboText;
         $value = $param->comboValue;
         $anchor = new Anchor($option->{$text}, '#' . $option->{$value}, $target = NULL);
         $elm = LI::factory()->add($anchor);
         $dropDownMenu->add($elm);
     }
     # div modal para manipulacao dos valores da grid
     $divModal = Div::factory()->addClass(array('SFModal', 'modal', 'hide'))->attr('tabindex', -1)->attr('role', 'dialog')->attr('aria-hidden', 'true');
     $divModalHeader = Div::factory()->addClass(array('modal-header'));
     $divModalHeaderTlt = H3::factory();
     $divModalHeaderBtn = Button::factory('x')->addClass('close')->attr('aria-hidden', 'true')->attr('data-toggle', 'modal');
     $divModalHeader->add($divModalHeaderBtn)->add($divModalHeaderTlt);
     $divModalBody = Div::factory()->addClass(array('modal-body', 'modal-body-margin'));
     $divModalFooter = Div::factory()->addClass(array('modal-footer'));
     $modalFooterBtnClose = Anchor::factory('Fechar')->addClass('btn')->attr('id', 'modalBtnClose');
     $modalFooterBtnSaveChange = Anchor::factory('Salvar Alterações')->addClass(array('btn', 'btn-primary'))->attr('id', 'modalBtnSaveChange');
     $divModalFooter->add($modalFooterBtnClose)->add($modalFooterBtnSaveChange);
     $divModal->add($divModalHeader)->add($divModalBody)->add($divModalFooter);
     # @todo substituir pelo componente modal
     $divSmartyFilter->add($divModal);
     # armazena o valor da ultima opcao selecionada este campo vai suprir a necessidade de efetuar
     # uma varredura no lado do cliente para saber qual das N options foi selecionada, tendo em vista
     # que o campo do filter nao eh um HTMLSelect real.
     $inputSelected = $this->input((object) array('name' => 'selectedIndex', 'type' => 'hidden'));
     $inputSelected->id = 'selectedIndex';
     $divSmartyFilter->add($inputSelected);
     # armazena os nomes das colunas
     $columns = $this->input((object) array('name' => 'columns', 'type' => 'hidden', 'value' => str_replace('"', "'", json_encode($param->grid->columns))));
     $divSmartyFilter->add($columns);
     # armazena a rowkey
     $divSmartyFilter->add($this->input((object) array('name' => 'rowKey', 'type' => 'hidden', 'value' => $this->safeToggle($param->grid, 'rowKey'))));
     # armazena eventos agendados para cada linha da grid
     $divSmartyFilter->add($this->input((object) array('name' => 'event', 'type' => 'hidden', 'value' => str_replace('"', "'", json_encode($this->safeToggle($param->grid, 'event', 0))))));
     # input que vai receber o param de pesquisa
     $param->comboName = 'smartFilterInput';
     $input = new Input($param->comboName);
     # monta o componente
     $divGroup->add($btnAction)->add($btnDropdown)->add($dropDownMenu)->add($input);
     # barra de botoes
     $toobar = $this->buttonbar((object) array('options' => array('search')));
     /* @return string */
     $arrPHPtoObjectJs = function (\stdClass $param) {
         $object = '{';
         foreach ($param as $key => $val) {
             switch (gettype($val)) {
                 case 'string':
                     $val = sprintf('"%s"', $val);
                     break;
                 case 'boolean':
                     $val = sprintf('%s', $val ? 'true' : 'false');
                     break;
             }
             $object .= sprintf('%s:%s,', $key, $val);
         }
         $object = substr($object, 0, -1) . '}';
         return $object;
     };
     # injeta ID da grid para que a parte JS possa localiza-la
     $param->httpRequest->gridID = sprintf('#table-%1$s_wrapper', $elmId);
     $scriptDocReady = new Text(sprintf('<script>$(document).ready(function () {$("#%1$s").smartFilter(%2$s); $("%3$s").hide();});</script>', $elmId, $arrPHPtoObjectJs($param->httpRequest), $param->httpRequest->gridID));
     # primeira parte do componente (filter)
     $container->add($divGroup)->add($toobar);
     # segunda parte do component (grid)
     $gridConf = new \stdClass();
     $gridConf->title = $elmId;
     $gridConf->columns = $param->grid->columns;
     $gridConf->data = array();
     $gridConf->httpRequest = $param->httpRequest;
     $gridConf->name = $gridConf->title;
     $grid = $this->grid($gridConf)->setUrlJS($param->cdn)->registerHttpInfo(json_encode($param->httpRequest))->loadDataOnReady();
     $divSmartyFilter->add($container)->add($grid)->add($scriptDocReady);
     return $divSmartyFilter;
 }