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

Documentation is available at TMultiEntry.php

  1. <?php
  2. namespace Adianti\Widget\Form;
  3.  
  4. use Adianti\Widget\Form\AdiantiWidgetInterface;
  5. use Adianti\Control\TPage;
  6. use Adianti\Control\TAction;
  7. use Adianti\Core\AdiantiCoreTranslator;
  8. use Adianti\Widget\Base\TElement;
  9. use Adianti\Widget\Base\TScript;
  10. use Adianti\Widget\Form\TField;
  11. use Exception;
  12.  
  13. /**
  14.  * Multi Entry Widget
  15.  *
  16.  * @version    7.4
  17.  * @package    widget
  18.  * @subpackage form
  19.  * @author     Matheus Agnes Dias
  20.  * @author     Pablo Dall'Oglio
  21.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  22.  * @license    http://www.adianti.com.br/framework-license
  23.  */
  24. class TMultiEntry extends TSelect implements AdiantiWidgetInterface
  25. {
  26.     protected $id;
  27.     protected $items;
  28.     protected $size;
  29.     protected $height;
  30.     protected $maxSize;
  31.     protected $editable;
  32.     protected $changeAction;
  33.     protected $changeFunction;
  34.     
  35.     /**
  36.      * Class Constructor
  37.      * @param  $name Widget's name
  38.      */
  39.     public function __construct($name)
  40.     {
  41.         // executes the parent class constructor
  42.         parent::__construct($name);
  43.         $this->id   = 'tmultientry_'.mt_rand(10000000001999999999);
  44.  
  45.         $this->height = 34;
  46.         $this->maxSize = 0;
  47.         
  48.         $this->tag->{'component''multientry';
  49.         $this->tag->{'widget''tmultientry';
  50.     }
  51.     
  52.     /**
  53.      * Define the widget's size
  54.      * @param  $width   Widget's width
  55.      * @param  $height  Widget's height
  56.      */
  57.     public function setSize($width$height NULL)
  58.     {
  59.         $this->size   $width;
  60.         if ($height)
  61.         {
  62.             $this->height $height;
  63.         }
  64.     }
  65.  
  66.     /**
  67.      * Define the maximum number of items that can be selected
  68.      */
  69.     public function setMaxSize($maxsize)
  70.     {
  71.         $this->maxSize $maxsize;
  72.     }
  73.     
  74.     /**
  75.      * Enable the field
  76.      * @param $form_name Form name
  77.      * @param $field Field name
  78.      */
  79.     public static function enableField($form_name$field)
  80.     {
  81.         TScript::create" tmultisearch_enable_field('{$form_name}', '{$field}'); );
  82.     }
  83.     
  84.     /**
  85.      * Disable the field
  86.      * @param $form_name Form name
  87.      * @param $field Field name
  88.      */
  89.     public static function disableField($form_name$field)
  90.     {
  91.         TScript::create" tmultisearch_disable_field('{$form_name}', '{$field}'); );
  92.     }
  93.  
  94.     /**
  95.      * Clear the field
  96.      * @param $form_name Form name
  97.      * @param $field Field name
  98.      */
  99.     public static function clearField($form_name$field)
  100.     {
  101.         TScript::create" tmultisearch_clear_field('{$form_name}', '{$field}'); );
  102.     }
  103.     
  104.     /**
  105.      * Render items
  106.      */
  107.     protected function renderItems$with_titles true)
  108.     {
  109.         if (parent::getValue())
  110.         {
  111.             // iterate the combobox items
  112.             foreach (parent::getValue(as $item)
  113.             {
  114.                 // creates an <option> tag
  115.                 $option new TElement('option');
  116.                 $option->{'value'$item;  // define the index
  117.                 $option->add($item);      // add the item label
  118.                 
  119.                 if ($with_titles)
  120.                 {
  121.                     $option->{'title'$item;  // define the title
  122.                 }
  123.                 
  124.                 // mark as selected
  125.                 $option->{'selected'1;
  126.                 
  127.                 $this->tag->add($option);
  128.             }
  129.         }
  130.     }
  131.     
  132.     /**
  133.      * Shows the widget
  134.      */
  135.     public function show()
  136.     {
  137.         // define the tag properties
  138.         $this->tag->{'name'}  $this->name.'[]';    // tag name
  139.         $this->tag->{'id'}  $this->id;    // tag name
  140.         
  141.         if (strstr((string) $this->size'%'!== FALSE)
  142.         {
  143.             $this->setProperty('style'"width:{$this->size};"false)//aggregate style info
  144.             $size  "{$this->size}";
  145.         }
  146.         else
  147.         {
  148.             $this->setProperty('style'"width:{$this->size}px;"false)//aggregate style info
  149.             $size  "{$this->size}px";
  150.         }
  151.         
  152.         $change_action 'function() {}';
  153.         
  154.         $this->renderItemsfalse );
  155.         
  156.         if ($this->editable)
  157.         {
  158.             if (isset($this->changeAction))
  159.             {
  160.                 if (!TForm::getFormByName($this->formNameinstanceof TForm)
  161.                 {
  162.                     throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3'__CLASS__$this->name'TForm::setFields()') );
  163.                 }
  164.                 
  165.                 $string_action $this->changeAction->serialize(FALSE);
  166.                 $change_action "function() { __adianti_post_lookup('{$this->formName}', '{$string_action}', '{$this->id}', 'callback'); }";
  167.             }
  168.             else if (isset($this->changeFunction))
  169.             {
  170.                 $change_action "function() { $this->changeFunction }";
  171.             }
  172.             $this->tag->show();
  173.             TScript::create(" tmultientry_start( '{$this->id}', '{$this->maxSize}', '{$size}', '{$this->height}px', $change_action ); ");
  174.         }
  175.         else
  176.         {
  177.             $this->tag->show();
  178.             TScript::create(" tmultientry_start( '{$this->id}', '{$this->maxSize}', '{$size}', '{$this->height}px', $change_action ); ");
  179.             TScript::create(" tmultientry_disable_field( '{$this->formName}', '{$this->name}'); ");
  180.         }
  181.     }
  182. }