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

Documentation is available at TPassword.php

  1. <?php
  2. namespace Adianti\Widget\Form;
  3.  
  4. use Adianti\Widget\Form\AdiantiWidgetInterface;
  5. use Adianti\Core\AdiantiCoreTranslator;
  6. use Adianti\Widget\Base\TElement;
  7. use Adianti\Widget\Base\TScript;
  8. use Adianti\Widget\Form\TField;
  9. use Adianti\Widget\Form\TForm;
  10. use Adianti\Widget\Util\TImage;
  11. use Adianti\Control\TAction;
  12.  
  13. use Exception;
  14.  
  15. /**
  16.  * Password Widget
  17.  *
  18.  * @version    7.4
  19.  * @package    widget
  20.  * @subpackage form
  21.  * @author     Pablo Dall'Oglio
  22.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  23.  * @license    http://www.adianti.com.br/framework-license
  24.  */
  25. class TPassword extends TField implements AdiantiWidgetInterface
  26. {
  27.     private $exitAction;
  28.     private $exitFunction;
  29.     protected $formName;
  30.     protected $innerIcon;
  31.     protected $id;
  32.     private $toggleVisibility;
  33.  
  34.     /**
  35.      * Class Constructor
  36.      * @param $name Name of the widget
  37.      */
  38.     public function __construct($name)
  39.     {
  40.         parent::__construct($name);
  41.         $this->id = 'tpassword_'.mt_rand(10000000001999999999);
  42.         $this->toggleVisibility TRUE;
  43.     }
  44.     
  45.     public function enableToggleVisibility($toggleVisibility TRUE)
  46.     {
  47.         $this->toggleVisibility $toggleVisibility;
  48.     }
  49.  
  50.     /**
  51.      * Define the action to be executed when the user leaves the form field
  52.      * @param $action TAction object
  53.      */
  54.     function setExitAction(TAction $action)
  55.     {
  56.         if ($action->isStatic())
  57.         {
  58.             $this->exitAction $action;
  59.         }
  60.         else
  61.         {
  62.             $string_action $action->toString();
  63.             throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2'$string_action__METHOD__));
  64.         }
  65.     }
  66.     
  67.     /**
  68.      * Define max length
  69.      * @param  $length Max length
  70.      */
  71.     public function setMaxLength($length)
  72.     {
  73.         if ($length 0)
  74.         {
  75.             $this->tag->{'maxlength'$length;
  76.         }
  77.     }
  78.     
  79.     /**
  80.      * Define the Inner icon
  81.      */
  82.     public function setInnerIcon(TImage $image$side 'right')
  83.     {
  84.         $this->innerIcon $image;
  85.         $this->innerIcon->{'class'.= ' input-inner-icon ' $side;
  86.         
  87.         if ($side == 'left')
  88.         {
  89.             $this->setProperty('style'"padding-left:23px"false)//aggregate style info
  90.         }
  91.     }
  92.     
  93.     /**
  94.      * Define the javascript function to be executed when the user leaves the form field
  95.      * @param $function Javascript function
  96.      */
  97.     public function setExitFunction($function)
  98.     {
  99.         $this->exitFunction $function;
  100.     }
  101.     
  102.     /**
  103.      * Show the widget at the screen
  104.      */
  105.     public function show()
  106.     {
  107.         // define the tag properties
  108.         $this->tag-> name  =  $this->name;   // tag name
  109.         $this->tag-> value =  $this->value;  // tag value
  110.         $this->tag-> type  =  'password';    // input type
  111.         
  112.         if (!empty($this->size))
  113.         {
  114.             if (strstr((string) $this->size'%'!== FALSE)
  115.             {
  116.                 $this->setProperty('style'"width:{$this->size};"FALSE)//aggregate style info
  117.             }
  118.             else
  119.             {
  120.                 $this->setProperty('style'"width:{$this->size}px;"FALSE)//aggregate style info
  121.             }
  122.         }
  123.         
  124.         // verify if the field is not editable
  125.         if (parent::getEditable())
  126.         {
  127.             if (isset($this->exitAction))
  128.             {
  129.                 if (!TForm::getFormByName($this->formNameinstanceof TForm)
  130.                 {
  131.                     throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3'__CLASS__$this->name'TForm::setFields()') );
  132.                 }
  133.                 
  134.                 $string_action $this->exitAction->serialize(FALSE);
  135.                 $this->setProperty('onBlur'"__adianti_post_lookup('{$this->formName}', '{$string_action}', this, 'callback')");
  136.             }
  137.             
  138.             if (isset($this->exitFunction))
  139.             {
  140.                 $this->setProperty('onBlur'$this->exitFunctionFALSE );
  141.             }
  142.         }
  143.         else
  144.         {
  145.             // make the field read-only
  146.             $this->tag-> readonly "1";
  147.             $this->tag->{'class'.= ' tfield_disabled'// CSS
  148.             $this->tag->{'tabindex''-1';
  149.         }
  150.         
  151.         if (!empty($this->innerIcon))
  152.         {
  153.             $icon_wrapper new TElement('div');
  154.             $icon_wrapper->add($this->tag);
  155.             $icon_wrapper->add($this->innerIcon);
  156.             $icon_wrapper->show();
  157.         }
  158.         else
  159.         {
  160.             if ($this->toggleVisibility)
  161.             {
  162.                 $div    new TElement('div');
  163.                 $button new TElement('button');
  164.                 $icon   new TElement('i');
  165.     
  166.                 $div->{'id'$this->id;
  167.                 $div->{'style'$this->getProperty('style');
  168.     
  169.                 $icon->{'class''fa fa-eye-slash';
  170.                 $div->{'class''tpassword';
  171.     
  172.                 $button->{'type''button';
  173.     
  174.                 $button->add($icon);
  175.                 $div->add($this->tag);
  176.                 $div->add($button);
  177.     
  178.                 $div->show();
  179.     
  180.                 TScript::create("tpassword_start('{$this->id}');");
  181.             }
  182.             else
  183.             {
  184.                 // shows the tag
  185.                 $this->tag->show();
  186.             }
  187.         }
  188.     }
  189. }