Path: blob/master/src/view/phui/PHUIObjectItemView.php
12249 views
<?php12final class PHUIObjectItemView extends AphrontTagView {34private $objectName;5private $header;6private $subhead;7private $href;8private $attributes = array();9private $icons = array();10private $barColor;11private $object;12private $effect;13private $statusIcon;14private $handleIcons = array();15private $bylines = array();16private $grippable;17private $actions = array();18private $headIcons = array();19private $disabled;20private $imageURI;21private $imageHref;22private $imageIcon;23private $titleText;24private $badge;25private $countdownNum;26private $countdownNoun;27private $sideColumn;28private $coverImage;29private $description;30private $clickable;31private $mapViews = array();32private $menu;3334private $selectableName;35private $selectableValue;36private $isSelected;37private $isForbidden;3839public function setDisabled($disabled) {40$this->disabled = $disabled;41return $this;42}4344public function getDisabled() {45return $this->disabled;46}4748public function addHeadIcon($icon) {49$this->headIcons[] = $icon;50return $this;51}5253public function setObjectName($name) {54$this->objectName = $name;55return $this;56}5758public function setGrippable($grippable) {59$this->grippable = $grippable;60return $this;61}6263public function getGrippable() {64return $this->grippable;65}6667public function setEffect($effect) {68$this->effect = $effect;69return $this;70}7172public function getEffect() {73return $this->effect;74}7576public function setObject($object) {77$this->object = $object;78return $this;79}8081public function getObject() {82return $this->object;83}8485public function setHref($href) {86$this->href = $href;87return $this;88}8990public function getHref() {91return $this->href;92}9394public function setHeader($header) {95$this->header = $header;96return $this;97}9899public function getHeader() {100return $this->header;101}102103public function setSubHead($subhead) {104$this->subhead = $subhead;105return $this;106}107108public function setBadge(PHUIBadgeMiniView $badge) {109$this->badge = $badge;110return $this;111}112113public function setCountdown($num, $noun) {114$this->countdownNum = $num;115$this->countdownNoun = $noun;116return $this;117}118119public function setTitleText($title_text) {120$this->titleText = $title_text;121return $this;122}123124public function getTitleText() {125return $this->titleText;126}127128public function addByline($byline) {129$this->bylines[] = $byline;130return $this;131}132133public function setImageURI($image_uri) {134$this->imageURI = $image_uri;135return $this;136}137138public function setImageHref($image_href) {139$this->imageHref = $image_href;140return $this;141}142143public function getImageURI() {144return $this->imageURI;145}146147public function setImageIcon($image_icon) {148if (!$image_icon instanceof PHUIIconView) {149$image_icon = id(new PHUIIconView())150->setIcon($image_icon);151}152$this->imageIcon = $image_icon;153return $this;154}155156public function getImageIcon() {157return $this->imageIcon;158}159160public function setCoverImage($image) {161$this->coverImage = $image;162return $this;163}164165public function setDescription($description) {166$this->description = $description;167return $this;168}169170public function setSelectable(171$name,172$value,173$is_selected,174$is_forbidden = false) {175176$this->selectableName = $name;177$this->selectableValue = $value;178$this->isSelected = $is_selected;179$this->isForbidden = $is_forbidden;180181return $this;182}183184public function setClickable($clickable) {185$this->clickable = $clickable;186return $this;187}188189public function getClickable() {190return $this->clickable;191}192193public function setEpoch($epoch) {194$date = phabricator_dual_datetime($epoch, $this->getUser());195$this->addIcon('none', $date);196return $this;197}198199public function addAction(PHUIListItemView $action) {200if (count($this->actions) >= 3) {201throw new Exception(pht('Limit 3 actions per item.'));202}203$this->actions[] = $action;204return $this;205}206207public function addIcon($icon, $label = null, $attributes = array()) {208$this->icons[] = array(209'icon' => $icon,210'label' => $label,211'attributes' => $attributes,212);213return $this;214}215216public function newMenuItem() {217if (!$this->menu) {218$this->menu = new FuelMenuView();219}220221return $this->menu->newItem();222}223224public function newMapView() {225$list = id(new FuelMapView())226->addClass('fuel-map-property-list');227$this->mapViews[] = $list;228return $list;229}230231/**232* This method has been deprecated, use @{method:setImageIcon} instead.233*234* @deprecated235*/236public function setIcon($icon) {237phlog(238pht('Deprecated call to setIcon(), use setImageIcon() instead.'));239240return $this->setImageIcon($icon);241}242243public function setStatusIcon($icon, $label = null) {244$this->statusIcon = array(245'icon' => $icon,246'label' => $label,247);248return $this;249}250251public function addHandleIcon(252PhabricatorObjectHandle $handle,253$label = null) {254$this->handleIcons[] = array(255'icon' => $handle,256'label' => $label,257);258return $this;259}260261public function setBarColor($bar_color) {262$this->barColor = $bar_color;263return $this;264}265266public function getBarColor() {267return $this->barColor;268}269270public function addAttribute($attribute) {271if (!empty($attribute)) {272$this->attributes[] = $attribute;273}274return $this;275}276277public function setSideColumn($column) {278$this->sideColumn = $column;279return $this;280}281282protected function getTagName() {283return 'li';284}285286protected function getTagAttributes() {287$sigils = array();288289$item_classes = array();290$item_classes[] = 'phui-oi';291292if ($this->icons) {293$item_classes[] = 'phui-oi-with-icons';294}295296if ($this->attributes) {297$item_classes[] = 'phui-oi-with-attrs';298}299300if ($this->handleIcons) {301$item_classes[] = 'phui-oi-with-handle-icons';302}303304if ($this->barColor) {305$item_classes[] = 'phui-oi-bar-color-'.$this->barColor;306} else {307$item_classes[] = 'phui-oi-no-bar';308}309310if ($this->actions) {311$n = count($this->actions);312$item_classes[] = 'phui-oi-with-actions';313$item_classes[] = 'phui-oi-with-'.$n.'-actions';314}315316if ($this->disabled) {317$item_classes[] = 'phui-oi-disabled';318} else {319$item_classes[] = 'phui-oi-enabled';320}321322switch ($this->effect) {323case 'highlighted':324$item_classes[] = 'phui-oi-highlighted';325break;326case 'selected':327$item_classes[] = 'phui-oi-selected';328break;329case 'visited':330$item_classes[] = 'phui-oi-visited';331break;332case null:333break;334default:335throw new Exception(pht('Invalid effect!'));336}337338if ($this->isForbidden) {339$item_classes[] = 'phui-oi-forbidden';340} else if ($this->isSelected) {341$item_classes[] = 'phui-oi-selected';342}343344if ($this->selectableName !== null && !$this->isForbidden) {345$item_classes[] = 'phui-oi-selectable';346$sigils[] = 'phui-oi-selectable';347348Javelin::initBehavior('phui-selectable-list');349}350351$is_grippable = $this->getGrippable();352if ($is_grippable !== null) {353$item_classes[] = 'phui-oi-has-grip';354if ($is_grippable) {355$item_classes[] = 'phui-oi-grippable';356} else {357$item_classes[] = 'phui-oi-ungrippable';358}359}360361if ($this->getImageURI()) {362$item_classes[] = 'phui-oi-with-image';363}364365if ($this->getImageIcon()) {366$item_classes[] = 'phui-oi-with-image-icon';367}368369if ($this->getClickable()) {370Javelin::initBehavior('linked-container');371372$item_classes[] = 'phui-oi-linked-container';373$sigils[] = 'linked-container';374}375376return array(377'class' => $item_classes,378'sigil' => $sigils,379);380}381382protected function getTagContent() {383$viewer = $this->getUser();384385$content_classes = array();386$content_classes[] = 'phui-oi-content';387388$header_name = array();389390if ($viewer) {391$header_name[] = id(new PHUISpacesNamespaceContextView())392->setUser($viewer)393->setObject($this->object);394}395396if ($this->objectName) {397$header_name[] = array(398javelin_tag(399'span',400array(401'class' => 'phui-oi-objname',402'sigil' => 'ungrabbable',403),404$this->objectName),405' ',406);407}408409$title_text = null;410if ($this->titleText) {411$title_text = $this->titleText;412} else if ($this->href) {413$title_text = $this->header;414}415416$header_link = phutil_tag(417$this->href ? 'a' : 'div',418array(419'href' => $this->href,420'class' => 'phui-oi-link',421'title' => $title_text,422),423$this->header);424425$description_tag = null;426if ($this->description) {427$decription_id = celerity_generate_unique_node_id();428$description_tag = id(new PHUITagView())429->setIcon('fa-ellipsis-h')430->addClass('phui-oi-description-tag')431->setType(PHUITagView::TYPE_SHADE)432->setColor(PHUITagView::COLOR_GREY)433->addSigil('jx-toggle-class')434->setSlimShady(true)435->setMetaData(array(436'map' => array(437$decription_id => 'phui-oi-description-reveal',438),439));440}441442$header = phutil_tag(443'div',444array(445'class' => 'phui-oi-name',446),447array(448$this->headIcons,449$header_name,450$header_link,451$description_tag,452));453454$icons = array();455if ($this->icons) {456$icon_list = array();457foreach ($this->icons as $spec) {458$icon = $spec['icon'];459$icon = id(new PHUIIconView())460->setIcon($icon)461->addClass('phui-oi-icon-image');462463if (isset($spec['attributes']['tip'])) {464$sigil = 'has-tooltip';465$meta = array(466'tip' => $spec['attributes']['tip'],467'align' => 'W',468);469$icon->addSigil($sigil);470$icon->setMetadata($meta);471}472473$label = phutil_tag(474'span',475array(476'class' => 'phui-oi-icon-label',477),478$spec['label']);479480$classes = array();481$classes[] = 'phui-oi-icon';482if (isset($spec['attributes']['class'])) {483$classes[] = $spec['attributes']['class'];484}485486$icon_list[] = javelin_tag(487'li',488array(489'class' => implode(' ', $classes),490),491array(492$icon,493$label,494));495}496497$icons[] = phutil_tag(498'ul',499array(500'class' => 'phui-oi-icons',501),502$icon_list);503}504505$handle_bar = null;506if ($this->handleIcons) {507$handle_bar = array();508foreach ($this->handleIcons as $handleicon) {509$handle_bar[] =510$this->renderHandleIcon($handleicon['icon'], $handleicon['label']);511}512$handle_bar = phutil_tag(513'li',514array(515'class' => 'phui-oi-handle-icons',516),517$handle_bar);518}519520$bylines = array();521if ($this->bylines) {522foreach ($this->bylines as $byline) {523$bylines[] = phutil_tag(524'div',525array(526'class' => 'phui-oi-byline',527),528$byline);529}530$bylines = phutil_tag(531'div',532array(533'class' => 'phui-oi-bylines',534),535$bylines);536}537538$subhead = null;539if ($this->subhead) {540$subhead = phutil_tag(541'div',542array(543'class' => 'phui-oi-subhead',544),545$this->subhead);546}547548if ($this->description) {549$subhead = phutil_tag(550'div',551array(552'class' => 'phui-oi-subhead phui-oi-description',553'id' => $decription_id,554),555$this->description);556}557558if ($icons) {559$icons = phutil_tag(560'div',561array(562'class' => 'phui-object-icon-pane',563),564$icons);565}566567$attrs = null;568if ($this->attributes || $handle_bar) {569$attrs = array();570$spacer = phutil_tag(571'span',572array(573'class' => 'phui-oi-attribute-spacer',574),575"\xC2\xB7");576$first = true;577foreach ($this->attributes as $attribute) {578$attrs[] = phutil_tag(579'li',580array(581'class' => 'phui-oi-attribute',582),583array(584($first ? null : $spacer),585$attribute,586));587$first = false;588}589590$attrs = phutil_tag(591'ul',592array(593'class' => 'phui-oi-attributes',594),595array(596$handle_bar,597$attrs,598));599}600601$status = null;602if ($this->statusIcon) {603$icon = $this->statusIcon;604$status = $this->renderStatusIcon($icon['icon'], $icon['label']);605}606607$grippable = null;608if ($this->getGrippable() !== null) {609$grippable = phutil_tag(610'div',611array(612'class' => 'phui-oi-grip',613),614'');615}616617$map_views = null;618if ($this->mapViews) {619$grid = id(new FuelGridView())620->addClass('fuel-grid-property-list');621622$row = $grid->newRow();623foreach ($this->mapViews as $map_view) {624$row->newCell()625->setContent($map_view);626}627628$map_views = $grid;629}630631$content = phutil_tag(632'div',633array(634'class' => implode(' ', $content_classes),635),636array(637$subhead,638$attrs,639$map_views,640$this->renderChildren(),641));642643$image = null;644if ($this->getImageURI()) {645$image = phutil_tag(646'div',647array(648'class' => 'phui-oi-image',649'style' => 'background-image: url('.$this->getImageURI().')',650),651'');652} else if ($this->getImageIcon()) {653$image = phutil_tag(654'div',655array(656'class' => 'phui-oi-image-icon',657),658$this->getImageIcon());659}660661$image_href = $this->href;662if ($image_href === null || !strlen($image_href)) {663$image_href = $this->imageHref;664}665666if ($image && $image_href !== null && strlen($image_href)) {667$image = phutil_tag(668'a',669array(670'href' => $image_href,671),672$image);673}674675/* Build a fake table */676$column0 = null;677if ($status) {678$column0 = phutil_tag(679'div',680array(681'class' => 'phui-oi-col0',682),683$status);684}685686if ($this->badge) {687$column0 = phutil_tag(688'div',689array(690'class' => 'phui-oi-col0 phui-oi-badge',691),692$this->badge);693}694695if ($this->countdownNum) {696$countdown = phutil_tag(697'div',698array(699'class' => 'phui-oi-countdown-number',700),701array(702phutil_tag_div('', $this->countdownNum),703phutil_tag_div('', $this->countdownNoun),704));705$column0 = phutil_tag(706'div',707array(708'class' => 'phui-oi-col0 phui-oi-countdown',709),710$countdown);711}712713if ($this->selectableName !== null) {714if (!$this->isForbidden) {715$checkbox = phutil_tag(716'input',717array(718'type' => 'checkbox',719'name' => $this->selectableName,720'value' => $this->selectableValue,721'checked' => ($this->isSelected ? 'checked' : null),722));723} else {724$checkbox = null;725}726727$column0 = phutil_tag(728'div',729array(730'class' => 'phui-oi-col0 phui-oi-checkbox',731),732$checkbox);733}734735$column1 = phutil_tag(736'div',737array(738'class' => 'phui-oi-col1',739),740array(741$header,742$content,743));744745$column2 = null;746if ($icons || $bylines) {747$column2 = phutil_tag(748'div',749array(750'class' => 'phui-oi-col2',751),752array(753$icons,754$bylines,755));756}757758/* Fixed width, right column container. */759$column3 = null;760if ($this->sideColumn) {761$column3 = phutil_tag(762'div',763array(764'class' => 'phui-oi-col2 phui-oi-side-column',765),766array(767$this->sideColumn,768));769}770771$table = phutil_tag(772'div',773array(774'class' => 'phui-oi-table',775),776phutil_tag_div(777'phui-oi-table-row',778array(779$column0,780$column1,781$column2,782$column3,783)));784785$box = phutil_tag(786'div',787array(788'class' => 'phui-oi-content-box',789),790array(791$grippable,792$table,793));794795$actions = array();796if ($this->actions) {797Javelin::initBehavior('phabricator-tooltips');798799foreach (array_reverse($this->actions) as $action) {800$action->setRenderNameAsTooltip(true);801$actions[] = $action;802}803$actions = phutil_tag(804'ul',805array(806'class' => 'phui-oi-actions',807),808$actions);809}810811$frame_content = phutil_tag(812'div',813array(814'class' => 'phui-oi-frame-content',815),816array(817$actions,818$image,819$box,820));821822if ($this->menu) {823$grid_view = id(new FuelGridView())824->addClass('fuel-grid-tablet');825$grid_row = $grid_view->newRow();826827$grid_row->newCell()828->setContent($frame_content);829830$menu = $this->menu;831832$grid_row->newCell()833->addClass('phui-oi-menu')834->setContent($menu);835836$frame_content = $grid_view;837}838839$frame_cover = null;840if ($this->coverImage) {841$cover_image = phutil_tag(842'img',843array(844'src' => $this->coverImage,845'class' => 'phui-oi-cover-image',846));847848$frame_cover = phutil_tag(849'div',850array(851'class' => 'phui-oi-frame-cover',852),853$cover_image);854}855856$frame = phutil_tag(857'div',858array(859'class' => 'phui-oi-frame',860),861array(862$frame_cover,863$frame_content,864));865866return $frame;867}868869private function renderStatusIcon($icon, $label) {870Javelin::initBehavior('phabricator-tooltips');871872$icon = id(new PHUIIconView())873->setIcon($icon);874875$options = array(876'class' => 'phui-oi-status-icon',877);878879if ($label !== null && strlen($label)) {880$options['sigil'] = 'has-tooltip';881$options['meta'] = array('tip' => $label, 'size' => 300);882}883884return javelin_tag('div', $options, $icon);885}886887888private function renderHandleIcon(PhabricatorObjectHandle $handle, $label) {889Javelin::initBehavior('phabricator-tooltips');890891$options = array(892'class' => 'phui-oi-handle-icon',893'style' => 'background-image: url('.$handle->getImageURI().')',894);895896if (strlen($label)) {897$options['sigil'] = 'has-tooltip';898$options['meta'] = array('tip' => $label, 'align' => 'E');899}900901return javelin_tag('span', $options, '');902}903904}905906907