edit_orm_one_to_many.html.twig 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.children %}
  17. <table>
  18. <thead>
  19. <tr>
  20. {% for field_name, nested_field in form.children[0].children %}
  21. {% if field_name == '_delete' %}
  22. <th>{% trans from 'SonataAdminBundle' %}action_delete{% endtrans %}</th>
  23. {% else %}
  24. {% if nested_field.get('sonata_admin').field_description.options.name is defined %}
  25. <th>{{ nested_field.get('sonata_admin').field_description.options.name }}</th>
  26. {% else %}
  27. <th>{{ field_name|trans({},'SonataAdminBundle') }}</th>
  28. {% endif %}
  29. {% endif %}
  30. {% endfor %}
  31. </tr>
  32. </thead>
  33. <tbody class="sonata-ba-tbody">
  34. {% for nested_group_field_name, nested_group_field in form.children %}
  35. <tr>
  36. {% for field_name, nested_field in nested_group_field.children %}
  37. <td class="sonata-ba-td-{{ id }}-{{ field_name }}">
  38. {% if sonata_admin.field_description.associationadmin.formfielddescriptions[field_name] is defined %}
  39. {{ form_widget(nested_field) }}
  40. {% set dummy = nested_group_field.setrendered %}
  41. {% else %}
  42. {{ form_widget(nested_field) }}
  43. {% endif %}
  44. </td>
  45. {% endfor %}
  46. </tr>
  47. {% endfor %}
  48. </tbody>
  49. </table>
  50. {% endif %}
  51. {% else %}
  52. {% if form.children %}
  53. <div>
  54. {% for nested_group_field_name, nested_group_field in form.children %}
  55. {% for field_name, nested_field in nested_group_field.children %}
  56. {% if sonata_admin.field_description.associationadmin.formfielddescriptions[field_name] is defined %}
  57. {{ form_widget(nested_field, {
  58. 'inline': 'natural',
  59. 'edit' : 'inline'
  60. }) }}
  61. {% set dummy = nested_group_field.setrendered %}
  62. {% else %}
  63. {{ form_widget(nested_field) }}
  64. {% endif %}
  65. {% endfor %}
  66. {% endfor %}
  67. </div>
  68. {% endif %}
  69. {% endif %}
  70. {% else %}
  71. {{ form_widget(form) }}
  72. {% endif %}
  73. </span>
  74. {% if sonata_admin.edit == 'inline' %}
  75. {% if sonata_admin.field_description.associationadmin.hasroute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') %}
  76. <span id="field_actions_{{ id }}" >
  77. <a
  78. href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
  79. onclick="start_field_retrieve_{{ id }}(event)"
  80. class="sonata-ba-action"
  81. >
  82. <img
  83. src="{{ asset('bundles/sonataadmin/famfamfam/add.png') }}"
  84. alt="{% trans from 'SonataAdminBundle' %}btn_add{% endtrans %}"
  85. />
  86. </a>
  87. </span>
  88. {% endif %}
  89. {# add code for the sortable options #}
  90. {% if sonata_admin.field_description.options.sortable is defined %}
  91. <script>
  92. jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody').sortable({
  93. axis: 'y',
  94. opacity: 0.6,
  95. items: 'tr',
  96. stop: apply_position_value_{{ id }}
  97. });
  98. function apply_position_value_{{ id }}() {
  99. // update the input value position
  100. jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody td.sonata-ba-td-{{ id }}-position').each(function(index, element) {
  101. // remove the sortable handler and put it back
  102. jQuery('span.sonata-ba-sortable-handler', element).remove();
  103. jQuery(element).append('<span class="sonata-ba-sortable-handler ui-icon ui-icon-grip-solid-horizontal"></span>');
  104. jQuery('input', element).hide();
  105. });
  106. jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody td.sonata-ba-td-{{ id }}-position input').each(function(index, value) {
  107. jQuery(value).val(index + 1);
  108. });
  109. }
  110. // refresh the sortable option when a new element is added
  111. jQuery('#sonata-ba-field-container-{{ id }}').bind('sonata.add_element', function() {
  112. apply_position_value_{{ id }}();
  113. jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody').sortable('refresh');
  114. });
  115. apply_position_value_{{ id }}();
  116. </script>
  117. {% endif %}
  118. {# include association code #}
  119. {% include 'SonataAdminBundle:CRUD:edit_orm_one_association_script.html.twig' %}
  120. {% else %}
  121. <span id="field_actions_{{ id }}" >
  122. {% if sonata_admin.field_description.associationadmin.hasroute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') %}
  123. <a
  124. href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
  125. onclick="start_field_dialog_form_add_{{ id }}(event)"
  126. class="sonata-ba-action"
  127. >
  128. <img
  129. src="{{ asset('bundles/sonataadmin/famfamfam/add.png') }}"
  130. alt="{% trans from 'SonataAdminBundle' %}btn_add{% endtrans %}"
  131. />
  132. </a>
  133. {% endif %}
  134. </span>
  135. <div style="display: none" id="field_dialog_{{ id }}">
  136. </div>
  137. {% include 'SonataAdminBundle:CRUD:edit_orm_many_association_script.html.twig' %}
  138. {% endif %}
  139. </div>
  140. {% endif %}