Control whether a filter editor should be rendered via setVisible()

We (may) have situations where a controller or view has to access the filter editor being created via Controller::setupFilterControl().
This is impossible if the view is compact because the filterEditor will be unset. This change introduces FilterEditor::setVisible() for
giving the responsibility of rendering to the filter editor. Controller::setupFilterControl() will be adapted accordingly.

refs #10778
This commit is contained in:
Eric Lippmann 2016-02-27 15:51:13 +01:00
parent c5aab53745
commit d8b14cb772
1 changed files with 34 additions and 0 deletions

View File

@ -55,6 +55,13 @@ class FilterEditor extends AbstractWidget
*/ */
private $selectedIdx; private $selectedIdx;
/**
* Whether the filter control is visible
*
* @var bool
*/
protected $visible = true;
/** /**
* Create a new FilterWidget * Create a new FilterWidget
* *
@ -144,6 +151,30 @@ class FilterEditor extends AbstractWidget
return $this; return $this;
} }
/**
* Get whether the filter control is visible
*
* @return bool
*/
public function isVisible()
{
return $this->visible;
}
/**
* Set whether the filter control is visible
*
* @param bool $visible
*
* @return $this
*/
public function setVisible($visible)
{
$this->visible = (bool) $visible;
return $this;
}
protected function redirectNow($url) protected function redirectNow($url)
{ {
$response = Icinga::app()->getFrontController()->getResponse(); $response = Icinga::app()->getFrontController()->getResponse();
@ -731,6 +762,9 @@ class FilterEditor extends AbstractWidget
public function render() public function render()
{ {
if (! $this->visible) {
return '';
}
if (! $this->preservedUrl()->getParam('modifyFilter')) { if (! $this->preservedUrl()->getParam('modifyFilter')) {
return '<div class="filter">' . $this->renderSearch() . $this->view()->escape($this->shorten($this->filter, 50)) . '</div>'; return '<div class="filter">' . $this->renderSearch() . $this->view()->escape($this->shorten($this->filter, 50)) . '</div>';
} }