[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/transactions/view/ -> PhabricatorApplicationTransactionCommentView.php (source)

   1  <?php
   2  
   3  /**
   4   * @concrete-extensible
   5   */
   6  class PhabricatorApplicationTransactionCommentView extends AphrontView {
   7  
   8    private $submitButtonName;
   9    private $action;
  10  
  11    private $previewPanelID;
  12    private $previewTimelineID;
  13    private $previewToggleID;
  14    private $formID;
  15    private $statusID;
  16    private $commentID;
  17    private $draft;
  18    private $requestURI;
  19    private $showPreview = true;
  20    private $objectPHID;
  21    private $headerText;
  22  
  23    public function setObjectPHID($object_phid) {
  24      $this->objectPHID = $object_phid;
  25      return $this;
  26    }
  27  
  28    public function getObjectPHID() {
  29      return $this->objectPHID;
  30    }
  31  
  32    public function setShowPreview($show_preview) {
  33      $this->showPreview = $show_preview;
  34      return $this;
  35    }
  36  
  37    public function getShowPreview() {
  38      return $this->showPreview;
  39    }
  40  
  41    public function setRequestURI(PhutilURI $request_uri) {
  42      $this->requestURI = $request_uri;
  43      return $this;
  44    }
  45    public function getRequestURI() {
  46      return $this->requestURI;
  47    }
  48  
  49    public function setDraft(PhabricatorDraft $draft) {
  50      $this->draft = $draft;
  51      return $this;
  52    }
  53  
  54    public function getDraft() {
  55      return $this->draft;
  56    }
  57  
  58    public function setSubmitButtonName($submit_button_name) {
  59      $this->submitButtonName = $submit_button_name;
  60      return $this;
  61    }
  62  
  63    public function getSubmitButtonName() {
  64      return $this->submitButtonName;
  65    }
  66  
  67    public function setAction($action) {
  68      $this->action = $action;
  69      return $this;
  70    }
  71  
  72    public function getAction() {
  73      return $this->action;
  74    }
  75  
  76    public function setHeaderText($text) {
  77      $this->headerText = $text;
  78      return $this;
  79    }
  80  
  81    public function render() {
  82  
  83      $user = $this->getUser();
  84      if (!$user->isLoggedIn()) {
  85        $uri = id(new PhutilURI('/login/'))
  86          ->setQueryParam('next', (string) $this->getRequestURI());
  87        return id(new PHUIObjectBoxView())
  88          ->setFlush(true)
  89          ->setHeaderText(pht('Add Comment'))
  90          ->appendChild(
  91            javelin_tag(
  92              'a',
  93              array(
  94                'class' => 'login-to-comment button',
  95                'href' => $uri,
  96              ),
  97              pht('Login to Comment')));
  98      }
  99  
 100      $data = array();
 101  
 102      $comment = $this->renderCommentPanel();
 103  
 104      if ($this->getShowPreview()) {
 105        $preview = $this->renderPreviewPanel();
 106      } else {
 107        $preview = null;
 108      }
 109  
 110      Javelin::initBehavior(
 111        'phabricator-transaction-comment-form',
 112        array(
 113          'formID'        => $this->getFormID(),
 114          'timelineID'    => $this->getPreviewTimelineID(),
 115          'panelID'       => $this->getPreviewPanelID(),
 116          'statusID'      => $this->getStatusID(),
 117          'commentID'     => $this->getCommentID(),
 118  
 119          'loadingString' => pht('Loading Preview...'),
 120          'savingString'  => pht('Saving Draft...'),
 121          'draftString'   => pht('Saved Draft'),
 122  
 123          'showPreview'   => $this->getShowPreview(),
 124  
 125          'actionURI'     => $this->getAction(),
 126        ));
 127  
 128      $comment_box = id(new PHUIObjectBoxView())
 129        ->setFlush(true)
 130        ->setHeaderText($this->headerText)
 131        ->appendChild($comment);
 132  
 133      return array($comment_box, $preview);
 134    }
 135  
 136    private function renderCommentPanel() {
 137      $status = phutil_tag(
 138        'div',
 139        array(
 140          'id' => $this->getStatusID(),
 141        ),
 142        '');
 143  
 144      $draft_comment = '';
 145      $draft_key = null;
 146      if ($this->getDraft()) {
 147        $draft_comment = $this->getDraft()->getDraft();
 148        $draft_key = $this->getDraft()->getDraftKey();
 149      }
 150  
 151      if (!$this->getObjectPHID()) {
 152        throw new Exception('Call setObjectPHID() before render()!');
 153      }
 154  
 155      return id(new AphrontFormView())
 156        ->setUser($this->getUser())
 157        ->addSigil('transaction-append')
 158        ->setWorkflow(true)
 159        ->setMetadata(
 160          array(
 161            'objectPHID' => $this->getObjectPHID(),
 162          ))
 163        ->setAction($this->getAction())
 164        ->setID($this->getFormID())
 165        ->addHiddenInput('__draft__', $draft_key)
 166        ->appendChild(
 167          id(new PhabricatorRemarkupControl())
 168            ->setID($this->getCommentID())
 169            ->setName('comment')
 170            ->setLabel(pht('Comment'))
 171            ->setUser($this->getUser())
 172            ->setValue($draft_comment))
 173        ->appendChild(
 174          id(new AphrontFormSubmitControl())
 175            ->setValue($this->getSubmitButtonName()))
 176        ->appendChild(
 177          id(new AphrontFormMarkupControl())
 178            ->setValue($status));
 179    }
 180  
 181    private function renderPreviewPanel() {
 182  
 183      $preview = id(new PHUITimelineView())
 184        ->setID($this->getPreviewTimelineID());
 185  
 186      return phutil_tag(
 187        'div',
 188        array(
 189          'id'    => $this->getPreviewPanelID(),
 190          'style' => 'display: none',
 191        ),
 192        $preview);
 193    }
 194  
 195    private function getPreviewPanelID() {
 196      if (!$this->previewPanelID) {
 197        $this->previewPanelID = celerity_generate_unique_node_id();
 198      }
 199      return $this->previewPanelID;
 200    }
 201  
 202    private function getPreviewTimelineID() {
 203      if (!$this->previewTimelineID) {
 204        $this->previewTimelineID = celerity_generate_unique_node_id();
 205      }
 206      return $this->previewTimelineID;
 207    }
 208  
 209    public function setFormID($id) {
 210      $this->formID = $id;
 211      return $this;
 212    }
 213  
 214    private function getFormID() {
 215      if (!$this->formID) {
 216        $this->formID = celerity_generate_unique_node_id();
 217      }
 218      return $this->formID;
 219    }
 220  
 221    private function getStatusID() {
 222      if (!$this->statusID) {
 223        $this->statusID = celerity_generate_unique_node_id();
 224      }
 225      return $this->statusID;
 226    }
 227  
 228    private function getCommentID() {
 229      if (!$this->commentID) {
 230        $this->commentID = celerity_generate_unique_node_id();
 231      }
 232      return $this->commentID;
 233    }
 234  
 235  }


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