4 * The default one-for-all hovercard. We may derive from this one to create
5 * more specialized ones.
7 final class PHUIHovercardView
extends AphrontTagView
{
10 * @var PhabricatorObjectHandle
15 private $title = array();
17 private $tags = array();
18 private $fields = array();
19 private $actions = array();
20 private $badges = array();
23 public function setObjectHandle(PhabricatorObjectHandle
$handle) {
24 $this->handle
= $handle;
28 public function setObject($object) {
29 $this->object = $object;
33 public function getObject() {
37 public function setTitle($title) {
38 $this->title
= $title;
42 public function setDetail($detail) {
43 $this->detail
= $detail;
47 public function setIsExiled($is_exiled) {
48 $this->isExiled
= $is_exiled;
52 public function getIsExiled() {
53 return $this->isExiled
;
56 public function addField($label, $value) {
57 $this->fields
[] = array(
64 public function addAction($label, $uri, $workflow = false) {
65 $this->actions
[] = array(
68 'workflow' => $workflow,
73 public function addTag(PHUITagView
$tag) {
78 public function addBadge(PHUIBadgeMiniView
$badge) {
79 $this->badges
[] = $badge;
83 protected function getTagAttributes() {
85 $classes[] = 'phui-hovercard-wrapper';
88 'class' => implode(' ', $classes),
92 protected function getTagContent() {
94 throw new PhutilInvalidStateException('setObjectHandle');
97 $viewer = $this->getUser();
98 $handle = $this->handle
;
100 require_celerity_resource('phui-hovercard-view-css');
102 // If we're a fully custom Hovercard, skip the common UI
103 $children = $this->renderChildren();
109 id(new PHUISpacesNamespaceContextView())
111 ->setObject($this->getObject()),
112 $this->title ?
$this->title
: $handle->getName(),
115 $header = new PHUIHeaderView();
116 $header->setHeader($title);
118 foreach ($this->tags
as $tag) {
119 $header->addActionItem($tag);
127 $body_title = $this->detail
;
128 } else if (!$this->fields
) {
129 // Fallback for object handles
130 $body_title = $handle->getFullName();
134 $body[] = phutil_tag_div('phui-hovercard-body-header', $body_title);
137 foreach ($this->fields
as $field) {
139 phutil_tag('strong', array(), $field['label']),
141 phutil_tag('span', array(), $field['value']),
143 $body[] = phutil_tag_div('phui-hovercard-body-item', $item);
147 $badges = id(new PHUIBadgeBoxView())
148 ->addItems($this->badges
)
149 ->setCollapsed(true);
150 $body[] = phutil_tag(
153 'class' => 'phui-hovercard-body-item hovercard-badges',
158 if ($handle->getImageURI()) {
159 // Probably a user, we don't need to assume something else
160 // "Prepend" the image by appending $body
164 'class' => 'phui-hovercard-body-image',
169 'class' => 'profile-header-picture-frame',
170 'style' => 'background-image: url('.$handle->getImageURI().');',
177 'class' => 'phui-hovercard-body-details',
184 foreach ($this->actions
as $action) {
186 'class' => 'button button-grey',
187 'href' => $action['uri'],
190 if ($action['workflow']) {
191 $options['sigil'] = 'workflow';
192 $buttons[] = javelin_tag(
197 $buttons[] = phutil_tag(
206 $tail = phutil_tag_div('phui-hovercard-tail', $buttons);
209 $hovercard = phutil_tag_div(
210 'phui-hovercard-container grouped',
212 phutil_tag_div('phui-hovercard-head', $header),
213 phutil_tag_div('phui-hovercard-body grouped', $body),