Exemplo n.º 1
0
 public function __construct($param)
 {
     $this->isValidType($param->type);
     $this->_nav = new UL();
     $this->_nav->addClass('nav')->addClass('nav-' . $param->type);
     foreach ($param->item as $item) {
         $this->_item = new LI();
         # Menu Dropdown
         if (isset($item['dropdown'])) {
             $divider = new \br\gov\sial\core\output\screen\html\Strong();
             $divider->addClass('caret');
             $link = new Anchor($item['text'] . ' ' . $divider, $item['href']);
             $link->addClass('dropdown-toggle')->attr('data-toggle', 'dropdown');
             $this->_item->add($link);
             $this->_item->addClass('dropdown');
             $this->_dropdown = new UL();
             $this->_dropdown->addClass('dropdown-menu');
             foreach ($item['dropdown'] as $subItem) {
                 $li = new LI();
                 $li->add(new Anchor($subItem['text'], $subItem['href']));
                 $this->_dropdown->add($li);
             }
             $this->_item->add($this->_dropdown);
         } else {
             $this->_item->add(new Anchor($item['text'], $item['href']));
         }
         if ($item['text'] == $param->active) {
             $this->_item->addClass('active');
         }
         $this->_nav->add($this->_item);
     }
 }
Exemplo n.º 2
0
 /**
  * Retorna uma lista dos elementos que compõe o componente brandbar
  * @param \stdClass $param
  * @return \br\gov\sial\core\output\screen\html\UL
  */
 private function setElements($param)
 {
     $ul = new UL();
     $ul->addClass('nav');
     foreach ($this->safeToggle($param, 'links', array()) as $link) {
         $li = new LI();
         $li->add(new Anchor($link['text'], $link['href']));
         $ul->add($li);
     }
     return $ul;
 }
Exemplo n.º 3
0
 /**
  * Cria menu.
  *
  * @param stdClass
  * @return Div
  * */
 public function menuNavbar(\stdClass $config)
 {
     # navbar
     $mainDiv = new Div();
     $mainDiv->addClass(array('navbar', 'navbar-fixed-top'));
     # inner
     $divInner = new Div();
     $divInner->addClass('navbar-inner');
     $mainDiv->add($divInner);
     # fluid
     $divFluid = new Div();
     $divFluid->addClass('container-fluid');
     $divInner->add($divFluid);
     # anchor
     $anchor = new Anchor();
     $anchor->attr('data-target', '.nav-collapse')->attr('data-toggle', 'collapse')->addClass(array('btn', 'btn-navbar'));
     $divFluid->add($anchor);
     # @todo a quantidade de icon-bar deve ser dinamica
     $span = new Span();
     $span->addClass('icon-bar');
     $anchor->add(array(clone $span, clone $span, $span));
     $divCollapse = new Div();
     $divCollapse->addClass('nav-collapse');
     $divFluid->add($divCollapse);
     $ulNav = new UL();
     $ulNav->addClass('nav');
     $divCollapse->add($ulNav);
     foreach ($config->options as $key => $val) {
         $li = new LI();
         $ulNav->add($li);
         if ('__DIVIDER_VERTICAL__' == $val) {
             $li->addClass('divider-vertical');
         } else {
             $li->addClass('dropdown');
             $anchor = new Anchor($key, '#');
             $anchor->attr('data-toggle', 'dropdown')->addClass('dropdown-toggle');
             $li->add($anchor);
             $strong = new Strong();
             $strong->addClass('caret');
             $anchor->add($strong);
             $ul = new UL();
             $ul->addClass('dropdown-menu');
             $li->add($ul);
             foreach ($val as $idx => $link) {
                 $anchor = new Anchor($link['text'], $link['href']);
                 $liSub = new LI();
                 $liSub->add($anchor);
                 $ul->add($liSub);
             }
         }
     }
     return $mainDiv;
 }
Exemplo n.º 4
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;
 }