[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/view/ -> DifferentialAddCommentView.php (source)

   1  <?php
   2  
   3  final class DifferentialAddCommentView extends AphrontView {
   4  
   5    private $revision;
   6    private $actions;
   7    private $actionURI;
   8    private $draft;
   9    private $reviewers = array();
  10    private $ccs = array();
  11    private $errorView;
  12  
  13    public function setErrorView(AphrontErrorView $error_view) {
  14      $this->errorView = $error_view;
  15      return $this;
  16    }
  17  
  18    public function getErrorView() {
  19      return $this->errorView;
  20    }
  21  
  22    public function setRevision($revision) {
  23      $this->revision = $revision;
  24      return $this;
  25    }
  26  
  27    public function setActions(array $actions) {
  28      $this->actions = $actions;
  29      return $this;
  30    }
  31  
  32    public function setActionURI($uri) {
  33      $this->actionURI = $uri;
  34      return $this;
  35    }
  36  
  37    public function setDraft(PhabricatorDraft $draft = null) {
  38      $this->draft = $draft;
  39      return $this;
  40    }
  41  
  42    public function setReviewers(array $names) {
  43      $this->reviewers = $names;
  44      return $this;
  45    }
  46  
  47    public function setCCs(array $names) {
  48      $this->ccs = $names;
  49      return $this;
  50    }
  51  
  52    public function render() {
  53  
  54      $this->requireResource('differential-revision-add-comment-css');
  55      $revision = $this->revision;
  56  
  57      $action = null;
  58      if ($this->draft) {
  59        $action = idx($this->draft->getMetadata(), 'action');
  60      }
  61  
  62      $enable_reviewers = DifferentialAction::allowReviewers($action);
  63      $enable_ccs = ($action == DifferentialAction::ACTION_ADDCCS);
  64      $add_reviewers_labels = array(
  65        'add_reviewers' => pht('Add Reviewers'),
  66        'request_review' => pht('Add Reviewers'),
  67        'resign' => pht('Suggest Reviewers'),
  68      );
  69  
  70      $form = new AphrontFormView();
  71      $form
  72        ->setWorkflow(true)
  73        ->setUser($this->user)
  74        ->setAction($this->actionURI)
  75        ->addHiddenInput('revision_id', $revision->getID())
  76        ->appendChild(
  77          id(new AphrontFormSelectControl())
  78            ->setLabel(pht('Action'))
  79            ->setName('action')
  80            ->setValue($action)
  81            ->setID('comment-action')
  82            ->setOptions($this->actions))
  83        ->appendChild(
  84          id(new AphrontFormTokenizerControl())
  85            ->setLabel($enable_reviewers ? $add_reviewers_labels[$action] :
  86              $add_reviewers_labels['add_reviewers'])
  87            ->setName('reviewers')
  88            ->setControlID('add-reviewers')
  89            ->setControlStyle($enable_reviewers ? null : 'display: none')
  90            ->setID('add-reviewers-tokenizer')
  91            ->setDisableBehavior(true))
  92        ->appendChild(
  93          id(new AphrontFormTokenizerControl())
  94            ->setLabel(pht('Add Subscribers'))
  95            ->setName('ccs')
  96            ->setControlID('add-ccs')
  97            ->setControlStyle($enable_ccs ? null : 'display: none')
  98            ->setID('add-ccs-tokenizer')
  99            ->setDisableBehavior(true))
 100        ->appendChild(
 101          id(new PhabricatorRemarkupControl())
 102            ->setName('comment')
 103            ->setID('comment-content')
 104            ->setLabel(pht('Comment'))
 105            ->setValue($this->draft ? $this->draft->getDraft() : null)
 106            ->setUser($this->user))
 107        ->appendChild(
 108          id(new AphrontFormSubmitControl())
 109            ->setValue(pht('Submit')));
 110  
 111      $mailable_source = new PhabricatorMetaMTAMailableDatasource();
 112      $reviewer_source = new PhabricatorProjectOrUserDatasource();
 113  
 114      Javelin::initBehavior(
 115        'differential-add-reviewers-and-ccs',
 116        array(
 117          'dynamic' => array(
 118            'add-reviewers-tokenizer' => array(
 119              'actions' => array(
 120                'request_review' => 1,
 121                'add_reviewers' => 1,
 122                'resign' => 1,
 123              ),
 124              'src' => $reviewer_source->getDatasourceURI(),
 125              'value' => $this->reviewers,
 126              'row' => 'add-reviewers',
 127              'labels' => $add_reviewers_labels,
 128              'placeholder' => $reviewer_source->getPlaceholderText(),
 129            ),
 130            'add-ccs-tokenizer' => array(
 131              'actions' => array('add_ccs' => 1),
 132              'src' => $mailable_source->getDatasourceURI(),
 133              'value' => $this->ccs,
 134              'row' => 'add-ccs',
 135              'placeholder' => $mailable_source->getPlaceholderText(),
 136            ),
 137          ),
 138          'select' => 'comment-action',
 139        ));
 140  
 141      $diff = $revision->loadActiveDiff();
 142      $rev_id = $revision->getID();
 143  
 144      Javelin::initBehavior(
 145        'differential-feedback-preview',
 146        array(
 147          'uri'       => '/differential/comment/preview/'.$rev_id.'/',
 148          'preview'   => 'comment-preview',
 149          'action'    => 'comment-action',
 150          'content'   => 'comment-content',
 151          'previewTokenizers' => array(
 152            'reviewers' => 'add-reviewers-tokenizer',
 153            'ccs'       => 'add-ccs-tokenizer',
 154          ),
 155  
 156          'inlineuri' => '/differential/comment/inline/preview/'.$rev_id.'/',
 157          'inline'    => 'inline-comment-preview',
 158        ));
 159  
 160      $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
 161      $header_text = $is_serious
 162        ? pht('Add Comment')
 163        : pht('Leap Into Action');
 164  
 165      $header = id(new PHUIHeaderView())
 166        ->setHeader($header_text);
 167  
 168      $anchor = id(new PhabricatorAnchorView())
 169          ->setAnchorName('comment')
 170          ->setNavigationMarker(true);
 171  
 172      $loading = phutil_tag(
 173        'span',
 174        array('class' => 'aphront-panel-preview-loading-text'),
 175        pht('Loading comment preview...'));
 176  
 177      $preview = phutil_tag_div(
 178        'aphront-panel-preview aphront-panel-flush',
 179        array(
 180          phutil_tag('div', array('id' => 'comment-preview'), $loading),
 181          phutil_tag('div', array('id' => 'inline-comment-preview')),
 182        ));
 183  
 184  
 185      $comment_box = id(new PHUIObjectBoxView())
 186        ->setHeader($header)
 187        ->appendChild($anchor)
 188        ->appendChild($form);
 189  
 190      if ($this->errorView) {
 191        $comment_box->setErrorView($this->errorView);
 192      }
 193  
 194      return array($comment_box, $preview);
 195    }
 196  }


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