Skip to content

Commit

Permalink
let filter decide wether it is active or not
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitpointet committed Feb 28, 2012
1 parent 6834d7f commit d42c0c2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
12 changes: 1 addition & 11 deletions Datagrid/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,14 @@ public function setValue($name, $operator, $value)
public function hasActiveFilters()
{
foreach ($this->filters as $name => $filter) {
if ($this->hasActiveFilter($name)) {
if ($filter->isActive()) {
return true;
}
}

return false;
}

/**
* @param $name
* @return bool
*/
public function hasActiveFilter($name)
{
return isset($this->values[$name])
&& ! empty($this->values[$name]['value']);
}

/**
* @return \Sonata\AdminBundle\Admin\FieldDescriptionCollection
*/
Expand Down
7 changes: 0 additions & 7 deletions Datagrid/DatagridInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,4 @@ function removeFilter($name);
* @return boolean
*/
public function hasActiveFilters();

/**
* @abstract
* @param $name
* @return bool
*/
public function hasActiveFilter($name);
}
11 changes: 10 additions & 1 deletion Filter/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ public function getValue()
return $this->value;
}

/**
* @return string
*/
public function isActive()
{
$values = $this->getValue();
return ! empty($values['value']);
}

/**
* @param $condition
* @return void
Expand All @@ -164,4 +173,4 @@ public function getCondition()
{
return $this->condition;
}
}
}
2 changes: 1 addition & 1 deletion Resources/views/CRUD/base_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ file that was distributed with this source code.
<div class="filter_container {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">
<table class="bordered-table">
{% for filter in admin.datagrid.filters %}
<tr id="filter_{{ filter.name }}_row" class="filter {{ admin.datagrid.hasActiveFilter(filter.name) ? 'active' : 'inactive' }}">
<tr id="filter_{{ filter.name }}_row" class="filter {{ filter.isActive ? 'active' : 'inactive' }}">
<td class="filter-title">{{ admin.trans(filter.label) }}</td>
<td class="filter-type">{{ form_widget(form.getChild(filter.name).getChild('type')) }}</td>
<td class="filter-value">{{ form_widget(form.getChild(filter.name).getChild('value')) }}</td>
Expand Down

0 comments on commit d42c0c2

Please sign in to comment.