[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/layout/ -> PhabricatorActionView.php (source)

   1  <?php
   2  
   3  final class PhabricatorActionView extends AphrontView {
   4  
   5    private $name;
   6    private $icon;
   7    private $href;
   8    private $disabled;
   9    private $workflow;
  10    private $renderAsForm;
  11    private $download;
  12    private $objectURI;
  13    private $sigils = array();
  14    private $metadata;
  15    private $selected;
  16  
  17    public function setSelected($selected) {
  18      $this->selected = $selected;
  19      return $this;
  20    }
  21  
  22    public function getSelected() {
  23      return $this->selected;
  24    }
  25  
  26    public function setMetadata($metadata) {
  27      $this->metadata = $metadata;
  28      return $this;
  29    }
  30  
  31    public function getMetadata() {
  32      return $this->metadata;
  33    }
  34  
  35    public function setObjectURI($object_uri) {
  36      $this->objectURI = $object_uri;
  37      return $this;
  38    }
  39    public function getObjectURI() {
  40      return $this->objectURI;
  41    }
  42  
  43    public function setDownload($download) {
  44      $this->download = $download;
  45      return $this;
  46    }
  47  
  48    public function getDownload() {
  49      return $this->download;
  50    }
  51  
  52    public function setHref($href) {
  53      $this->href = $href;
  54      return $this;
  55    }
  56  
  57    public function addSigil($sigil) {
  58      $this->sigils[] = $sigil;
  59      return $this;
  60    }
  61  
  62    /**
  63     * If the user is not logged in and the action is relatively complicated,
  64     * give them a generic login link that will re-direct to the page they're
  65     * viewing.
  66     */
  67    public function getHref() {
  68      if (($this->workflow || $this->renderAsForm) && !$this->download) {
  69        if (!$this->user || !$this->user->isLoggedIn()) {
  70          return id(new PhutilURI('/auth/start/'))
  71            ->setQueryParam('next', (string)$this->getObjectURI());
  72        }
  73      }
  74  
  75      return $this->href;
  76    }
  77  
  78    public function setIcon($icon) {
  79      $this->icon = $icon;
  80      return $this;
  81    }
  82  
  83    public function setName($name) {
  84      $this->name = $name;
  85      return $this;
  86    }
  87  
  88    public function setDisabled($disabled) {
  89      $this->disabled = $disabled;
  90      return $this;
  91    }
  92  
  93    public function setWorkflow($workflow) {
  94      $this->workflow = $workflow;
  95      return $this;
  96    }
  97  
  98    public function setRenderAsForm($form) {
  99      $this->renderAsForm = $form;
 100      return $this;
 101    }
 102  
 103    public function render() {
 104  
 105      $icon = null;
 106      if ($this->icon) {
 107        $color = '';
 108        if ($this->disabled) {
 109          $color = ' grey';
 110        }
 111        $icon = id(new PHUIIconView())
 112          ->addClass('phabricator-action-view-icon')
 113          ->setIconFont($this->icon.$color);
 114      }
 115  
 116      if ($this->href) {
 117  
 118        $sigils = array();
 119        if ($this->workflow) {
 120          $sigils[] = 'workflow';
 121        }
 122        if ($this->download) {
 123          $sigils[] = 'download';
 124        }
 125  
 126        if ($this->sigils) {
 127          $sigils = array_merge($sigils, $this->sigils);
 128        }
 129  
 130        $sigils = $sigils ? implode(' ', $sigils) : null;
 131  
 132        if ($this->renderAsForm) {
 133          if (!$this->user) {
 134            throw new Exception(
 135              'Call setUser() when rendering an action as a form.');
 136          }
 137  
 138          $item = javelin_tag(
 139            'button',
 140            array(
 141              'class' => 'phabricator-action-view-item',
 142            ),
 143            array($icon, $this->name));
 144  
 145          $item = phabricator_form(
 146            $this->user,
 147            array(
 148              'action'    => $this->getHref(),
 149              'method'    => 'POST',
 150              'sigil'     => $sigils,
 151              'meta' => $this->metadata,
 152            ),
 153            $item);
 154        } else {
 155          $item = javelin_tag(
 156            'a',
 157            array(
 158              'href'  => $this->getHref(),
 159              'class' => 'phabricator-action-view-item',
 160              'sigil' => $sigils,
 161              'meta' => $this->metadata,
 162            ),
 163            array($icon, $this->name));
 164        }
 165      } else {
 166        $item = phutil_tag(
 167          'span',
 168          array(
 169            'class' => 'phabricator-action-view-item',
 170          ),
 171          array($icon, $this->name));
 172      }
 173  
 174      $classes = array();
 175      $classes[] = 'phabricator-action-view';
 176      if ($this->disabled) {
 177        $classes[] = 'phabricator-action-view-disabled';
 178      }
 179  
 180      if ($this->selected) {
 181        $classes[] = 'phabricator-action-view-selected';
 182      }
 183  
 184      return phutil_tag(
 185        'li',
 186        array(
 187          'class' => implode(' ', $classes),
 188        ),
 189        $item);
 190    }
 191  
 192  }


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