Skip to content

Commit 0dc2da4

Browse files
committed
fix ajax list view
1 parent 8a031d6 commit 0dc2da4

6 files changed

Lines changed: 88 additions & 40 deletions

File tree

Resources/config/cms/sonata_admin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ sonata_admin:
2727
delete: NetworkingInitCmsBundle:CRUD:delete.html.twig
2828
action: NetworkingInitCmsBundle:CRUD:action.html.twig
2929
dashboard: NetworkingInitCmsBundle:Core:dashboard.html.twig
30+
select: NetworkingInitCmsBundle:CRUD:list__select.html.twig
3031
batch_confirmation: NetworkingInitCmsBundle:CRUD:batch_confirmation.html.twig
3132
base_list_field: NetworkingInitCmsBundle:CRUD:base_list_field.html.twig
33+
inner_list_row: NetworkingInitCmsBundle:CRUD:list_inner_row.html.twig
3234
# default values of helper templates
3335
short_object_description: NetworkingInitCmsBundle:Helper:short-object-description.html.twig
3436
# default values of block templates, they should extend the base_block template

Resources/views/CRUD/base_list.html.twig

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ file that was distributed with this source code.
1818
{% block side_menu %}{{ knp_menu_render(admin.sidemenu(action), {'currentClass' : 'active'}, 'list') }}{% endblock %}
1919

2020
{% block list_filters %}
21-
{% if admin.datagrid.filters and not app.request.isxmlhttprequest %}
21+
{% if admin.datagrid.filters %}
2222

