public function render()
 {
     if (!$this->handle) {
         throw new PhutilInvalidStateException('setObjectHandle');
     }
     $viewer = $this->getUser();
     $handle = $this->handle;
     require_celerity_resource('phabricator-hovercard-view-css');
     $title = array(id(new PHUISpacesNamespaceContextView())->setUser($viewer)->setObject($this->getObject()), pht('%s: %s', $handle->getTypeName(), $this->title ? $this->title : $handle->getName()));
     $header = new PHUIActionHeaderView();
     $header->setHeaderColor($this->color);
     $header->setHeaderTitle($title);
     if ($this->tags) {
         foreach ($this->tags as $tag) {
             $header->setTag($tag);
         }
     }
     $body = array();
     if ($this->detail) {
         $body_title = $this->detail;
     } else {
         // Fallback for object handles
         $body_title = $handle->getFullName();
     }
     $body[] = phutil_tag_div('phabricator-hovercard-body-header', $body_title);
     foreach ($this->fields as $field) {
         $item = array(phutil_tag('strong', array(), $field['label']), ' ', phutil_tag('span', array(), $field['value']));
         $body[] = phutil_tag_div('phabricator-hovercard-body-item', $item);
     }
     if ($handle->getImageURI()) {
         // Probably a user, we don't need to assume something else
         // "Prepend" the image by appending $body
         $body = phutil_tag('div', array('class' => 'phabricator-hovercard-body-image'), phutil_tag('div', array('class' => 'profile-header-picture-frame', 'style' => 'background-image: url(' . $handle->getImageURI() . ');'), ''))->appendHTML(phutil_tag('div', array('class' => 'phabricator-hovercard-body-details'), $body));
     }
     $buttons = array();
     foreach ($this->actions as $action) {
         $options = array('class' => 'button grey', 'href' => $action['uri']);
         if ($action['workflow']) {
             $options['sigil'] = 'workflow';
             $buttons[] = javelin_tag('a', $options, $action['label']);
         } else {
             $buttons[] = phutil_tag('a', $options, $action['label']);
         }
     }
     $tail = null;
     if ($buttons) {
         $tail = phutil_tag_div('phabricator-hovercard-tail', $buttons);
     }
     // Assemble container
     // TODO: Add color support
     $hovercard = phutil_tag_div('phabricator-hovercard-container', array(phutil_tag_div('phabricator-hovercard-head', $header), phutil_tag_div('phabricator-hovercard-body grouped', $body), $tail));
     // Wrap for thick border
     // and later the tip at the bottom
     return phutil_tag_div('phabricator-hovercard-wrapper', $hovercard);
 }
Example #2
0
 public final function render()
 {
     require_celerity_resource('aphront-dialog-view-css');
     $buttons = array();
     if ($this->submitButton) {
         $meta = array();
         if ($this->disableWorkflowOnSubmit) {
             $meta['disableWorkflow'] = true;
         }
         $buttons[] = javelin_tag('button', array('name' => '__submit__', 'sigil' => '__default__', 'type' => 'submit', 'meta' => $meta), $this->submitButton);
     }
     if ($this->cancelURI) {
         $meta = array();
         if ($this->disableWorkflowOnCancel) {
             $meta['disableWorkflow'] = true;
         }
         $buttons[] = javelin_tag('a', array('href' => $this->cancelURI, 'class' => 'button grey', 'name' => '__cancel__', 'sigil' => 'jx-workflow-button', 'meta' => $meta), $this->cancelText);
     }
     if (!$this->user) {
         throw new Exception(pht('You must call setUser() when rendering an AphrontDialogView.'));
     }
     $more = $this->class;
     if ($this->flush) {
         $more .= ' aphront-dialog-flush';
     }
     switch ($this->width) {
         case self::WIDTH_FORM:
         case self::WIDTH_FULL:
             $more .= ' aphront-dialog-view-width-' . $this->width;
             break;
         case self::WIDTH_DEFAULT:
             break;
         default:
             throw new Exception("Unknown dialog width '{$this->width}'!");
     }
     if ($this->isStandalone) {
         $more .= ' aphront-dialog-view-standalone';
     }
     $attributes = array('class' => 'aphront-dialog-view ' . $more, 'sigil' => 'jx-dialog');
     $form_attributes = array('action' => $this->submitURI, 'method' => $this->method, 'id' => $this->formID);
     $hidden_inputs = array();
     $hidden_inputs[] = phutil_tag('input', array('type' => 'hidden', 'name' => '__dialog__', 'value' => '1'));
     foreach ($this->hidden as $desc) {
         list($key, $value) = $desc;
         $hidden_inputs[] = javelin_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value, 'sigil' => 'aphront-dialog-application-input'));
     }
     if (!$this->renderAsForm) {
         $buttons = array(phabricator_form($this->user, $form_attributes, array_merge($hidden_inputs, $buttons)));
     }
     $children = $this->renderChildren();
     $errors = $this->errors;
     $ex = $this->validationException;
     $exception_errors = null;
     if ($ex) {
         foreach ($ex->getErrors() as $error) {
             $errors[] = $error->getMessage();
         }
     }
     if ($errors) {
         $children = array(id(new AphrontErrorView())->setErrors($errors), $children);
     }
     $header = new PHUIActionHeaderView();
     $header->setHeaderTitle($this->title);
     $header->setHeaderColor($this->headerColor);
     $footer = null;
     if ($this->footers) {
         $footer = phutil_tag('div', array('class' => 'aphront-dialog-foot'), $this->footers);
     }
     $content = array(phutil_tag('div', array('class' => 'aphront-dialog-head'), $header), phutil_tag('div', array('class' => 'aphront-dialog-body grouped'), $children), phutil_tag('div', array('class' => 'aphront-dialog-tail grouped'), array($buttons, $footer)));
     if ($this->renderAsForm) {
         return phabricator_form($this->user, $form_attributes + $attributes, array($hidden_inputs, $content));
     } else {
         return javelin_tag('div', $attributes, $content);
     }
 }