2012-08-15 19:45:06 +02:00
|
|
|
<?php
|
|
|
|
|
2013-09-09 23:14:34 +02:00
|
|
|
final class PHUIObjectItemListView extends AphrontTagView {
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
private $header;
|
|
|
|
private $items;
|
|
|
|
private $pager;
|
2012-09-11 18:55:27 +02:00
|
|
|
private $noDataString;
|
2013-03-23 22:38:01 +01:00
|
|
|
private $flush;
|
2014-01-13 21:24:13 +01:00
|
|
|
private $allowEmptyList;
|
2014-04-29 19:14:18 +02:00
|
|
|
private $states;
|
2014-01-13 21:24:13 +01:00
|
|
|
|
|
|
|
public function setAllowEmptyList($allow_empty_list) {
|
|
|
|
$this->allowEmptyList = $allow_empty_list;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllowEmptyList() {
|
|
|
|
return $this->allowEmptyList;
|
|
|
|
}
|
2013-03-23 22:38:01 +01:00
|
|
|
|
|
|
|
public function setFlush($flush) {
|
|
|
|
$this->flush = $flush;
|
|
|
|
return $this;
|
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
public function setHeader($header) {
|
|
|
|
$this->header = $header;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPager($pager) {
|
|
|
|
$this->pager = $pager;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-09-11 18:55:27 +02:00
|
|
|
public function setNoDataString($no_data_string) {
|
|
|
|
$this->noDataString = $no_data_string;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-09 23:14:34 +02:00
|
|
|
public function addItem(PHUIObjectItemView $item) {
|
2012-08-15 19:45:06 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-29 19:14:18 +02:00
|
|
|
public function setStates($states) {
|
|
|
|
$this->states = $states;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-02 18:39:44 +02:00
|
|
|
protected function getTagName() {
|
|
|
|
return 'ul';
|
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
|
2013-06-02 18:39:44 +02:00
|
|
|
protected function getTagAttributes() {
|
2013-01-25 06:00:47 +01:00
|
|
|
$classes = array();
|
2013-06-02 18:39:44 +02:00
|
|
|
|
2013-09-09 23:14:34 +02:00
|
|
|
$classes[] = 'phui-object-item-list-view';
|
2014-04-29 19:14:18 +02:00
|
|
|
if ($this->states) {
|
|
|
|
$classes[] = 'phui-object-list-states';
|
|
|
|
}
|
2013-06-02 18:39:44 +02:00
|
|
|
if ($this->flush) {
|
2013-09-09 23:14:34 +02:00
|
|
|
$classes[] = 'phui-object-list-flush';
|
|
|
|
}
|
2013-06-02 18:39:44 +02:00
|
|
|
|
|
|
|
return array(
|
|
|
|
'class' => $classes,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTagContent() {
|
2013-09-09 23:14:34 +02:00
|
|
|
require_celerity_resource('phui-object-item-list-view-css');
|
2013-06-02 18:39:44 +02:00
|
|
|
|
2012-12-13 19:59:29 +01:00
|
|
|
$header = null;
|
|
|
|
if (strlen($this->header)) {
|
2013-01-18 03:43:35 +01:00
|
|
|
$header = phutil_tag(
|
2012-12-13 19:59:29 +01:00
|
|
|
'h1',
|
|
|
|
array(
|
2013-09-09 23:14:34 +02:00
|
|
|
'class' => 'phui-object-item-list-header',
|
2012-12-13 19:59:29 +01:00
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$this->header);
|
2012-12-13 19:59:29 +01:00
|
|
|
}
|
2012-09-11 18:55:27 +02:00
|
|
|
|
|
|
|
if ($this->items) {
|
2013-03-09 22:52:41 +01:00
|
|
|
$items = $this->items;
|
2014-01-13 21:24:13 +01:00
|
|
|
} else if ($this->allowEmptyList) {
|
|
|
|
$items = null;
|
2012-09-11 18:55:27 +02:00
|
|
|
} else {
|
|
|
|
$string = nonempty($this->noDataString, pht('No data.'));
|
2015-03-01 23:45:56 +01:00
|
|
|
$string = id(new PHUIInfoView())
|
|
|
|
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
|
2013-02-07 01:53:49 +01:00
|
|
|
->appendChild($string);
|
2014-02-28 20:16:11 +01:00
|
|
|
$items = phutil_tag(
|
|
|
|
'li',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-object-item-empty',
|
|
|
|
),
|
2014-02-28 20:16:11 +01:00
|
|
|
$string);
|
|
|
|
|
2012-09-11 18:55:27 +02:00
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
$pager = null;
|
|
|
|
if ($this->pager) {
|
2013-03-09 22:52:41 +01:00
|
|
|
$pager = $this->pager;
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
2013-06-02 18:39:44 +02:00
|
|
|
return array(
|
|
|
|
$header,
|
|
|
|
$items,
|
|
|
|
$pager,
|
|
|
|
$this->renderChildren(),
|
|
|
|
);
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|