edit_orm_one_to_many.html.twig 7.7 KB

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