Files
phabricator/src/view/form/control/AphrontFormTokenizerControl.php

86 lines
2.0 KiB
PHP
Raw Normal View History

2011-01-25 13:48:05 -08:00
<?php
final class AphrontFormTokenizerControl extends AphrontFormControl {
2011-01-25 13:48:05 -08:00
private $datasource;
private $disableBehavior;
private $limit;
private $placeholder;
2011-01-25 13:48:05 -08:00
public function setDatasource(PhabricatorTypeaheadDatasource $datasource) {
2011-01-25 13:48:05 -08:00
$this->datasource = $datasource;
return $this;
}
2011-02-04 22:45:42 -08:00
public function setDisableBehavior($disable) {
$this->disableBehavior = $disable;
return $this;
}
2011-01-25 13:48:05 -08:00
protected function getCustomControlClass() {
return 'aphront-form-control-tokenizer';
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function setPlaceholder($placeholder) {
$this->placeholder = $placeholder;
return $this;
}
2011-01-25 13:48:05 -08:00
protected function renderInput() {
$name = $this->getName();
2011-03-22 20:41:02 -07:00
$values = nonempty($this->getValue(), array());
2011-01-25 13:48:05 -08:00
assert_instances_of($values, 'PhabricatorObjectHandle');
2011-02-04 22:45:42 -08:00
if ($this->getID()) {
$id = $this->getID();
} else {
$id = celerity_generate_unique_node_id();
}
2011-01-25 13:48:05 -08:00
$placeholder = null;
if (!strlen($this->placeholder)) {
if ($this->datasource) {
$placeholder = $this->datasource->getPlaceholderText();
}
} else {
$placeholder = $this->placeholder;
}
2011-03-22 20:41:02 -07:00
$template = new AphrontTokenizerTemplateView();
$template->setName($name);
$template->setID($id);
$template->setValue($values);
$username = null;
if ($this->user) {
$username = $this->user->getUsername();
}
$datasource_uri = null;
if ($this->datasource) {
$datasource_uri = $this->datasource->getDatasourceURI();
}
2011-02-04 22:45:42 -08:00
if (!$this->disableBehavior) {
Javelin::initBehavior('aphront-basic-tokenizer', array(
'id' => $id,
'src' => $datasource_uri,
'value' => mpull($values, 'getFullName', 'getPHID'),
'icons' => mpull($values, 'getIcon', 'getPHID'),
'limit' => $this->limit,
'username' => $username,
'placeholder' => $placeholder,
2011-02-04 22:45:42 -08:00
));
}
2011-01-25 13:48:05 -08:00
2011-03-22 20:41:02 -07:00
return $template->render();
2011-01-25 13:48:05 -08:00
}
}