Skip to content

Commit

Permalink
added highlighting of activate filters, filter drawer stays open upon…
Browse files Browse the repository at this point in the history
… activate filters
  • Loading branch information
benoitpointet committed Feb 22, 2012
1 parent c30c984 commit 6103ac6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
26 changes: 25 additions & 1 deletion Datagrid/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ public function setValue($name, $operator, $value)
$this->values[$name] = array('type' => $operator, 'value' => $value);
}

/**
* @return boolean
*/
public function hasActiveFilters()
{
foreach ($this->filters as $name => $filter) {
if ($this->hasActiveFilter($name)) {
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 All @@ -202,4 +226,4 @@ public function getForm()

return $this->form;
}
}
}
15 changes: 14 additions & 1 deletion Datagrid/DatagridInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,17 @@ function hasFilter($name);
* @param $name
*/
function removeFilter($name);
}

/**
* @abstract
* @return boolean
*/
public function hasActiveFilters();

/**
* @abstract
* @param $name
* @return bool
*/
public function hasActiveFilter($name);
}
2 changes: 1 addition & 1 deletion Resources/public/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var Admin = {
},

add_filters: function(subject) {
jQuery('div.filter_container', subject).hide();
jQuery('div.filter_container.inactive', subject).hide();
jQuery('fieldset.filter_legend', subject).click(function(event) {
jQuery('div.filter_container', jQuery(event.target).parent()).toggle();
});
Expand Down
7 changes: 7 additions & 0 deletions Resources/public/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ body.sonata-bc {
padding-left: 0;
}


.sonata-bc legend.filter_legend.active,
.sonata-bc tr.filter.active * {
font-weight: bold;
color: #000;
}

.sonata-bc table.sonata-ba-list td {
width: 75px;
}
Expand Down
6 changes: 3 additions & 3 deletions Resources/views/CRUD/base_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ file that was distributed with this source code.
{% if admin.datagrid.filters %}
<form class="sonata-filter-form form-stacked {{ admin.isChild and 1 == admin.datagrid.filters|length ? 'hide' : '' }}" action="{{ admin.generateUrl('list') }}" method="GET">
<fieldset class="filter_legend">
<legend class="filter_legend">{% trans from 'SonataAdminBundle' %}label_filters{% endtrans %}</legend>
<legend class="filter_legend {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">{% trans from 'SonataAdminBundle' %}label_filters{% endtrans %}</legend>

<div class="filter_container">
<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">
<tr id="filter_{{ filter.name }}_row" class="filter {{ admin.datagrid.hasActiveFilter(filter.name) ? '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 6103ac6

Please sign in to comment.