Skip to content

Commit

Permalink
feature #584 Improve the design for empty collections (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the master branch (closes #584).

Discussion
----------

Improve the design for empty collections

### Before

![empty_before](https://cloud.githubusercontent.com/assets/73419/11319205/7c0ff4f2-906f-11e5-9a45-619c5b7d0f62.png)

### After

![empty_after](https://cloud.githubusercontent.com/assets/73419/11319206/7f7c39fc-906f-11e5-968f-836f8f815cdc.png)

Commits
-------

51b90e1 Improve the design for empty collections
  • Loading branch information
javiereguiluz committed Nov 21, 2015
2 parents cf822cb + 51b90e1 commit 6c2161c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions Resources/views/css/admin.css.twig
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ button.btn-danger {
margin-bottom: .5em;
}

/* Field: collection
------------------------------------------------------------------------- */
.field-collection .collection-empty {
margin: .5em 0;
}
.field-collection .collection-empty .label-empty {
color: {{ colors.gray_dark }};
}

/* Select2 widget
------------------------------------------------------------------------- */
.select2-container--bootstrap .select2-selection {
Expand Down
16 changes: 10 additions & 6 deletions Resources/views/form/bootstrap_3_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@
{% if allow_add|default(false) %}
{% set js_add_item %}
$(function() {
if(event.preventDefault) event.preventDefault(); else event.returnValue = false;
if (event.preventDefault) event.preventDefault(); else event.returnValue = false;

var collection = $('#{{ id }}');
var numItems = collection.children('div.form-group').length;

collection.prev('.collection-empty').remove();

var newItem = collection.attr('data-prototype')
.replace(/\>__name__label__\</g, '>' + numItems + '<')
.replace(/_{{ name }}___name__/g, '_{{ name }}_' + numItems)
Expand Down Expand Up @@ -283,16 +285,18 @@
{% endblock form_errors %}

{%- block form_widget_compound -%}
{% if value is empty %}
<div class="empty collection-empty">
<span class="label label-empty">{{ 'label.empty'|trans({}, 'EasyAdminBundle') }}</span>
</div>
{% endif %}

{{ parent() }}

{% if form.parent.vars.allow_delete|default(false) %}
{% set remove_item_javascript %}
$(function() {
if(event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
if (event.preventDefault) event.preventDefault(); else event.returnValue = false;

var containerDiv = $('#{{ id }}').parents('.form-group:first');
containerDiv.remove();
Expand Down

0 comments on commit 6c2161c

Please sign in to comment.