2013-06-13 03:23:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PHUIButtonView extends AphrontTagView {
|
|
|
|
|
|
|
|
const GREEN = 'green';
|
|
|
|
const GREY = 'grey';
|
|
|
|
const DISABLED = 'disabled';
|
|
|
|
|
|
|
|
const SMALL = 'small';
|
|
|
|
const BIG = 'big';
|
|
|
|
|
2017-05-30 23:32:54 +02:00
|
|
|
const BUTTONTYPE_DEFAULT = 'buttontype.default';
|
|
|
|
const BUTTONTYPE_SIMPLE = 'buttontype.simple';
|
|
|
|
|
2013-06-13 03:23:35 +02:00
|
|
|
private $size;
|
|
|
|
private $text;
|
|
|
|
private $subtext;
|
|
|
|
private $color;
|
2013-06-17 15:12:45 +02:00
|
|
|
private $tag = 'button';
|
2013-06-13 03:23:35 +02:00
|
|
|
private $dropdown;
|
|
|
|
private $icon;
|
2015-06-02 23:34:04 +02:00
|
|
|
private $iconFirst;
|
2013-12-03 20:58:10 +01:00
|
|
|
private $href = null;
|
2014-02-10 20:11:36 +01:00
|
|
|
private $title = null;
|
2014-02-21 23:43:24 +01:00
|
|
|
private $disabled;
|
2014-03-25 22:20:25 +01:00
|
|
|
private $name;
|
2015-03-26 19:09:20 +01:00
|
|
|
private $tooltip;
|
2017-01-17 21:04:28 +01:00
|
|
|
private $noCSS;
|
2017-01-17 22:59:56 +01:00
|
|
|
private $hasCaret;
|
2017-05-30 23:32:54 +02:00
|
|
|
private $buttonType = self::BUTTONTYPE_DEFAULT;
|
2014-03-25 22:20:25 +01:00
|
|
|
|
|
|
|
public function setName($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
2013-06-13 03:23:35 +02:00
|
|
|
|
|
|
|
public function setText($text) {
|
|
|
|
$this->text = $text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-12-03 20:58:10 +01:00
|
|
|
public function setHref($href) {
|
|
|
|
$this->href = $href;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-10 20:11:36 +01:00
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-13 03:23:35 +02:00
|
|
|
public function setSubtext($subtext) {
|
|
|
|
$this->subtext = $subtext;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setColor($color) {
|
|
|
|
$this->color = $color;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-05-17 05:13:34 +02:00
|
|
|
public function getColor() {
|
|
|
|
return $this->color;
|
|
|
|
}
|
|
|
|
|
2014-02-21 23:43:24 +01:00
|
|
|
public function setDisabled($disabled) {
|
|
|
|
$this->disabled = $disabled;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-13 03:23:35 +02:00
|
|
|
public function setTag($tag) {
|
|
|
|
$this->tag = $tag;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSize($size) {
|
|
|
|
$this->size = $size;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDropdown($dd) {
|
|
|
|
$this->dropdown = $dd;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-03-26 19:09:20 +01:00
|
|
|
public function setTooltip($text) {
|
|
|
|
$this->tooltip = $text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-17 21:04:28 +01:00
|
|
|
public function setNoCSS($no_css) {
|
|
|
|
$this->noCSS = $no_css;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-17 22:59:56 +01:00
|
|
|
public function setHasCaret($has_caret) {
|
|
|
|
$this->hasCaret = $has_caret;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHasCaret() {
|
|
|
|
return $this->hasCaret;
|
|
|
|
}
|
|
|
|
|
2017-05-30 23:32:54 +02:00
|
|
|
public function setButtonType($button_type) {
|
|
|
|
$this->buttonType = $button_type;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getButtonType() {
|
|
|
|
return $this->buttonType;
|
|
|
|
}
|
|
|
|
|
2016-01-28 05:38:01 +01:00
|
|
|
public function setIcon($icon, $first = true) {
|
|
|
|
if (!($icon instanceof PHUIIconView)) {
|
|
|
|
$icon = id(new PHUIIconView())
|
|
|
|
->setIcon($icon);
|
|
|
|
}
|
2013-06-13 03:23:35 +02:00
|
|
|
$this->icon = $icon;
|
2015-06-02 23:34:04 +02:00
|
|
|
$this->iconFirst = $first;
|
2013-06-13 03:23:35 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:54:39 +01:00
|
|
|
protected function getTagName() {
|
2013-06-13 03:23:35 +02:00
|
|
|
return $this->tag;
|
|
|
|
}
|
|
|
|
|
2015-05-19 21:14:44 +02:00
|
|
|
public function setDropdownMenu(PhabricatorActionListView $actions) {
|
|
|
|
Javelin::initBehavior('phui-dropdown-menu');
|
|
|
|
|
|
|
|
$this->addSigil('phui-dropdown-menu');
|
2016-06-20 20:49:11 +02:00
|
|
|
$this->setMetadata($actions->getDropdownMenuMetadata());
|
2015-05-19 21:14:44 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-06-21 02:49:38 +02:00
|
|
|
public function setDropdownMenuID($id) {
|
|
|
|
Javelin::initBehavior('phui-dropdown-menu');
|
|
|
|
|
|
|
|
$this->addSigil('phui-dropdown-menu');
|
|
|
|
$this->setMetadata(
|
|
|
|
array(
|
|
|
|
'menuID' => $id,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-13 03:23:35 +02:00
|
|
|
protected function getTagAttributes() {
|
|
|
|
|
|
|
|
require_celerity_resource('phui-button-css');
|
2017-06-01 22:30:00 +02:00
|
|
|
require_celerity_resource('phui-button-simple-css');
|
2013-06-13 03:23:35 +02:00
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
$classes[] = 'button';
|
|
|
|
|
|
|
|
if ($this->color) {
|
|
|
|
$classes[] = $this->color;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->size) {
|
|
|
|
$classes[] = $this->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->dropdown) {
|
|
|
|
$classes[] = 'dropdown';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->icon) {
|
|
|
|
$classes[] = 'has-icon';
|
|
|
|
}
|
|
|
|
|
2017-06-02 13:02:56 +02:00
|
|
|
if ($this->text !== null) {
|
2017-05-31 22:11:15 +02:00
|
|
|
$classes[] = 'has-text';
|
|
|
|
}
|
|
|
|
|
2015-06-02 23:34:04 +02:00
|
|
|
if ($this->iconFirst == false) {
|
|
|
|
$classes[] = 'icon-last';
|
|
|
|
}
|
|
|
|
|
2014-02-21 23:43:24 +01:00
|
|
|
if ($this->disabled) {
|
|
|
|
$classes[] = 'disabled';
|
|
|
|
}
|
|
|
|
|
2017-05-30 23:32:54 +02:00
|
|
|
switch ($this->getButtonType()) {
|
|
|
|
case self::BUTTONTYPE_DEFAULT:
|
|
|
|
// Nothing special for default buttons.
|
|
|
|
break;
|
|
|
|
case self::BUTTONTYPE_SIMPLE:
|
|
|
|
$classes[] = 'simple';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-26 19:09:20 +01:00
|
|
|
$sigil = null;
|
|
|
|
$meta = null;
|
|
|
|
if ($this->tooltip) {
|
|
|
|
Javelin::initBehavior('phabricator-tooltips');
|
|
|
|
require_celerity_resource('aphront-tooltip-css');
|
|
|
|
$sigil = 'has-tooltip';
|
|
|
|
$meta = array(
|
|
|
|
'tip' => $this->tooltip,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-17 21:04:28 +01:00
|
|
|
if ($this->noCSS) {
|
|
|
|
$classes = array();
|
|
|
|
}
|
|
|
|
|
2014-03-25 22:20:25 +01:00
|
|
|
return array(
|
|
|
|
'class' => $classes,
|
|
|
|
'href' => $this->href,
|
|
|
|
'name' => $this->name,
|
|
|
|
'title' => $this->title,
|
2015-03-26 19:09:20 +01:00
|
|
|
'sigil' => $sigil,
|
|
|
|
'meta' => $meta,
|
2014-03-25 22:20:25 +01:00
|
|
|
);
|
2013-06-13 03:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTagContent() {
|
|
|
|
|
|
|
|
$icon = null;
|
|
|
|
$text = $this->text;
|
|
|
|
if ($this->icon) {
|
|
|
|
$icon = $this->icon;
|
|
|
|
|
|
|
|
$subtext = null;
|
|
|
|
if ($this->subtext) {
|
|
|
|
$subtext = phutil_tag(
|
2017-05-31 22:11:15 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-button-subtext',
|
|
|
|
),
|
|
|
|
$this->subtext);
|
|
|
|
}
|
|
|
|
|
2017-06-02 13:02:56 +02:00
|
|
|
if ($this->text !== null) {
|
2017-05-31 22:11:15 +02:00
|
|
|
$text = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-button-text',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$text,
|
|
|
|
$subtext,
|
|
|
|
));
|
2013-06-13 03:23:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$caret = null;
|
2017-01-17 22:59:56 +01:00
|
|
|
if ($this->dropdown || $this->getHasCaret()) {
|
2013-06-13 03:23:35 +02:00
|
|
|
$caret = phutil_tag('span', array('class' => 'caret'), '');
|
|
|
|
}
|
|
|
|
|
2015-06-02 23:34:04 +02:00
|
|
|
if ($this->iconFirst == true) {
|
|
|
|
return array($icon, $text, $caret);
|
|
|
|
} else {
|
|
|
|
return array($text, $icon);
|
|
|
|
}
|
2013-06-13 03:23:35 +02:00
|
|
|
}
|
|
|
|
}
|