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_OBJECT = 'object'; | ||||
const TYPE_DISABLED = 'disabled'; | const TYPE_DISABLED = 'disabled'; | ||||
const TYPE_FUNCTION = 'function'; | const TYPE_FUNCTION = 'function'; | ||||
const TYPE_INVALID = 'invalid'; | const TYPE_INVALID = 'invalid'; | ||||
private $key; | private $key; | ||||
private $icon; | private $icon; | ||||
private $color; | private $color; | ||||
private $inputName; | private $inputName; | ||||
private $value; | private $value; | ||||
private $tokenType = self::TYPE_OBJECT; | private $tokenType = self::TYPE_OBJECT; | ||||
private $availabilityColor; | |||||
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()) | ||||
->setColor($result->getColor()) | ->setColor($result->getColor()) | ||||
Show All 11 Lines | public static function newFromHandle( | ||||
if ($handle->isDisabled() || | if ($handle->isDisabled() || | ||||
$handle->getStatus() == PhabricatorObjectHandle::STATUS_CLOSED) { | $handle->getStatus() == PhabricatorObjectHandle::STATUS_CLOSED) { | ||||
$token->setTokenType(self::TYPE_DISABLED); | $token->setTokenType(self::TYPE_DISABLED); | ||||
} else { | } else { | ||||
$token->setColor($handle->getTagColor()); | $token->setColor($handle->getTagColor()); | ||||
} | } | ||||
$availability = $handle->getAvailability(); | |||||
$color = null; | |||||
switch ($availability) { | |||||
case PhabricatorObjectHandle::AVAILABILITY_PARTIAL: | |||||
$color = PHUITagView::COLOR_ORANGE; | |||||
break; | |||||
case PhabricatorObjectHandle::AVAILABILITY_NONE: | |||||
$color = PHUITagView::COLOR_RED; | |||||
break; | |||||
} | |||||
if ($color !== null) { | |||||
$token->setAvailabilityColor($color); | |||||
} | |||||
return $token; | return $token; | ||||
} | } | ||||
public function isInvalid() { | public function isInvalid() { | ||||
return ($this->getTokenType() == self::TYPE_INVALID); | return ($this->getTokenType() == self::TYPE_INVALID); | ||||
} | } | ||||
public function setKey($key) { | public function setKey($key) { | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | final class PhabricatorTypeaheadTokenView | ||||
public function getValue() { | public function getValue() { | ||||
return $this->value; | return $this->value; | ||||
} | } | ||||
protected function getTagName() { | protected function getTagName() { | ||||
return 'a'; | return 'a'; | ||||
} | } | ||||
public function setAvailabilityColor($availability_color) { | |||||
$this->availabilityColor = $availability_color; | |||||
return $this; | |||||
} | |||||
public function getAvailabilityColor() { | |||||
return $this->availabilityColor; | |||||
} | |||||
protected function getTagAttributes() { | protected function getTagAttributes() { | ||||
$classes = array(); | $classes = array(); | ||||
$classes[] = 'jx-tokenizer-token'; | $classes[] = 'jx-tokenizer-token'; | ||||
switch ($this->getTokenType()) { | switch ($this->getTokenType()) { | ||||
case self::TYPE_FUNCTION: | case self::TYPE_FUNCTION: | ||||
$classes[] = 'jx-tokenizer-token-function'; | $classes[] = 'jx-tokenizer-token-function'; | ||||
break; | break; | ||||
case self::TYPE_INVALID: | case self::TYPE_INVALID: | ||||
Show All 17 Lines | final class PhabricatorTypeaheadTokenView | ||||
protected function getTagContent() { | protected function getTagContent() { | ||||
$input_name = $this->getInputName(); | $input_name = $this->getInputName(); | ||||
if ($input_name) { | if ($input_name) { | ||||
$input_name .= '[]'; | $input_name .= '[]'; | ||||
} | } | ||||
$value = $this->getValue(); | $value = $this->getValue(); | ||||
$availability = null; | |||||
$availability_color = $this->getAvailabilityColor(); | |||||
if ($availability_color) { | |||||
$availability = phutil_tag( | |||||
'span', | |||||
array( | |||||
'class' => 'phui-tag-dot phui-tag-color-'.$availability_color, | |||||
)); | |||||
} | |||||
$icon_view = null; | |||||
$icon = $this->getIcon(); | $icon = $this->getIcon(); | ||||
if ($icon) { | if ($icon) { | ||||
$value = array( | $icon_view = phutil_tag( | ||||
phutil_tag( | |||||
'span', | 'span', | ||||
array( | array( | ||||
'class' => 'phui-icon-view phui-font-fa '.$icon, | 'class' => 'phui-icon-view phui-font-fa '.$icon, | ||||
)), | )); | ||||
$value, | |||||
); | |||||
} | } | ||||
return array( | return array( | ||||
array( | |||||
$icon_view, | |||||
$availability, | |||||
$value, | $value, | ||||
), | |||||
phutil_tag( | phutil_tag( | ||||
'input', | 'input', | ||||
array( | array( | ||||
'type' => 'hidden', | 'type' => 'hidden', | ||||
'name' => $input_name, | 'name' => $input_name, | ||||
'value' => $this->getKey(), | 'value' => $this->getKey(), | ||||
)), | )), | ||||
phutil_tag('span', array('class' => 'jx-tokenizer-x-placeholder'), ''), | phutil_tag('span', array('class' => 'jx-tokenizer-x-placeholder'), ''), | ||||
); | ); | ||||
} | } | ||||
} | } |