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

Documentation is available at TQRCodeInputReader.php

  1. <?php
  2. namespace Adianti\Widget\Form;
  3.  
  4. use Adianti\Widget\Form\AdiantiWidgetInterface;
  5. use Adianti\Widget\Base\TElement;
  6. use Adianti\Widget\Base\TScript;
  7. use Adianti\Widget\Form\TEntry;
  8. use Adianti\Control\TAction;
  9.  
  10. /**
  11.  * QR Code Input Reader
  12.  *
  13.  * @version    7.4
  14.  * @package    widget
  15.  * @subpackage form
  16.  * @author     Lucas Tomasi
  17.  * @author     Pablo Dall'Oglio
  18.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  19.  * @license    http://www.adianti.com.br/framework-license
  20.  */
  21. class TQRCodeInputReader extends TEntry implements AdiantiWidgetInterface
  22. {
  23.     protected $formName;
  24.     protected $name;
  25.     protected $id;
  26.     protected $size;
  27.     protected $changeFunction;
  28.     protected $changeAction;
  29.  
  30.     /**
  31.      * Class Constructor
  32.      * @param $name Name of the widget
  33.      */
  34.     public function __construct($name)
  35.     {
  36.         parent::__construct($name);
  37.         $this->id = 'tqrcodeinputreader_'.mt_rand(10000000001999999999);
  38.         $this->tag->{'widget''tqrcodeinputreader';
  39.         $this->tag->{'autocomplete''off';
  40.     }
  41.  
  42.     /**
  43.      * Set change function
  44.      */
  45.     public function setChangeFunction($function)
  46.     {
  47.         $this->changeFunction $function;
  48.     }
  49.  
  50.     /**
  51.      * Define the action to be executed when the user changes the content
  52.      * @param $action TAction object
  53.      */
  54.     public function setChangeAction(TAction $action)
  55.     {
  56.         $this->changeAction $action;
  57.     }
  58.  
  59.     /**
  60.      * Shows the widget at the screen
  61.      */
  62.     public function show()
  63.     {
  64.         $wrapper new TElement('div');
  65.         $wrapper->{'class''input-group';
  66.         $wrapper->{'style''float:inherit;width: 100%';
  67.  
  68.         $span new TElement('span');
  69.         $span->{'class''input-group-addon tqrcodeinputreader';
  70.  
  71.         $outer_size 'undefined';
  72.         if (strstr((string) $this->size'%'!== FALSE)
  73.         {
  74.             $outer_size $this->size;
  75.             $this->size '100%';
  76.         }
  77.  
  78.         if ($this->changeAction)
  79.         {
  80.             if (!TForm::getFormByName($this->formNameinstanceof TForm)
  81.             {
  82.                 throw new Exception(AdiantiCoreTranslator::translate('You must pass the ^1 (^2) as a parameter to ^3'__CLASS__$this->name'TForm::setFields()') );
  83.             }
  84.  
  85.             $string_action $this->changeAction->serialize(FALSE);
  86.             $this->setProperty('changeaction'"__adianti_post_lookup('{$this->formName}', '{$string_action}', '{$this->id}', 'callback')");
  87.             $this->setProperty('onChange'$this->getProperty('changeaction')FALSE);
  88.         }
  89.         
  90.         if (isset($this->changeFunction))
  91.         {
  92.             $this->setProperty('changeaction'$this->changeFunctionFALSE);
  93.             $this->setProperty('onChange'$this->changeFunctionFALSE);
  94.         }
  95.         
  96.         $i new TElement('i');
  97.         $i->{'class''fa fa-qrcode';
  98.         $span->{'onclick'"tqrcodeinputreader_open_reader('{$this->id}');";
  99.         
  100.         $span->add($i);
  101.         ob_start();
  102.         parent::show();
  103.         $child ob_get_contents();
  104.         ob_end_clean();
  105.         
  106.         $wrapper->add($child);
  107.         $wrapper->add($span);
  108.         $wrapper->show();
  109.  
  110.         if (!parent::getEditable())
  111.         {
  112.             self::disableField($this->formName$this->name);
  113.         }
  114.     }
  115. }