edit_orm_one_to_many.html.twig 6.6 KB

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