[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/control/ -> PhabricatorObjectSelectorDialog.php (source)

   1  <?php
   2  
   3  final class PhabricatorObjectSelectorDialog {
   4  
   5    private $user;
   6    private $filters = array();
   7    private $handles = array();
   8    private $cancelURI;
   9    private $submitURI;
  10    private $searchURI;
  11    private $selectedFilter;
  12    private $excluded;
  13  
  14    private $title;
  15    private $header;
  16    private $buttonText;
  17    private $instructions;
  18  
  19    public function setUser($user) {
  20      $this->user = $user;
  21      return $this;
  22    }
  23  
  24    public function setFilters(array $filters) {
  25      $this->filters = $filters;
  26      return $this;
  27    }
  28  
  29    public function setSelectedFilter($selected_filter) {
  30      $this->selectedFilter = $selected_filter;
  31      return $this;
  32    }
  33  
  34    public function setExcluded($excluded_phid) {
  35      $this->excluded = $excluded_phid;
  36      return $this;
  37    }
  38  
  39    public function setHandles(array $handles) {
  40      assert_instances_of($handles, 'PhabricatorObjectHandle');
  41      $this->handles = $handles;
  42      return $this;
  43    }
  44  
  45    public function setCancelURI($cancel_uri) {
  46      $this->cancelURI = $cancel_uri;
  47      return $this;
  48    }
  49  
  50    public function setSubmitURI($submit_uri) {
  51      $this->submitURI = $submit_uri;
  52      return $this;
  53    }
  54  
  55    public function setSearchURI($search_uri) {
  56      $this->searchURI = $search_uri;
  57      return $this;
  58    }
  59  
  60    public function setTitle($title) {
  61      $this->title = $title;
  62      return $this;
  63    }
  64  
  65    public function setHeader($header) {
  66      $this->header = $header;
  67      return $this;
  68    }
  69  
  70    public function setButtonText($button_text) {
  71      $this->buttonText = $button_text;
  72      return $this;
  73    }
  74  
  75    public function setInstructions($instructions) {
  76      $this->instructions = $instructions;
  77      return $this;
  78    }
  79  
  80    public function buildDialog() {
  81      $user = $this->user;
  82  
  83      $filter_id = celerity_generate_unique_node_id();
  84      $query_id = celerity_generate_unique_node_id();
  85      $results_id = celerity_generate_unique_node_id();
  86      $current_id = celerity_generate_unique_node_id();
  87      $search_id  = celerity_generate_unique_node_id();
  88      $form_id = celerity_generate_unique_node_id();
  89  
  90      require_celerity_resource('phabricator-object-selector-css');
  91  
  92      $options = array();
  93      foreach ($this->filters as $key => $label) {
  94        $options[] = phutil_tag(
  95          'option',
  96          array(
  97            'value' => $key,
  98            'selected' => ($key == $this->selectedFilter)
  99              ? 'selected'
 100              : null,
 101          ),
 102          $label);
 103      }
 104  
 105      $instructions = null;
 106      if ($this->instructions) {
 107        $instructions = phutil_tag(
 108          'p',
 109          array('class' => 'phabricator-object-selector-instructions'),
 110          $this->instructions);
 111      }
 112  
 113      $search_box = phabricator_form(
 114        $user,
 115        array(
 116          'method' => 'POST',
 117          'action' => $this->submitURI,
 118          'id'     => $search_id,
 119        ),
 120        phutil_tag(
 121          'table',
 122          array('class' => 'phabricator-object-selector-search'),
 123          phutil_tag('tr', array(), array(
 124            phutil_tag(
 125              'td',
 126              array('class' => 'phabricator-object-selector-search-filter'),
 127              phutil_tag('select', array('id' => $filter_id), $options)),
 128            phutil_tag(
 129              'td',
 130              array('class' => 'phabricator-object-selector-search-text'),
 131              phutil_tag('input', array('id' => $query_id, 'type' => 'text'))),
 132          ))));
 133  
 134      $result_box = phutil_tag(
 135        'div',
 136        array(
 137          'class' => 'phabricator-object-selector-results',
 138          'id' => $results_id,
 139        ),
 140        '');
 141  
 142      $attached_box = phutil_tag_div(
 143        'phabricator-object-selector-current',
 144        phutil_tag_div(
 145          'phabricator-object-selector-currently-attached',
 146          array(
 147            phutil_tag_div('phabricator-object-selector-header', $this->header),
 148            phutil_tag('div', array('id' => $current_id)),
 149            $instructions,
 150          )));
 151  
 152      $dialog = new AphrontDialogView();
 153      $dialog
 154        ->setUser($this->user)
 155        ->setTitle($this->title)
 156        ->setClass('phabricator-object-selector-dialog')
 157        ->appendChild($search_box)
 158        ->appendChild($result_box)
 159        ->appendChild($attached_box)
 160        ->setRenderDialogAsDiv()
 161        ->setFormID($form_id)
 162        ->addSubmitButton($this->buttonText);
 163  
 164      if ($this->cancelURI) {
 165        $dialog->addCancelButton($this->cancelURI);
 166      }
 167  
 168      $handle_views = array();
 169      foreach ($this->handles as $handle) {
 170        $phid = $handle->getPHID();
 171        $view = new PhabricatorHandleObjectSelectorDataView($handle);
 172        $handle_views[$phid] = $view->renderData();
 173      }
 174      $dialog->addHiddenInput('phids', implode(';', array_keys($this->handles)));
 175  
 176  
 177      Javelin::initBehavior(
 178        'phabricator-object-selector',
 179        array(
 180          'filter'  => $filter_id,
 181          'query'   => $query_id,
 182          'search'  => $search_id,
 183          'results' => $results_id,
 184          'current' => $current_id,
 185          'form'    => $form_id,
 186          'exclude' => $this->excluded,
 187          'uri'     => $this->searchURI,
 188          'handles' => $handle_views,
 189        ));
 190  
 191     return $dialog;
 192    }
 193  
 194  }


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