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

Documentation is available at TSpinner.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.  
  11. use Adianti\Core\AdiantiCoreTranslator;
  12. use Exception;
  13.  
  14. /**
  15.  * Spinner Widget (also known as spin button)
  16.  *
  17.  * @version    7.4
  18.  * @package    widget
  19.  * @subpackage form
  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 TSpinner extends TField implements AdiantiWidgetInterface
  25. {
  26.     private $min;
  27.     private $max;
  28.     private $step;
  29.     private $exitAction;
  30.     private $exitFunction;
  31.     protected $id;
  32.     protected $formName;
  33.     protected $value;
  34.     
  35.     /**
  36.      * Class Constructor
  37.      * @param $name Name of the widget
  38.      */
  39.     public function __construct($name)
  40.     {
  41.         parent::__construct($name);
  42.         $this->id = 'tspinner_'.mt_rand(10000000001999999999);
  43.         $this->tag->{'widget''tspinner';
  44.     }
  45.     
  46.     /**
  47.      * Define the field's range
  48.      * @param $min Minimal value
  49.      * @param $max Maximal value
  50.      * @param $step Step value
  51.      */
  52.     public function setRange($min$max$step)
  53.     {
  54.         $this->min = $min;
  55.         $this->max = $max;
  56.         $this->step $step;
  57.         
  58.         if ($step == 0)
  59.         {
  60.             throw new Exception(AdiantiCoreTranslator::translate('Invalid parameter (^1) in ^2'$step'setRange'));
  61.         }
  62.         
  63.         if (is_int($stepAND $this->getValue($step !== 0)
  64.         {
  65.             parent::setValue($min);
  66.         }
  67.     }
  68.     
  69.     /**
  70.      * Define the action to be executed when the user leaves the form field
  71.      * @param $action TAction object
  72.      */
  73.     function setExitAction(TAction $action)
  74.     {
  75.         if ($action->isStatic())
  76.         {
  77.             $this->exitAction $action;
  78.         }
  79.         else
  80.         {
  81.             $string_action $action->toString();
  82.             throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2'$string_action__METHOD__));
  83.         }
  84.     }
  85.     
  86.     /**
  87.      * Enable the field
  88.      * @param $form_name Form name
  89.      * @param $field Field name
  90.      */
  91.     public static function enableField($form_name$field)
  92.     {
  93.         TScript::create" tspinner_enable_field('{$form_name}', '{$field}'); );
  94.     }
  95.     
  96.     /**
  97.      * Disable the field
  98.      * @param $form_name Form name
  99.      * @param $field Field name
  100.      */
  101.     public static function disableField($form_name$field)
  102.     {
  103.         TScript::create" tspinner_disable_field('{$form_name}', '{$field}'); );
  104.     }
  105.     
  106.     /**
  107.      * Set exit function
  108.      */
  109.     public function setExitFunction($function)
  110.     {
  111.         $this->exitFunction $function;
  112.     }
  113.     
  114.     /**
  115.      * Shows the widget at the screen
  116.      */
  117.     public function show()
  118.     {
  119.         // define the tag properties
  120.         $this->tag->{'name'}  $this->name;    // TAG name
  121.         $this->tag->{'value'$this->value;   // TAG value
  122.         $this->tag->{'type'}  'text';         // input type
  123.         $this->tag->{'data-min'$this->min;
  124.         $this->tag->{'data-max'$this->max;
  125.         $this->tag->{'data-step'$this->step;
  126.         
  127.         if ($this->step and $this->step 1)
  128.         {
  129.             $this->tag->{'data-rule''currency';
  130.         }
  131.         
  132.         $this->setProperty('style'"text-align:right"false)//aggregate style info
  133.         
  134.         if (strstr((string) $this->size'%'!== FALSE)
  135.         {
  136.             $this->setProperty('style'"width:{$this->size};"false)//aggregate style info
  137.             $this->setProperty('relwidth'"{$this->size}"false)//aggregate style info
  138.         }
  139.         else
  140.         {
  141.             $this->setProperty('style'"width:{$this->size}px;"false)//aggregate style info
  142.         }
  143.         
  144.         if ($this->id)
  145.         {
  146.             $this->tag->{'id'}  $this->id;
  147.         }
  148.         
  149.         if (isset($this->exitAction))
  150.         {
  151.             if (!TForm::getFormByName($this->formNameinstanceof TForm)
  152.             {
  153.                 throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3'__CLASS__$this->name'TForm::setFields()') );
  154.             }
  155.             $string_action $this->exitAction->serialize(FALSE);
  156.             $this->setProperty('exitaction'"__adianti_post_lookup('{$this->formName}', '{$string_action}', '{$this->id}', 'callback')");
  157.         }
  158.         
  159.         $exit_action "function() {}";
  160.         if (isset($this->exitFunction))
  161.         {
  162.             $exit_action "function() { {$this->exitFunction} }";
  163.         }
  164.         
  165.         if (!parent::getEditable())
  166.         {
  167.             $this->tag->{'tabindex''-1';
  168.         }
  169.         $this->tag->show();
  170.         TScript::create(" tspinner_start( '#{$this->id}', $exit_action); ");
  171.         
  172.         // verify if the widget is non-editable
  173.         if (!parent::getEditable())
  174.         {
  175.             self::disableField($this->formName$this->name);
  176.         }
  177.     }
  178.     
  179.     /**
  180.      * Set the value
  181.      */
  182.     public function setValue($value)
  183.     {
  184.         parent::setValue(float) $value);
  185.     }
  186. }