2012-05-01 19:15:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialResultsTableView extends AphrontView {
|
|
|
|
|
|
|
|
private $rows;
|
|
|
|
private $showMoreString;
|
|
|
|
|
|
|
|
public function setRows(array $rows) {
|
|
|
|
$this->rows = $rows;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setShowMoreString($show_more_string) {
|
|
|
|
$this->showMoreString = $show_more_string;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
$any_hidden = false;
|
|
|
|
foreach ($this->rows as $row) {
|
|
|
|
|
|
|
|
$style = idx($row, 'style');
|
|
|
|
switch ($style) {
|
|
|
|
case 'section':
|
2013-01-29 03:46:04 +01:00
|
|
|
$cells = phutil_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'th',
|
|
|
|
array(
|
|
|
|
'colspan' => 2,
|
|
|
|
),
|
|
|
|
idx($row, 'name'));
|
|
|
|
break;
|
|
|
|
default:
|
2013-01-29 03:46:04 +01:00
|
|
|
$name = phutil_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'th',
|
|
|
|
array(
|
|
|
|
),
|
|
|
|
idx($row, 'name'));
|
2013-01-29 03:46:04 +01:00
|
|
|
$value = phutil_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'td',
|
|
|
|
array(
|
|
|
|
),
|
|
|
|
idx($row, 'value'));
|
2013-01-29 03:46:04 +01:00
|
|
|
$cells = array($name, $value);
|
2012-05-01 19:15:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$show = idx($row, 'show');
|
|
|
|
|
2013-01-29 03:46:04 +01:00
|
|
|
$rows[] = javelin_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'tr',
|
|
|
|
array(
|
|
|
|
'style' => $show ? null : 'display: none',
|
|
|
|
'sigil' => $show ? null : 'differential-results-row-toggle',
|
|
|
|
'class' => 'differential-results-row-'.$style,
|
|
|
|
),
|
|
|
|
$cells);
|
|
|
|
|
|
|
|
if (!$show) {
|
|
|
|
$any_hidden = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($any_hidden) {
|
2013-01-29 03:46:04 +01:00
|
|
|
$show_more = javelin_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
),
|
|
|
|
$this->showMoreString);
|
|
|
|
|
2013-01-29 03:46:04 +01:00
|
|
|
$hide_more = javelin_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
),
|
|
|
|
'Hide');
|
|
|
|
|
2013-01-29 03:46:04 +01:00
|
|
|
$rows[] = javelin_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'tr',
|
|
|
|
array(
|
|
|
|
'class' => 'differential-results-row-show',
|
|
|
|
'sigil' => 'differential-results-row-show',
|
|
|
|
),
|
2013-01-29 03:46:04 +01:00
|
|
|
phutil_tag('th', array('colspan' => 2), $show_more));
|
2012-05-01 19:15:56 +02:00
|
|
|
|
2013-01-29 03:46:04 +01:00
|
|
|
$rows[] = javelin_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'tr',
|
|
|
|
array(
|
|
|
|
'class' => 'differential-results-row-show',
|
|
|
|
'sigil' => 'differential-results-row-hide',
|
|
|
|
'style' => 'display: none',
|
|
|
|
),
|
2013-01-29 03:46:04 +01:00
|
|
|
phutil_tag('th', array('colspan' => 2), $hide_more));
|
2012-05-01 19:15:56 +02:00
|
|
|
|
|
|
|
Javelin::initBehavior('differential-show-field-details');
|
|
|
|
}
|
|
|
|
|
|
|
|
require_celerity_resource('differential-results-table-css');
|
|
|
|
|
2013-01-29 20:01:47 +01:00
|
|
|
return javelin_tag(
|
2012-05-01 19:15:56 +02:00
|
|
|
'table',
|
|
|
|
array(
|
|
|
|
'class' => 'differential-results-table',
|
|
|
|
'sigil' => 'differential-results-table',
|
|
|
|
),
|
2013-01-29 20:01:47 +01:00
|
|
|
$rows);
|
2012-05-01 19:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|