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 TCheckButton.php

Documentation is available at TCheckButton.php

  1. <?php
  2. namespace Adianti\Widget\Form;
  3.  
  4. use Adianti\Widget\Base\TElement;
  5. use Adianti\Widget\Form\AdiantiWidgetInterface;
  6. use Adianti\Widget\Form\TField;
  7. use Adianti\Widget\Form\TLabel;
  8.  
  9. /**
  10.  * CheckButton widget
  11.  *
  12.  * @version    7.4
  13.  * @package    widget
  14.  * @subpackage form
  15.  * @author     Pablo Dall'Oglio
  16.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  17.  * @license    http://www.adianti.com.br/framework-license
  18.  */
  19. class TCheckButton extends TField implements AdiantiWidgetInterface
  20. {
  21.     private $indexValue;
  22.     private $useSwitch;
  23.     private $labelClass;
  24.     
  25.     /**
  26.      * Class Constructor
  27.      * @param $name Name of the widget
  28.      */
  29.     public function __construct($name)
  30.     {
  31.         parent::__construct($name);
  32.         $this->id = 'tcheckbutton_' mt_rand(10000000001999999999);
  33.         $this->tag->{'class''';
  34.         $this->useSwitch  FALSE;
  35.     }
  36.     
  37.     /**
  38.      * Show as switch
  39.      */
  40.     public function setUseSwitch($useSwitch TRUE$labelClass 'blue')
  41.     {
  42.        $this->labelClass 'tswitch ' $labelClass;
  43.        $this->useSwitch  $useSwitch;
  44.     }
  45.  
  46.     /**
  47.      * Define the index value for check button
  48.      * @index Index value
  49.      */
  50.     public function setIndexValue($index)
  51.     {        
  52.         $this->indexValue $index;
  53.     }
  54.     
  55.     /**
  56.      * Shows the widget at the screen
  57.      */
  58.     public function show()
  59.     {
  60.         // define the tag properties for the checkbutton
  61.         $this->tag->{'name'}  $this->name;    // tag name
  62.         $this->tag->{'type'}  'checkbox';     // input type
  63.         $this->tag->{'value'$this->indexValue;   // value
  64.         
  65.         if ($this->id and empty($this->tag->{'id'}))
  66.         {
  67.             $this->tag->{'id'$this->id;
  68.         }
  69.         
  70.         // compare current value with indexValue
  71.         if ($this->indexValue == $this->value AND !(is_null($this->value)) AND strlen((string) $this->value0)
  72.         {
  73.             $this->tag->{'checked''1';
  74.         }
  75.         
  76.         // check whether the widget is non-editable
  77.         if (!parent::getEditable())
  78.         {
  79.             // make the widget read-only
  80.             //$this->tag-> disabled   = "1"; // the value don't post
  81.             $this->tag->{'onclick'"return false;";
  82.             $this->tag->{'style'}   'pointer-events:none';
  83.             $this->tag->{'tabindex''-1';
  84.         }
  85.         
  86.         if ($this->useSwitch)
  87.         {
  88.             $obj new TLabel('');
  89.             $obj->{'class''tswitch ' $this->labelClass;
  90.             $obj->{'for'$this->id;
  91.  
  92.             $this->tag->{'class''filled-in btn-tswitch';
  93.  
  94.             $wrapper new TElement('div');
  95.             $wrapper->{'style''display:inline-flex;align-items:center;';
  96.             $wrapper->add($this->tag);
  97.             $wrapper->add($obj);
  98.             $wrapper->show();
  99.         }
  100.         else
  101.         {
  102.             // shows the tag
  103.             $this->tag->show();
  104.         }
  105.  
  106.     }
  107. }