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

Documentation is available at TText.php

  1. <?php
  2. namespace Adianti\Widget\Form;
  3.  
  4. use Adianti\Widget\Form\AdiantiWidgetInterface;
  5. use Adianti\Control\TAction;
  6. use Adianti\Widget\Base\TElement;
  7. use Adianti\Widget\Form\TForm;
  8. use Adianti\Widget\Form\TField;
  9.  
  10. use Adianti\Core\AdiantiCoreTranslator;
  11. use Exception;
  12.  
  13. /**
  14.  * Text Widget (also known as Memo)
  15.  *
  16.  * @version    7.4
  17.  * @package    widget
  18.  * @subpackage form
  19.  * @author     Pablo Dall'Oglio
  20.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  21.  * @license    http://www.adianti.com.br/framework-license
  22.  */
  23. class TText extends TField implements AdiantiWidgetInterface
  24. {
  25.     private   $exitAction;
  26.     private   $exitFunction;
  27.     protected $id;
  28.     protected $formName;
  29.     protected $size;
  30.     protected $height;
  31.     
  32.     /**
  33.      * Class Constructor
  34.      * @param $name Widet's name
  35.      */
  36.     public function __construct($name)
  37.     {
  38.         parent::__construct($name);
  39.         $this->id   = 'ttext_' mt_rand(10000000001999999999);
  40.         
  41.         // creates a <textarea> tag
  42.         $this->tag = new TElement('textarea');
  43.         $this->tag->{'class''tfield';       // CSS
  44.         $this->tag->{'widget''ttext';
  45.         // defines the text default height
  46.         $this->height100;
  47.     }
  48.     
  49.     /**
  50.      * Define the widget's size
  51.      * @param  $width   Widget's width
  52.      * @param  $height  Widget's height
  53.      */
  54.     public function setSize($width$height NULL)
  55.     {
  56.         $this->size   $width;
  57.         if ($height)
  58.         {
  59.             $this->height $height;
  60.         }
  61.     }
  62.     
  63.     /**
  64.      * Returns the size
  65.      * @return array(width, height)
  66.      */
  67.     public function getSize()
  68.     {
  69.         return array$this->size$this->height );
  70.     }
  71.     
  72.     /**
  73.      * Define max length
  74.      * @param  $length Max length
  75.      */
  76.     public function setMaxLength($length)
  77.     {
  78.         if ($length 0)
  79.         {
  80.             $this->tag->{'maxlength'$length;
  81.         }
  82.     }
  83.     
  84.     /**
  85.      * Define the action to be executed when the user leaves the form field
  86.      * @param $action TAction object
  87.      */
  88.     function setExitAction(TAction $action)
  89.     {
  90.         if ($action->isStatic())
  91.         {
  92.             $this->exitAction $action;
  93.         }
  94.         else
  95.         {
  96.             $string_action $action->toString();
  97.             throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2'$string_action__METHOD__));
  98.         }
  99.     }
  100.     
  101.     /**
  102.      * Set exit function
  103.      */
  104.     public function setExitFunction($function)
  105.     {
  106.         $this->exitFunction $function;
  107.     }
  108.     
  109.     /**
  110.      * Force lower case
  111.      */
  112.     public function forceLowerCase()
  113.     {
  114.         $this->tag->{'onKeyPress'"return tentry_lower(this)";
  115.         $this->tag->{'onBlur'"return tentry_lower(this)";
  116.         $this->tag->{'forcelower'"1";
  117.         $this->setProperty('style''text-transform: lowercase');
  118.         
  119.     }
  120.     
  121.     /**
  122.      * Force upper case
  123.      */
  124.     public function forceUpperCase()
  125.     {
  126.         $this->tag->{'onKeyPress'"return tentry_upper(this)";
  127.         $this->tag->{'onBlur'"return tentry_upper(this)";
  128.         $this->tag->{'forceupper'"1";
  129.         $this->setProperty('style''text-transform: uppercase');
  130.     }
  131.     
  132.     /**
  133.      * Return the post data
  134.      */
  135.     public function getPostData()
  136.     {
  137.         $name str_replace(['[',']']['','']$this->name);
  138.         
  139.         if (isset($_POST[$name]))
  140.         {
  141.             return $_POST[$name];
  142.         }
  143.         else
  144.         {
  145.             return '';
  146.         }
  147.     }
  148.     
  149.     /**
  150.      * Show the widget
  151.      */
  152.     public function show()
  153.     {
  154.         $this->tag->{'name'}  $this->name;   // tag name
  155.         
  156.         if ($this->size)
  157.         {
  158.             $size (strstr((string) $this->size'%'!== FALSE$this->size "{$this->size}px";
  159.             $this->setProperty('style'"width:{$size};"FALSE)//aggregate style info
  160.         }
  161.         
  162.         if ($this->height)
  163.         {
  164.             $height (strstr($this->height'%'!== FALSE$this->height "{$this->height}px";
  165.             $this->setProperty('style'"height:{$height}"FALSE)//aggregate style info
  166.         }
  167.         
  168.         if ($this->id and empty($this->tag->{'id'}))
  169.         {
  170.             $this->tag->{'id'$this->id;
  171.         }
  172.         
  173.         // check if the field is not editable
  174.         if (!parent::getEditable())
  175.         {
  176.             // make the widget read-only
  177.             $this->tag->{'readonly'"1";
  178.             $this->tag->{'class'$this->tag->{'class'== 'tfield' 'tfield_disabled' $this->tag->{'class'' tfield_disabled'// CSS
  179.             $this->tag->{'tabindex''-1';
  180.         }
  181.         
  182.         if (isset($this->exitAction))
  183.         {
  184.             if (!TForm::getFormByName($this->formNameinstanceof TForm)
  185.             {
  186.                 throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3'__CLASS__$this->name'TForm::setFields()') );
  187.             }
  188.             $string_action $this->exitAction->serialize(FALSE);
  189.             $this->setProperty('exitaction'"__adianti_post_lookup('{$this->formName}', '{$string_action}', '{$this->id}', 'callback')");
  190.             $this->setProperty('onBlur'$this->getProperty('exitaction')FALSE);
  191.         }
  192.         
  193.         if (isset($this->exitFunction))
  194.         {
  195.             $this->setProperty('onBlur'$this->exitFunctionFALSE );
  196.         }
  197.         
  198.         // add the content to the textarea
  199.         $this->tag->add(htmlspecialchars(string) $this->value));
  200.         // show the tag
  201.         $this->tag->show();
  202.     }
  203. }