Changeset View
Changeset View
Standalone View
Standalone View
src/applications/typeahead/view/PhabricatorTypeaheadTokenView.php
<?php | <?php | ||||
final class PhabricatorTypeaheadTokenView | final class PhabricatorTypeaheadTokenView | ||||
extends AphrontTagView { | extends AphrontTagView { | ||||
const TYPE_OBJECT = 'object'; | |||||
const TYPE_DISABLED = 'disabled'; | |||||
const TYPE_FUNCTION = 'function'; | |||||
const TYPE_INVALID = 'invalid'; | |||||
private $key; | private $key; | ||||
private $icon; | private $icon; | ||||
private $inputName; | private $inputName; | ||||
private $value; | private $value; | ||||
private $tokenType = self::TYPE_OBJECT; | |||||
const KEY_INVALID = '<invalid>'; | |||||
public static function newFromTypeaheadResult( | public static function newFromTypeaheadResult( | ||||
PhabricatorTypeaheadResult $result) { | PhabricatorTypeaheadResult $result) { | ||||
return id(new PhabricatorTypeaheadTokenView()) | return id(new PhabricatorTypeaheadTokenView()) | ||||
->setKey($result->getPHID()) | ->setKey($result->getPHID()) | ||||
->setIcon($result->getIcon()) | ->setIcon($result->getIcon()) | ||||
->setValue($result->getDisplayName()); | ->setValue($result->getDisplayName()) | ||||
->setTokenType($result->getTokenType()); | |||||
} | } | ||||
public static function newFromHandle( | public static function newFromHandle( | ||||
PhabricatorObjectHandle $handle) { | PhabricatorObjectHandle $handle) { | ||||
return id(new PhabricatorTypeaheadTokenView()) | $token = id(new PhabricatorTypeaheadTokenView()) | ||||
->setKey($handle->getPHID()) | ->setKey($handle->getPHID()) | ||||
->setValue($handle->getFullName()) | ->setValue($handle->getFullName()) | ||||
->setIcon($handle->getIcon()); | ->setIcon(rtrim($handle->getIcon().' '.$handle->getIconColor())); | ||||
if ($handle->isDisabled() || | |||||
$handle->getStatus() == PhabricatorObjectHandleStatus::STATUS_CLOSED) { | |||||
$token->setTokenType(self::TYPE_DISABLED); | |||||
} | |||||
return $token; | |||||
} | } | ||||
public function setKey($key) { | public function setKey($key) { | ||||
$this->key = $key; | $this->key = $key; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getKey() { | public function getKey() { | ||||
return $this->key; | return $this->key; | ||||
} | } | ||||
public function setTokenType($token_type) { | |||||
$this->tokenType = $token_type; | |||||
return $this; | |||||
} | |||||
public function getTokenType() { | |||||
return $this->tokenType; | |||||
} | |||||
public function setInputName($input_name) { | public function setInputName($input_name) { | ||||
$this->inputName = $input_name; | $this->inputName = $input_name; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getInputName() { | public function getInputName() { | ||||
return $this->inputName; | return $this->inputName; | ||||
} | } | ||||
Show All 16 Lines | public function getValue() { | ||||
return $this->value; | return $this->value; | ||||
} | } | ||||
protected function getTagName() { | protected function getTagName() { | ||||
return 'a'; | return 'a'; | ||||
} | } | ||||
protected function getTagAttributes() { | protected function getTagAttributes() { | ||||
$classes = array(); | |||||
$classes[] = 'jx-tokenizer-token'; | |||||
switch ($this->getTokenType()) { | |||||
case self::TYPE_FUNCTION: | |||||
$classes[] = 'jx-tokenizer-token-function'; | |||||
break; | |||||
case self::TYPE_INVALID: | |||||
$classes[] = 'jx-tokenizer-token-invalid'; | |||||
break; | |||||
case self::TYPE_DISABLED: | |||||
$classes[] = 'jx-tokenizer-token-disabled'; | |||||
break; | |||||
case self::TYPE_OBJECT: | |||||
default: | |||||
break; | |||||
} | |||||
return array( | return array( | ||||
'class' => 'jx-tokenizer-token', | 'class' => $classes, | ||||
); | ); | ||||
} | } | ||||
protected function getTagContent() { | protected function getTagContent() { | ||||
$input_name = $this->getInputName(); | $input_name = $this->getInputName(); | ||||
if ($input_name) { | if ($input_name) { | ||||
$input_name .= '[]'; | $input_name .= '[]'; | ||||
} | } | ||||
Show All 29 Lines |