Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TDropDown.php

Documentation is available at TDropDown.php

  1. <?php
  2. namespace Adianti\Widget\Util;
  3.  
  4. use Adianti\Core\AdiantiCoreTranslator;
  5. use Adianti\Control\TAction;
  6. use Adianti\Widget\Base\TElement;
  7. use Adianti\Widget\Base\TScript;
  8. use Adianti\Widget\Util\TImage;
  9.  
  10. /**
  11.  * TDropDown Widget
  12.  *
  13.  * @version    7.4
  14.  * @package    widget
  15.  * @subpackage util
  16.  * @author     Pablo Dall'Oglio
  17.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  18.  * @license    http://www.adianti.com.br/framework-license
  19.  */
  20. class TDropDown extends TElement
  21. {
  22.     protected $elements;
  23.     private $button;
  24.     
  25.     /**
  26.      * Class Constructor
  27.      * @param $title Dropdown title
  28.      * @param $icon  Dropdown icon
  29.      */
  30.     public function __construct($label$icon NULL$use_caret FALSE$title ''$height null)
  31.     {
  32.         parent::__construct('div');
  33.         $this->{'class''btn-group';
  34.         $this->{'style''display:inline-block; -moz-user-select: none; -webkit-user-select:none; user-select:none;';
  35.         
  36.         $button new TElement('button');
  37.         $button->{'data-toggle''dropdown';
  38.         $button->{'class'}       'btn btn-default btn-sm dropdown-toggle';
  39.         $this->button $button;
  40.         
  41.         if ($icon)
  42.         {
  43.             $button->add(new TImage($icon));
  44.         }
  45.         
  46.         if ($title)
  47.         {
  48.             $button->{'title'$title;
  49.         }
  50.         $button->add($label);
  51.         
  52.         if ($use_caret)
  53.         {
  54.             $span new TElement('span');
  55.             $span->{'class''fa fa-chevron-down';
  56.             $span->{'style''margin-left: 3px';
  57.             $button->add($span);
  58.         }
  59.         
  60.         parent::add($button);
  61.         
  62.         //$this->id = 'tdropdown_' . mt_rand(1000000000, 1999999999);
  63.         $this->elements new TElement('ul');
  64.         $this->elements->{'class''dropdown-menu pull-left';
  65.         $this->elements->{'aria-labelledby''drop2';
  66.         $this->elements->{'widget''tdropdown';
  67.         
  68.         if (!empty($height))
  69.         {
  70.             $this->elements->{'style'"height:{$height}px;overflow:auto";
  71.         }
  72.         parent::add($this->elements);
  73.     }
  74.     
  75.     /**
  76.      * Define the pull side
  77.      * @side left/right
  78.      */
  79.     public function setPullSide($side)
  80.     {
  81.         $this->elements->{'class'"dropdown-menu pull-{$side} dropdown-menu-{$side}";
  82.     }
  83.  
  84.     /**
  85.      * Define the button size
  86.      * @size sm (small) lg (large)
  87.      */
  88.     public function setButtonSize($size)
  89.     {
  90.         $this->button->{'class'"btn btn-default btn-{$size} dropdown-toggle";
  91.     }
  92.     
  93.     /**
  94.      * Define the button class
  95.      * @class CSS class
  96.      */
  97.     public function setButtonClass($class)
  98.     {
  99.         $this->button->{'class'$class;
  100.     }
  101.     
  102.     /**
  103.      * Returns the dropdown button
  104.      */
  105.     public function getButton()
  106.     {
  107.         return $this->button;
  108.     }
  109.     
  110.     /**
  111.      * Add an action
  112.      * @param $title  Title
  113.      * @param $action Action (TAction or string Javascript action)
  114.      * @param $icon   Icon
  115.      */
  116.     public function addAction($title$action$icon NULL$popover ''$add true)
  117.     {
  118.         $li new TElement('li');
  119.         // $li->{'class'} = "dropdown-item";
  120.         $link new TElement('a');
  121.         
  122.         if ($action instanceof TAction)
  123.         
  124.             $link->{'href'$action->serialize();
  125.             $link->{'generator'"adianti";
  126.         }
  127.         else if (is_string($action))
  128.         {
  129.             $link->{'onclick'$action;
  130.         }
  131.         $link->{'style''cursor: pointer';
  132.         
  133.         if ($popover)
  134.         {
  135.             $link->{'title'$popover;
  136.         }
  137.         
  138.         if ($icon)
  139.         {
  140.             $image is_object($iconclone $icon new TImage($icon);
  141.             $image->{'style'.= ';padding: 4px';
  142.             $link->add($image);
  143.         }
  144.         
  145.         $span new TElement('span');
  146.         $span->add($title);
  147.         $link->add($span);
  148.         $li->add($link);
  149.         
  150.         if ($add)
  151.         {
  152.             $this->elements->add($li);
  153.         }
  154.         return $li;
  155.     }
  156.     
  157.     /**
  158.      * Add an action
  159.      * @param $title  Title
  160.      * @param $action Action (TAction or string Javascript action)
  161.      * @param $icon   Icon
  162.      */
  163.     public function addPostAction($title$action$form$icon NULL$popover ''$add true)
  164.     {
  165.         $li new TElement('li');
  166.         
  167.         $link new TElement('a');
  168.         
  169.         if ($action instanceof TAction)
  170.         
  171.             $url $action->serialize(FALSE);
  172.             
  173.             if ($action->isStatic())
  174.             {
  175.                 $url .= '&static=1';
  176.             }
  177.             $url htmlspecialchars($url);
  178.             $wait_message AdiantiCoreTranslator::translate('Loading');
  179.             
  180.             // define the button's action (ajax post)
  181.             $action "Adianti.waitMessage = '$wait_message';";
  182.             $action.= "{$this->functions}";
  183.             $action.= "__adianti_post_data('{$form}', '{$url}');";
  184.             $action.= "return false;";
  185.             
  186.             $link->{'onclick'$action;
  187.         }
  188.         else if (is_string($action))
  189.         {
  190.             $link->{'onclick'$action;
  191.         }
  192.         $link->{'style''cursor: pointer';
  193.         
  194.         if ($popover)
  195.         {
  196.             $link->{'title'$popover;
  197.         }
  198.         
  199.         if ($icon)
  200.         {
  201.             $image is_object($iconclone $icon new TImage($icon);
  202.             $image->{'style'.= ';padding: 4px';
  203.             $link->add($image);
  204.         }
  205.         
  206.         $span new TElement('span');
  207.         $span->add($title);
  208.         $link->add($span);
  209.         $li->add($link);
  210.         
  211.         if ($add)
  212.         {
  213.             $this->elements->add($li);
  214.         }
  215.         return $li;
  216.     }
  217.     
  218.     /**
  219.      * Add an action group
  220.      */
  221.     public function addActionGroup($title$actions$icon)
  222.     {
  223.         $li new TElement('li');
  224.         $li->{'class'"dropdown-submenu";
  225.         $link new TElement('a');
  226.         $span new TElement('span');
  227.         
  228.         if ($icon)
  229.         {
  230.             $image is_object($iconclone $icon new TImage($icon);
  231.             $image->{'style'.= ';padding: 4px';
  232.             $link->add($image);
  233.         }
  234.         
  235.         $span->add($title);
  236.         $link->add($span);
  237.         $li->add($link);
  238.         
  239.         $ul new TElement('ul');
  240.         $ul->{'class'"dropdown-menu";
  241.         $li->add($ul);
  242.         if ($actions)
  243.         {
  244.             foreach ($actions as $action)
  245.             {
  246.                 $ul->add$this->addAction$action[0]$action[1]$action[2]''false ) );
  247.             }
  248.         }
  249.         
  250.         $this->elements->add($li);
  251.     }
  252.     
  253.     /**
  254.      * Add a header
  255.      * @param $header Options Header
  256.      */
  257.     public function addHeader($header)
  258.     {
  259.         $li new TElement('li');
  260.         $li->{'role''presentation';
  261.         $li->{'class''dropdown-header';
  262.         $li->add($header);
  263.         $this->elements->add($li);
  264.     }
  265.     
  266.     /**
  267.      * Add a separator
  268.      */
  269.     public function addSeparator()
  270.     {
  271.         $li new TElement('li');
  272.         $li->{'class''dropdown-divider';
  273.         $this->elements->add($li);
  274.     }
  275.     
  276.     /**
  277.      * Clear child elements
  278.      */
  279.     public function clearItems()
  280.     {
  281.         $this->elements->clearChildren();
  282.     }
  283. }