HosipLan

Untitled

Aug 3rd, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. namespace Matosoft\Utils\Forms;
  5.  
  6. use Nette\Application\Responses\TextResponse;
  7. use Nette\Application\UI\ISignalReceiver;
  8. use Nette\Application\UI\Presenter;
  9. use Nette\Forms\Controls\TextArea;
  10. use Nette\Forms\Form;
  11.  
  12.  
  13.  
  14. class TexylaInput extends TextArea implements ISignalReceiver
  15. {
  16.  
  17.     /**
  18.      * @var \Texy
  19.      */
  20.     private $texy;
  21.  
  22.     /**
  23.      * @var Presenter
  24.      */
  25.     private $presenter;
  26.  
  27.  
  28.  
  29.     public function __construct($label = NULL, $cols = NULL, $rows = NULL)
  30.     {
  31.         parent::__construct($label, $cols, $rows);
  32.         $this->monitor('Nette\Application\UI\Presenter');
  33.     }
  34.  
  35.  
  36.     protected function getPresenter()
  37.     {
  38.         return $this->lookup('Nette\Application\UI\Presenter');
  39.     }
  40.  
  41.  
  42.     protected function getUniqueId()
  43.     {
  44.         return $this->lookupPath('Nette\Application\UI\Presenter');
  45.     }
  46.  
  47.  
  48.  
  49.     protected function attached($parent)
  50.     {
  51.         if ($parent instanceof Presenter) {
  52.             $name = $this->getUniqueId();
  53.             $this->setAttribute('data-previewLink', $parent->link('this', array('do' => $name . '-preview')));
  54.         }
  55.  
  56.         parent::attached($object);
  57.     }
  58.  
  59.  
  60.  
  61.     /**
  62.      * @param  string
  63.      * @return void
  64.      */
  65.     public function signalReceived($signal)
  66.     {
  67.         if ($signal === 'preview') {
  68.             $this->getPresenter()->sendResponse(new TextResponse($this->getTexy()->process($this->value)));
  69.         }
  70.  
  71.         throw new \Nette\Application\UI\BadSignalException;
  72.     }
  73.  
  74.  
  75.  
  76.     /**
  77.      * @return \Texy
  78.      */
  79.     private function getTexy()
  80.     {
  81.         if ($this->texy === NULL) {
  82.             $this->texy = new \Texy();
  83.         }
  84.  
  85.         return $this->texy;
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment