Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
Conflicts:
	Resources/views/CRUD/base_list.html.twig
  • Loading branch information
rande committed Mar 27, 2013
2 parents 0b60fa5 + 3d8818d commit 5594a79
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 60 deletions.
5 changes: 4 additions & 1 deletion Admin/FieldDescriptionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ public function count()
*/
public function reorder(array $keys)
{
array_unshift($keys, 'batch');
if ($this->has('batch')) {
array_unshift($keys, 'batch');
}

$this->elements = array_merge(array_flip($keys), $this->elements);
}
}
8 changes: 4 additions & 4 deletions Resources/doc/reference/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Obtaining an ``Admin`` Service
------------------------------

``Admin`` definitions are accessible through the ``sonata.admin.pool`` service or
directly from the DIC (dependency injection container). The ``Admin`` definitions
directly from the DIC (dependency injection container). The ``Admin`` definitions
are lazy-loaded from the DIC to reduce overhead.

Declaring a new Admin class
Expand Down Expand Up @@ -154,8 +154,8 @@ Or if you're using a YML configuration file,
You can extend ``Sonata\AdminBundle\Admin\Admin`` class to minimize the amount of
code to write. This base admin class uses the routing services to build routes.
Note that you can use both the Bundle:Controller format or a `service name`_ to
specify what controller to load.

specify what controller to load. If you provide null instead of SonataNewsBundle:PostAdmin,
you will not need to create a controller class and the system will use the default.

.. _`Django Project Website`: http://www.djangoproject.com/
.. _`service name`: http://symfony.com/doc/2.0/cookbook/controller/service.html
.. _`service name`: http://symfony.com/doc/2.1/cookbook/controller/service.html
2 changes: 1 addition & 1 deletion Resources/translations/SonataAdminBundle.de.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
</trans-unit>
<trans-unit id="message_delete_confirmation">
<source>message_delete_confirmation</source>
<target>Sind Sie sicher dass Sie das ausgewählte Element löschen wollen?</target>
<target>Sind Sie sicher, dass Sie das ausgewählte Element löschen wollen?</target>
</trans-unit>
<trans-unit id="btn_delete">
<source>btn_delete</source>
Expand Down
5 changes: 4 additions & 1 deletion Resources/views/CRUD/base_edit_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
{% endif %}
{% if admin.id(object) %}
<input type="submit" class="btn btn-primary" name="btn_update_and_edit" value="{{ 'btn_update_and_edit_again'|trans({}, 'SonataAdminBundle') }}"/>
<input type="submit" class="btn" name="btn_update_and_list" value="{{ 'btn_update_and_return_to_list'|trans({}, 'SonataAdminBundle') }}"/>

{% if admin.hasroute('list') %}
<input type="submit" class="btn" name="btn_update_and_list" value="{{ 'btn_update_and_return_to_list'|trans({}, 'SonataAdminBundle') }}"/>
{% endif %}

{% if admin.hasroute('delete') and admin.isGranted('DELETE', object) %}
{{ 'delete_or'|trans({}, 'SonataAdminBundle') }}
Expand Down
105 changes: 53 additions & 52 deletions Resources/views/CRUD/base_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -77,64 +77,65 @@ file that was distributed with this source code.
<tr>
<th colspan="{{ admin.list.elements|length - (app.request.isXmlHttpRequest ? 2 : 0) }}">
<div class="form-inline">
{% if not app.request.isXmlHttpRequest and batchactions|length > 0 %}
{% block batch %}
<script type="text/javascript">
{% block batch_javascript %}
jQuery(document).ready(function ($) {
$('#list_batch_checkbox').click(function () {
$(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked')).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
});
$("td.sonata-ba-list-field-batch input[type='checkbox']").change(function () {
$(this).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
});
});
{% endblock %}
</script>

{% block batch_actions %}
<label class="checkbox" for="{{ admin.uniqid }}_all_elements">
<input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements"/>
{{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
</label>

<select name="action" style="width: auto; height: auto">
{% for action, options in batchactions %}
<option value="{{ action }}">{{ options.label }}</option>
{% endfor %}
</select>

<input type="submit" class="btn btn-small btn-primary" value="{{ 'btn_batch'|trans({}, 'SonataAdminBundle') }}"/>
<div class="pull-right">
{% if admin.hasRoute('export') and admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
{{ "label_export_download"|trans({}, "SonataAdminBundle") }}
{% for format in admin.getExportFormats() %}
<a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last %},{% endif %}
{% if not app.request.isXmlHttpRequest %}
{% if batchactions|length > 0 %}
{% block batch %}
<script type="text/javascript">
{% block batch_javascript %}
jQuery(document).ready(function ($) {
$('#list_batch_checkbox').click(function () {
$(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked')).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
});
$("td.sonata-ba-list-field-batch input[type='checkbox']").change(function () {
$(this).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
});
});
{% endblock %}
</script>

{% block batch_actions %}
<label class="checkbox" for="{{ admin.uniqid }}_all_elements">
<input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements"/>
{{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
</label>

<select name="action" style="width: auto; height: auto">
{% for action, options in batchactions %}
<option value="{{ action }}">{{ options.label }}</option>
{% endfor %}
</select>
{% endblock %}
{% endblock %}

<input type="submit" class="btn btn-small btn-primary" value="{{ 'btn_batch'|trans({}, 'SonataAdminBundle') }}"/>
{% endif %}

<div class="pull-right">
{% if admin.hasRoute('export') and admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
{{ "label_export_download"|trans({}, "SonataAdminBundle") }}
{% for format in admin.getExportFormats() %}
<a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last %},{% endif %}
{% endfor %}

&nbsp;-&nbsp;
{% endif %}
&nbsp;-&nbsp;
{% endif %}

{{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
{{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}

&nbsp;-&nbsp;
&nbsp;-&nbsp;

{% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}
{% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}

{% if not app.request.isXmlHttpRequest %}
&nbsp;-&nbsp;
<label class="control-label" for="{{ admin.uniqid }}_per_page">{% trans from 'SonataAdminBundle' %}label_per_page{% endtrans %}</label>
<select class="per-page small" id="{{ admin.uniqid }}_per_page" style="width: auto; height: auto">
{% for per_page in admin.getperpageoptions %}
<option {% if per_page == admin.datagrid.pager.maxperpage %}selected="selected"{% endif %} value="{{ admin.generateUrl('list', {'filter': admin.datagrid.values | merge({'_per_page': per_page})}) }}">
{{ per_page }}
</option>
{% endfor %}
</select>
{% endif %}
</div>
{% endblock %}
{% endblock %}
&nbsp;-&nbsp;
<label class="control-label" for="{{ admin.uniqid }}_per_page">{% trans from 'SonataAdminBundle' %}label_per_page{% endtrans %}</label>
<select class="per-page small" id="{{ admin.uniqid }}_per_page" style="width: auto; height: auto">
{% for per_page in admin.getperpageoptions %}
<option {% if per_page == admin.datagrid.pager.maxperpage %}selected="selected"{% endif %} value="{{ admin.generateUrl('list', {'filter': admin.datagrid.values | merge({'_per_page': per_page})}) }}">
{{ per_page }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
</div>
</th>
Expand Down
45 changes: 44 additions & 1 deletion Tests/Admin/FieldDescriptionCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,47 @@ public function testArrayAccessSetField()

$collection['foo'] = null;
}
}

public function testReorderListWithoutBatchField()
{
$collection = new FieldDescriptionCollection();

$fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
$fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('title'));
$collection->add($fieldDescription);

$fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
$fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('position'));
$collection->add($fieldDescription);

$newOrder = array('position', 'title');
$collection->reorder($newOrder);

$actualElements = array_keys($collection->getElements());
$this->assertSame($newOrder, $actualElements, 'the order is wrong');
}

public function testReorderListWithBatchField()
{
$collection = new FieldDescriptionCollection();

$fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
$fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('title'));
$collection->add($fieldDescription);

$fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
$fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('position'));
$collection->add($fieldDescription);

$fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
$fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('batch'));
$collection->add($fieldDescription);

$newOrder = array('position', 'title');
$collection->reorder($newOrder);
array_unshift($newOrder, 'batch');

$actualElements = array_keys($collection->getElements());
$this->assertSame($newOrder, $actualElements, 'the order is wrong');
}
}

0 comments on commit 5594a79

Please sign in to comment.