[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/widget/hovercard/ -> PhabricatorHovercardView.php (source)

   1  <?php
   2  
   3  /**
   4   * The default one-for-all hovercard. We may derive from this one to create
   5   * more specialized ones
   6   */
   7  final class PhabricatorHovercardView extends AphrontView {
   8  
   9    /**
  10     * @var PhabricatorObjectHandle
  11     */
  12    private $handle;
  13  
  14    private $title = array();
  15    private $detail;
  16    private $tags = array();
  17    private $fields = array();
  18    private $actions = array();
  19  
  20    private $color = 'lightblue';
  21    public function setObjectHandle(PhabricatorObjectHandle $handle) {
  22      $this->handle = $handle;
  23      return $this;
  24    }
  25  
  26    public function setTitle($title) {
  27      $this->title = $title;
  28      return $this;
  29    }
  30  
  31    public function setDetail($detail) {
  32      $this->detail = $detail;
  33      return $this;
  34    }
  35  
  36    public function addField($label, $value) {
  37      $this->fields[] = array(
  38        'label' => $label,
  39        'value' => $value,
  40      );
  41      return $this;
  42    }
  43  
  44    public function addAction($label, $uri, $workflow = false) {
  45      $this->actions[] = array(
  46        'label'    => $label,
  47        'uri'      => $uri,
  48        'workflow' => $workflow,
  49      );
  50      return $this;
  51    }
  52  
  53    public function addTag(PHUITagView $tag) {
  54      $this->tags[] = $tag;
  55      return $this;
  56    }
  57  
  58    public function setColor($color) {
  59      $this->color = $color;
  60      return $this;
  61    }
  62  
  63    public function render() {
  64      if (!$this->handle) {
  65        throw new Exception('Call setObjectHandle() before calling render()!');
  66      }
  67  
  68      $handle = $this->handle;
  69  
  70      require_celerity_resource('phabricator-hovercard-view-css');
  71  
  72      $title = pht('%s: %s',
  73        $handle->getTypeName(),
  74        $this->title ? $this->title : $handle->getName());
  75  
  76      $header = new PHUIActionHeaderView();
  77      $header->setHeaderColor($this->color);
  78      $header->setHeaderTitle($title);
  79      if ($this->tags) {
  80        foreach ($this->tags as $tag) {
  81          $header->setTag($tag);
  82        }
  83      }
  84  
  85      $body = array();
  86  
  87      if ($this->detail) {
  88        $body_title = $this->detail;
  89      } else {
  90        // Fallback for object handles
  91        $body_title = $handle->getFullName();
  92      }
  93  
  94      $body[] = phutil_tag_div('phabricator-hovercard-body-header', $body_title);
  95  
  96      foreach ($this->fields as $field) {
  97        $item = array(
  98          phutil_tag('strong', array(), $field['label']),
  99          ' ',
 100          phutil_tag('span', array(), $field['value']),
 101        );
 102        $body[] = phutil_tag_div('phabricator-hovercard-body-item', $item);
 103      }
 104  
 105      if ($handle->getImageURI()) {
 106        // Probably a user, we don't need to assume something else
 107        // "Prepend" the image by appending $body
 108        $body = phutil_tag(
 109          'div',
 110          array(
 111            'class' => 'phabricator-hovercard-body-image',
 112          ),
 113          phutil_tag(
 114            'div',
 115            array(
 116              'class' => 'profile-header-picture-frame',
 117              'style' => 'background-image: url('.$handle->getImageURI().');',
 118            ),
 119            ''))
 120        ->appendHTML(
 121          phutil_tag(
 122            'div',
 123            array(
 124              'class' => 'phabricator-hovercard-body-details',
 125            ),
 126            $body));
 127      }
 128  
 129      $buttons = array();
 130  
 131      foreach ($this->actions as $action) {
 132        $options = array(
 133          'class' => 'button grey',
 134          'href'  => $action['uri'],
 135        );
 136  
 137        if ($action['workflow']) {
 138          $options['sigil'] = 'workflow';
 139          $buttons[] = javelin_tag(
 140            'a',
 141            $options,
 142            $action['label']);
 143        } else {
 144          $buttons[] = phutil_tag(
 145            'a',
 146            $options,
 147            $action['label']);
 148        }
 149      }
 150  
 151      $tail = null;
 152      if ($buttons) {
 153        $tail = phutil_tag_div('phabricator-hovercard-tail', $buttons);
 154      }
 155  
 156      // Assemble container
 157      // TODO: Add color support
 158      $hovercard = phutil_tag_div(
 159        'phabricator-hovercard-container',
 160        array(
 161          phutil_tag_div('phabricator-hovercard-head', $header),
 162          phutil_tag_div('phabricator-hovercard-body grouped', $body),
 163          $tail,
 164        ));
 165  
 166      // Wrap for thick border
 167      // and later the tip at the bottom
 168      return phutil_tag_div('phabricator-hovercard-wrapper', $hovercard);
 169    }
 170  
 171  }


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