2323
<form action="{{ admin.generateUrl('list') }}" method="GET"
2424
class="sonata-filter-form {{ admin.isChild and 1 == admin.datagrid.filters|length ? 'hide' : '' }}form-horizontal filters">
@@ -118,10 +118,17 @@ file that was distributed with this source code.
118118
<thead>
119119
<tr>
120120
{% for field_description in admin.list.elements %}
121-
{% if field_description.getOption('code') == '_batch' and batchactions|length > 0 %}
122-
<th class="sonata-ba-list-field-header sonata-ba-list-field-header-batch">
123-
{#<input type="checkbox" id="list_batch_checkbox"/>#}
124-
</th>
121+
{% if admin.hasRoute('batch') and field_description.getOption('code') == '_batch' and batchactions|length > 0 %}
122+
{% if not app.request.isXmlHttpRequest %}
123+
<th class="sonata-ba-list-field-header sonata-ba-list-field-header-batch">
124+
</th>
125+
{% endif %}
126+
{% elseif field_description.getOption('code') == '_select' %}
127+
<th class="sonata-ba-list-field-header sonata-ba-list-field-header-select"></th>
128+
{% elseif field_description.name == '_action' and app.request.isXmlHttpRequest %}
129+
{# Action buttons disabled in ajax view! #}
130+
{% elseif field_description.getOption('ajax_hidden') == true and app.request.isXmlHttpRequest %}
131+
{# Disable fields with 'ajax_hidden' option set to true #}
125132
{% else %}
126133
{% set sortable = false %}
127134
{% if field_description.options.sortable is defined and field_description.options.sortable %}
@@ -150,12 +157,10 @@ file that was distributed with this source code.
150157
<tbody>
151158
{% for object in admin.datagrid.results %}
152159
<tr>
153-
{% for field_description in admin.list.elements %}
154-
{{ object|render_list_element(field_description) }}
155-
{% endfor %}
160+
{% include admin.getTemplate('inner_list_row') %}
156161
</tr>
157162
{% endfor %}
158-
{% if batchactions|length > 0 %}
163+
{% if batchactions|length > 0 and not app.request.isxmlhttprequest %}
159164
<tr>
160165
<td>
161166
<input type="checkbox" id="list_batch_checkbox" name="all_elements"/>
@@ -171,28 +176,28 @@ file that was distributed with this source code.
171176
{% block table_footer %}
172177
<tfoot>
173178
<tr>
174-
<th colspan="{{ admin.list.elements|length - 2 }}">
175-
{{ block('batch') }}
176-
</th>
177-
178-
<th class="align-right form-inline" colspan="2">
179-
<label class="control-label"><strong>{% transchoice datagrid.pager.nbresults with {'%count%': datagrid.pager.nbresults} from 'SonataAdminBundle' %}
180-
list_results_count{% endtranschoice %}</strong></label>
181-
{% block max_per_page %}
182-
<label class="control-label"
183-
for="{{ admin.uniqid }}_per_page">{% trans from 'SonataAdminBundle' %}
184-
label_per_page{% endtrans %}
185-
<select class="per-page small" id="{{ admin.uniqid }}_per_page"
186-
style="width: auto; height: auto">
187-
{% for per_page in admin.getperpageoptions %}
188-
<option {% if per_page ==datagrid.pager.maxperpage %}selected="selected"{% endif %}
189-
value="{{ admin.generateUrl('list', {'filter':datagrid.values|merge({'_per_page': per_page})}) }}">
190-
{{ per_page }}
191-
</option>
192-
{% endfor %}
193-
</select>
194-
</label>
195-
{% endblock %}
179+
<th colspan="{{ admin.list.elements|length - (app.request.isXmlHttpRequest ? (admin.list.has('_action') + admin.list.has('batch')) : 0) }}">
180+
<div class="form-inline">
181+
{% if not app.request.isxmlhttprequest %}{{ block('batch') }}{% endif %}
182+
<div class="pull-right">
183+
<label class="control-label"><strong>{% transchoice datagrid.pager.nbresults with {'%count%': datagrid.pager.nbresults} from 'SonataAdminBundle' %}
184+
list_results_count{% endtranschoice %}</strong></label>
185+
{% block max_per_page %}
186+
<label class="control-label"
187+
for="{{ admin.uniqid }}_per_page">{% trans from 'SonataAdminBundle' %}
188+
label_per_page{% endtrans %}</label>
189+
<select class="per-page small" id="{{ admin.uniqid }}_per_page"
190+
style="width: auto; height: auto">
191+
{% for per_page in admin.getperpageoptions %}
192+
<option {% if per_page ==datagrid.pager.maxperpage %}selected="selected"{% endif %}
193+
value="{{ admin.generateUrl('list', {'filter':datagrid.values|merge({'_per_page': per_page})}) }}">
194+
{{ per_page }}
195+
</option>
196+
{% endfor %}
197+
</select>
198+
{% endblock %}
199+
</div>
200+
</div>
196201
</th>
197202
</tr>
198203
</tfoot>
@@ -252,14 +257,16 @@ file that was distributed with this source code.
252257

253258
</div>
254259
{% endif %}
255-
{% if admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
256-
<p> {{ "label_export_download"|trans({}, "NetworkingInitCmsBundle") }}:
257-
{% for format in admin.getExportFormats() %}
258-
<a
259-
href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}"
260-
class="link-underlined">{{ format }}</a>{% if not loop.last %},{% endif %}
261-
{% endfor %}
262-
</p>
260+
{% if not app.request.isxmlhttprequest %}
261+
{% if admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
262+
<p> {{ "label_export_download"|trans({}, "NetworkingInitCmsBundle") }}:
263+
{% for format in admin.getExportFormats() %}
264+
<a
265+
href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}"
266+
class="link-underlined">{{ format }}</a>{% if not loop.last %},{% endif %}
267+
{% endfor %}
268+
</p>
269+
{% endif %}
263270
{% endif %}
264271

265272
{% if admin.hasRoute('batch') %}
@@ -271,8 +278,14 @@ file that was distributed with this source code.
271278
</p>
272279
{% endif %}
273280

274-
{% if not app.request.isxmlhttprequest %}
281+
{% if not app.request.isXmlHttpRequest %}
275282
</div>
283+
{% else %}
284+
<script type="text/javascript">
285+
$(function () {
286+
Admin.add_filters();
287+
});
288+
</script>
276289
{% endif %}
277290
{% endblock %}
278291

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% if admin.list.has('batch') and not app.request.isXmlHttpRequest %}
2+
<td class="sonata-ba-list-field sonata-ba-list-field-batch">
3+
{{ object|render_list_element(admin.list['batch']) }}
4+
</td>
5+
{% endif %}
6+
7+
<td class="sonata-ba-list-field sonata-ba-list-field-inline-fields" colspan="{{ admin.list.elements|length - (admin.list.has('_action') + admin.list.has('batch')) }}" objectId="{{ admin.id(object) }}">
8+
{% block row %}{% endblock %}
9+
</td>
10+
11+
{% if admin.list.has('_action') and not app.request.isXmlHttpRequest %}
12+
<td class="sonata-ba-list-field sonata-ba-list-field-_action" objectId="{{ admin.id(object) }}">
13+
{{ object|render_list_element(admin.list['_action']) }}
14+
</td>
15+
{% endif %}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% for field_description in admin.list.elements %}
2+
{% if (field_description.name == '_action' or field_description.name == 'batch') and app.request.isXmlHttpRequest %}
3+
{# Action buttons disabled in ajax view! #}
4+
{% elseif field_description.getOption('ajax_hidden') == true and app.request.isXmlHttpRequest %}
5+
{# Disable fields with 'ajax_hidden' option set to true #}
6+
{% else %}
7+
{{ object|render_list_element(field_description) }}
8+
{% endif %}
9+
{% endfor %}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends admin.getTemplate('base_list_field') %}
2+
3+
{% block field %}
4+
<a class="btn btn-default btn-sm select-media pull-right" href="#" data-object-id="{{ object.id }}">
5+
<i class="glyphicon glyphicon-arrow-right"></i>
6+
{{ 'list_select'|trans({}, 'SonataAdminBundle') }}
7+
</a>
8+
{% endblock %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends 'NetworkingInitCmsBundle:CRUD:base_list_inner_row.html.twig' %}

0 commit comments

Comments
 (0)