edit_orm_one_to_many.html.twig 6.8 KB

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