QuickTable: introduce getActionUrl
* removed getActionUrls * introduced optional exta actions * no longer showing actions table per default
This commit is contained in:
parent
01b44eb14c
commit
6d3bdc10fc
|
@ -16,9 +16,9 @@ class ActivityLogTable extends QuickTable
|
|||
);
|
||||
}
|
||||
|
||||
protected function getActionLinks($id)
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->view()->qlink('Show', 'director/show/activitylog', array('id' => $id));
|
||||
return $this->url('director/show/activitylog', array('id' => $row->id));
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
|
|
|
@ -16,9 +16,9 @@ class IcingaCommandTable extends QuickTable
|
|||
);
|
||||
}
|
||||
|
||||
protected function getActionLinks($id)
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->view()->qlink('Edit', 'director/object/command', array('id' => $id));
|
||||
return $this->url('director/object/command', array('id' => $row->id));
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
|
|
|
@ -16,9 +16,9 @@ class IcingaHostTable extends QuickTable
|
|||
);
|
||||
}
|
||||
|
||||
protected function getActionLinks($id)
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->view()->qlink('Edit', 'director/object/host', array('id' => $id));
|
||||
return $this->url('director/object/host', array('id' => $row->id));
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
|
|
|
@ -14,9 +14,9 @@ class IcingaZoneTable extends QuickTable
|
|||
);
|
||||
}
|
||||
|
||||
protected function getActionLinks($id)
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->view()->qlink('Edit', 'director/object/zone', array('id' => $id));
|
||||
return $this->url('director/object/zone', array('id' => $row->id));
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
|
|
|
@ -13,26 +13,53 @@ abstract class QuickTable
|
|||
|
||||
protected $connection;
|
||||
|
||||
protected function renderRow($row)
|
||||
protected function renderRow($row, $actionColumn = false)
|
||||
{
|
||||
$htm = " <tr>\n";
|
||||
$idKey = key($row);
|
||||
$id = $row->$idKey;
|
||||
unset($row->$idKey);
|
||||
$firstRow = true;
|
||||
|
||||
foreach ($row as $key => $val) {
|
||||
$htm .= ' <td>' . ($val === null ? '-' : $this->view()->escape($val)) . "</td>\n";
|
||||
$value = null;
|
||||
if ($key === $idKey) continue;
|
||||
|
||||
if ($firstRow) {
|
||||
if ($val !== null && $url = $this->getActionUrl($row)) {
|
||||
$value = $this->view()->qlink($val, $this->getActionUrl($row));
|
||||
}
|
||||
$firstRow = false;
|
||||
}
|
||||
|
||||
if ($value === null) {
|
||||
$value = $val === null ? '-' : $this->view()->escape($val);
|
||||
}
|
||||
|
||||
$htm .= ' <td>' . $value . "</td>\n";
|
||||
}
|
||||
$htm .= ' <td class="actions">' . $this->getActionLinks($id) . "</td>\n";
|
||||
|
||||
if ($this->hasAdditionalActions()) {
|
||||
$htm .= ' <td class="actions">' . $this->renderAdditionalActions($row) . "</td>\n";
|
||||
}
|
||||
|
||||
return $htm . " </tr>\n";
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setConnection(Selectable $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasAdditionalActions()
|
||||
{
|
||||
return method_exists($this, 'renderAdditionalActions');
|
||||
}
|
||||
|
||||
protected function connection()
|
||||
{
|
||||
// TODO: Fail if missing? Require connection in constructor?
|
||||
|
@ -43,13 +70,23 @@ abstract class QuickTable
|
|||
{
|
||||
$view = $this->view;
|
||||
$htm = "<thead>\n <tr>\n";
|
||||
|
||||
foreach ($row as $title) {
|
||||
$htm .= ' <th>' . $view->escape($title) . "</th>\n";
|
||||
}
|
||||
$htm .= ' <th class="actions">' . $view->translate('Actions') . "</th>\n";
|
||||
|
||||
if ($this->hasAdditionalActions()) {
|
||||
$htm .= ' <th class="actions">' . $view->translate('Actions') . "</th>\n";
|
||||
}
|
||||
|
||||
return $htm . " </tr>\n</thead>\n";
|
||||
}
|
||||
|
||||
protected function url($url, $params)
|
||||
{
|
||||
return Url::fromPath($url, $params);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$data = $this->fetchData();
|
||||
|
|
Loading…
Reference in New Issue