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

Documentation is available at TSeekButton.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\Base\TScript;
  8. use Adianti\Widget\Form\TForm;
  9. use Adianti\Widget\Form\TField;
  10. use Adianti\Widget\Form\TEntry;
  11. use Adianti\Widget\Util\TImage;
  12.  
  13. use Adianti\Core\AdiantiCoreTranslator;
  14. use Exception;
  15. use ReflectionClass;
  16.  
  17. /**
  18.  * Record Lookup Widget: Creates a lookup field used to search values from associated entities
  19.  *
  20.  * @version    7.4
  21.  * @package    widget
  22.  * @subpackage form
  23.  * @author     Pablo Dall'Oglio
  24.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  25.  * @license    http://www.adianti.com.br/framework-license
  26.  */
  27. class TSeekButton extends TEntry implements AdiantiWidgetInterface
  28. {
  29.     private $action;
  30.     private $useOutEvent;
  31.     private $button;
  32.     private $extra_size;
  33.     private $input_size;
  34.     protected $size;
  35.     protected $auxiliar;
  36.     protected $id;
  37.     protected $formName;
  38.     protected $name;
  39.     
  40.     /**
  41.      * Class Constructor
  42.      * @param  $name name of the field
  43.      */
  44.     public function __construct($name$icon NULL)
  45.     {
  46.         parent::__construct($name);
  47.         $this->useOutEvent TRUE;
  48.         $this->setProperty('class''tfield tseekentry'TRUE);   // classe CSS
  49.         $this->extra_size 24;
  50.         $this->input_size '100%';
  51.         $this->size = "100%";
  52.         $this->button self::createButton($this->name$icon);
  53.     }
  54.     
  55.     /**
  56.      * Create seek button object
  57.      */
  58.     public static function createButton($name$icon)
  59.     {
  60.         $image new TImage$icon $icon 'fa:search');
  61.         $button new TElement('span');
  62.         $button->{'class''btn btn-default tseekbutton';
  63.         $button->{'type''button';
  64.         $button->{'onmouseover'"style.cursor = 'pointer'";
  65.         $button->{'name''_' $name '_seek';
  66.         $button->{'for'$name;
  67.         $button->{'onmouseout'}  "style.cursor = 'default'";
  68.         $button->add($image);
  69.         
  70.         return $button;
  71.     }
  72.     
  73.     /**
  74.      * Returns a property value
  75.      * @param $name     Property Name
  76.      */
  77.     public function __get($name)
  78.     {
  79.         if ($name == 'button')
  80.         {
  81.             return $this->button;
  82.         }
  83.         else
  84.         {
  85.             return parent::__get($name);
  86.         }
  87.     }
  88.     
  89.     /**
  90.      * Define the Field's width
  91.      * @param $width Field's width in pixels
  92.      */
  93.     public function setSize($width$height NULL)
  94.     {
  95.         if ($this->hasAuxiliar(&& empty($height)) // height is passed by BootstrapFormBuilder::wrapField() only
  96.         {
  97.             $this->input_size $width;
  98.         }
  99.         else
  100.         {
  101.             $this->size $width;
  102.         }
  103.     }
  104.     
  105.     /**
  106.      * Define it the out event will be fired
  107.      */
  108.     public function setUseOutEvent($bool)
  109.     {
  110.         $this->useOutEvent $bool;
  111.     }
  112.     
  113.     /**
  114.      * Define the action for the SeekButton
  115.      * @param $action Action taken when the user
  116.      *  clicks over the Seek Button (A TAction object)
  117.      */
  118.     public function setAction(TAction $action)
  119.     {
  120.         $this->action $action;
  121.     }
  122.     
  123.     /**
  124.      * Return the action
  125.      */
  126.     public function getAction()
  127.     {
  128.         return $this->action;
  129.     }
  130.     
  131.     /**
  132.      * Define an auxiliar field
  133.      * @param $object any TField object
  134.      */
  135.     public function setAuxiliar($object)
  136.     {
  137.         if (method_exists($object'show'))
  138.         {
  139.             $this->auxiliar $object;
  140.             $this->extra_size *= 2;
  141.             $this->input_size $this->size;
  142.             $this->size '100%';
  143.             
  144.             if ($object instanceof TField)
  145.             {
  146.                 $this->action->setParameter('receive_field'$object->getName());
  147.             }
  148.         }
  149.     }
  150.     
  151.     /**
  152.      * Returns if has auxiliar field
  153.      */
  154.     public function hasAuxiliar()
  155.     {
  156.         return !empty($this->auxiliar);
  157.     }
  158.     
  159.     /**
  160.      * Set extra size
  161.      */
  162.     public function setExtraSize($extra_size)
  163.     {
  164.         $this->extra_size $extra_size;
  165.     }
  166.     
  167.     /**
  168.      * Returns extra size
  169.      */
  170.     public function getExtraSize()
  171.     {
  172.         return $this->extra_size;
  173.     }
  174.     
  175.     /**
  176.      * Enable the field
  177.      * @param $form_name Form name
  178.      * @param $field Field name
  179.      */
  180.     public static function enableField($form_name$field)
  181.     {
  182.         TScript::create" tseekbutton_enable_field('{$form_name}', '{$field}'); );
  183.     }
  184.     
  185.     /**
  186.      * Disable the field
  187.      * @param $form_name Form name
  188.      * @param $field Field name
  189.      */
  190.     public static function disableField($form_name$field)
  191.     {
  192.         TScript::create" tseekbutton_disable_field('{$form_name}', '{$field}'); );
  193.     }
  194.     
  195.     /**
  196.      * Show the widget
  197.      */
  198.     public function show()
  199.     {
  200.         // check if it's not editable
  201.         if (parent::getEditable())
  202.         {
  203.             if (!TForm::getFormByName($this->formNameinstanceof TForm)
  204.             {
  205.                 throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3'__CLASS__$this->name'TForm::setFields()') );
  206.             }
  207.             
  208.             $serialized_action '';
  209.             if ($this->action)
  210.             {
  211.                 // get the action class name
  212.                 if (is_array($callback $this->action->getAction()))
  213.                 {
  214.                     if (is_object($callback[0]))
  215.                     {
  216.                         $rc new ReflectionClass($callback[0]);
  217.                         $class $rc->getName();
  218.                     }
  219.                     else
  220.                     {
  221.                         $class  $callback[0];
  222.                     }
  223.                     
  224.                     if ($this->useOutEvent)
  225.                     {
  226.                         $ajaxAction new TAction(array($class'onSelect'));
  227.                         if (in_array($class['TStandardSeek']))
  228.                         {
  229.                             $ajaxAction->setParameter('parent',  $this->action->getParameter('parent'));
  230.                             $ajaxAction->setParameter('database',$this->action->getParameter('database'));
  231.                             $ajaxAction->setParameter('model',   $this->action->getParameter('model'));
  232.                             $ajaxAction->setParameter('display_field'$this->action->getParameter('display_field'));
  233.                             $ajaxAction->setParameter('receive_key',   $this->action->getParameter('receive_key'));
  234.                             $ajaxAction->setParameter('receive_field'$this->action->getParameter('receive_field'));
  235.                             $ajaxAction->setParameter('criteria',      $this->action->getParameter('criteria'));
  236.                             $ajaxAction->setParameter('mask',          $this->action->getParameter('mask'));
  237.                             $ajaxAction->setParameter('operator',      $this->action->getParameter('operator'$this->action->getParameter('operator''like');
  238.                         }
  239.                         else
  240.                         {
  241.                             if ($actionParameters $this->action->getParameters())
  242.                             {
  243.                                 foreach ($actionParameters as $key => $value
  244.                                 {
  245.                                     $ajaxAction->setParameter($key$value);
  246.                                 }                            
  247.                             }                                            
  248.                         }
  249.                         $ajaxAction->setParameter('form_name',  $this->formName);
  250.                         
  251.                         $string_action $ajaxAction->serialize(FALSE);
  252.                         $this->setProperty('seekaction'"__adianti_post_lookup('{$this->formName}', '{$string_action}', '{$this->id}', 'callback')");
  253.                         $this->setProperty('onBlur'$this->getProperty('seekaction')FALSE);
  254.                     }
  255.                 }
  256.                 
  257.                 $this->action->setParameter('_field_id',   $this->id);
  258.                 $this->action->setParameter('_field_name'$this->name);
  259.                 $this->action->setParameter('_form_name',  $this->formName);
  260.                 
  261.                 $this->action->setParameter('field_name'$this->name);
  262.                 $this->action->setParameter('form_name',  $this->formName);
  263.                 
  264.                 $serialized_action $this->action->serialize(FALSE);
  265.             }
  266.             
  267.             $this->button->{'onclick'"__adianti_post_page_lookup('{$this->formName}', '{$serialized_action}', '{$this->id}', 'callback')";
  268.             
  269.             $wrapper new TElement('div');
  270.             $wrapper->{'class''tseek-group';
  271.             
  272.             if (strstr((string) $this->size'%'!== FALSE)
  273.             {
  274.                 $wrapper->{'style'.= ";width:{$this->size};";
  275.             }
  276.             else
  277.             {
  278.                 $wrapper->{'style'.= ";width:{$this->size}px;";
  279.             }
  280.             
  281.             $this->size ($this->hasAuxiliar($this->input_size "calc(100% - {$this->extra_size}px)");
  282.             
  283.             $wrapper->open();
  284.             parent::show();
  285.             $this->button->show();
  286.             
  287.             if ($this->auxiliar)
  288.             {
  289.                 $this->auxiliar->show();
  290.             }
  291.             $wrapper->close();
  292.         }
  293.         else
  294.         {
  295.             parent::show();
  296.         }
  297.     }
  298. }