edit_orm_one_to_many.html.twig 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. {#
  2. This file is part of the Sonata package.
  3. (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  4. For the full copyright and license information, please view the LICENSE
  5. file that was distributed with this source code.
  6. #}
  7. {% if not sonata_admin.field_description.hasassociationadmin %}
  8. {% for element in value %}
  9. {{ element|render_relation_element(sonata_admin.field_description) }}
  10. {% endfor %}
  11. {% else %}
  12. <div id="field_container_{{ id }}">
  13. <span id="field_widget_{{ id }}" >
  14. {% if sonata_admin.edit == 'inline' %}
  15. {% if sonata_admin.inline == 'table' %}
  16. {% if form.getChildren() %}
  17. <table class="bordered-table">
  18. <thead>
  19. <tr>
  20. {% for field_name, nested_field in form.getChild(0).getChildren() %}
  21. {% if field_name == '_delete' %}
  22. <th>{% trans from 'SonataAdminBundle' %}action_delete{% endtrans %}</th>
  23. {% else %}
  24. <th>{{ nested_field.get('sonata_admin').admin.trans(nested_field.vars.label) }}</th>
  25. {% endif %}
  26. {% endfor %}
  27. </tr>
  28. </thead>
  29. <tbody class="sonata-ba-tbody">
  30. {% for nested_group_field_name, nested_group_field in form.getChildren() %}
  31. <tr>
  32. {% for field_name, nested_field in nested_group_field.getChildren() %}
  33. <td class="sonata-ba-td-{{ id }}-{{ field_name }}">
  34. {% if sonata_admin.field_description.associationadmin.formfielddescriptions[field_name] is defined %}
  35. {{ form_widget(nested_field) }}
  36. {% set dummy = nested_group_field.setrendered %}
  37. {% else %}
  38. {{ form_widget(nested_field) }}
  39. {% endif %}
  40. </td>
  41. {% endfor %}
  42. </tr>
  43. {% endfor %}
  44. </tbody>
  45. </table>
  46. {% endif %}
  47. {% elseif form.getChildren() %}
  48. <div>
  49. {% for nested_group_field_name, nested_group_field in form.getChildren() %}
  50. {% for field_name, nested_field in nested_group_field.getChildren() %}
  51. {% if sonata_admin.field_description.associationadmin.formfielddescriptions[field_name] is defined %}
  52. {{ form_widget(nested_field, {
  53. 'inline': 'natural',
  54. 'edit' : 'inline'
  55. }) }}
  56. {% set dummy = nested_group_field.setrendered %}
  57. {% else %}
  58. {{ form_widget(nested_field) }}
  59. {% endif %}
  60. {% endfor %}
  61. {% endfor %}
  62. </div>
  63. {% endif %}
  64. {% else %}
  65. {{ form_widget(form) }}
  66. {% endif %}
  67. </span>
  68. {% if sonata_admin.edit == 'inline' %}
  69. {% if sonata_admin.field_description.associationadmin.hasroute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') %}
  70. <span id="field_actions_{{ id }}" >
  71. <a
  72. href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
  73. onclick="return start_field_retrieve_{{ id }}(this);"
  74. class="sonata-ba-action"
  75. >
  76. <img
  77. src="{{ asset('bundles/sonataadmin/famfamfam/add.png') }}"
  78. alt="{% trans from 'SonataAdminBundle' %}btn_add{% endtrans %}"
  79. />
  80. </a>
  81. </span>
  82. {% endif %}
  83. {# add code for the sortable options #}
  84. {% if sonata_admin.field_description.options.sortable is defined %}
  85. <script type="text/javascript">
  86. jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody').sortable({
  87. axis: 'y',
  88. opacity: 0.6,
  89. items: 'tr',
  90. stop: apply_position_value_{{ id }}
  91. });
  92. function apply_position_value_{{ id }}() {
  93. // update the input value position
  94. jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody td.sonata-ba-td-{{ id }}-position').each(function(index, element) {
  95. // remove the sortable handler and put it back
  96. jQuery('span.sonata-ba-sortable-handler', element).remove();
  97. jQuery(element).append('<span class="sonata-ba-sortable-handler ui-icon ui-icon-grip-solid-horizontal"></span>');
  98. jQuery('input', element).hide();
  99. });
  100. jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody td.sonata-ba-td-{{ id }}-position input').each(function(index, value) {
  101. jQuery(value).val(index + 1);
  102. });
  103. }
  104. // refresh the sortable option when a new element is added
  105. jQuery('#sonata-ba-field-container-{{ id }}').bind('sonata.add_element', function() {
  106. apply_position_value_{{ id }}();
  107. jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody').sortable('refresh');
  108. });
  109. apply_position_value_{{ id }}();
  110. </script>
  111. {% endif %}
  112. {# include association code #}
  113. {% include 'SonataDoctrineORMAdminBundle:CRUD:edit_orm_one_association_script.html.twig' %}
  114. {% else %}
  115. <span id="field_actions_{{ id }}" >
  116. {% if sonata_admin.field_description.associationadmin.hasroute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') %}
  117. <a
  118. href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
  119. onclick="return start_field_dialog_form_add_{{ id }}(this);"
  120. class="sonata-ba-action"
  121. >
  122. <img
  123. src="{{ asset('bundles/sonataadmin/famfamfam/add.png') }}"
  124. alt="{% trans from 'SonataAdminBundle' %}btn_add{% endtrans %}"
  125. />
  126. </a>
  127. {% endif %}
  128. </span>
  129. <div style="display: none" id="field_dialog_{{ id }}">
  130. </div>
  131. {% include 'SonataDoctrineORMAdminBundle:CRUD:edit_orm_many_association_script.html.twig' %}
  132. {% endif %}
  133. </div>
  134. {% endif %}