[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/control/ -> AphrontTokenizerTemplateView.php (source)

   1  <?php
   2  
   3  final class AphrontTokenizerTemplateView extends AphrontView {
   4  
   5    private $value;
   6    private $name;
   7    private $id;
   8  
   9    public function setID($id) {
  10      $this->id = $id;
  11      return $this;
  12    }
  13  
  14    public function setValue(array $value) {
  15      assert_instances_of($value, 'PhabricatorObjectHandle');
  16      $this->value = $value;
  17      return $this;
  18    }
  19  
  20    public function getValue() {
  21      return $this->value;
  22    }
  23  
  24    public function setName($name) {
  25      $this->name = $name;
  26      return $this;
  27    }
  28  
  29    public function getName() {
  30      return $this->name;
  31    }
  32  
  33    public function render() {
  34      require_celerity_resource('aphront-tokenizer-control-css');
  35  
  36      $id = $this->id;
  37      $name = $this->getName();
  38      $values = nonempty($this->getValue(), array());
  39  
  40      $tokens = array();
  41      foreach ($values as $key => $value) {
  42        $tokens[] = $this->renderToken(
  43          $value->getPHID(),
  44          $value->getFullName(),
  45          $value->getType());
  46      }
  47  
  48      $input = javelin_tag(
  49        'input',
  50        array(
  51          'mustcapture' => true,
  52          'name'        => $name,
  53          'class'       => 'jx-tokenizer-input',
  54          'sigil'       => 'tokenizer-input',
  55          'style'       => 'width: 0px;',
  56          'disabled'    => 'disabled',
  57          'type'        => 'text',
  58        ));
  59  
  60      $content = $tokens;
  61      $content[] = $input;
  62      $content[] = phutil_tag('div', array('style' => 'clear: both;'), '');
  63  
  64      return phutil_tag(
  65        'div',
  66        array(
  67          'id' => $id,
  68          'class' => 'jx-tokenizer-container',
  69        ),
  70        $content);
  71    }
  72  
  73    private function renderToken($key, $value, $icon) {
  74      $input_name = $this->getName();
  75      if ($input_name) {
  76        $input_name .= '[]';
  77      }
  78  
  79      if ($icon) {
  80        $value = array(
  81          phutil_tag(
  82            'span',
  83            array(
  84              'class' => 'phui-icon-view phui-font-fa bluetext '.$icon,
  85            )),
  86          $value,
  87        );
  88      }
  89  
  90      return phutil_tag(
  91        'a',
  92        array(
  93          'class' => 'jx-tokenizer-token',
  94        ),
  95        array(
  96          $value,
  97          phutil_tag(
  98            'input',
  99            array(
 100              'type'  => 'hidden',
 101              'name'  => $input_name,
 102              'value' => $key,
 103            )),
 104          phutil_tag('span', array('class' => 'jx-tokenizer-x-placeholder'), ''),
 105        ));
 106    }
 107  
 108  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1