edit_one_association_script.html.twig 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. {#
  8. This code manage the one-to-many association field popup
  9. #}
  10. {% autoescape false %}
  11. <script>
  12. <!-- edit one association -->
  13. // handle the add link
  14. var field_add_{{ admin.uniqid }}_{{ field_element.id }} = function(event) {
  15. event.preventDefault();
  16. var form = jQuery(this).closest('form');
  17. // the ajax post
  18. jQuery.ajax({
  19. url: '{{ url('sonata_base_application_append_form_element', {
  20. 'code': admin.root.code,
  21. 'elementId': field_element.id,
  22. 'objectId': admin.root.subject.id,
  23. 'uniqid': admin.root.uniqid
  24. }) }}',
  25. type: "POST",
  26. data: form.serializeArray(),
  27. success: function(html) {
  28. jQuery('#sonata-ba-field-container-{{ admin.uniqid }}-{{ field_element.id}}').replaceWith(html);
  29. }
  30. });
  31. return false;
  32. };
  33. var field_widget_{{ admin.uniqid }}_{{ field_element.id }} = false;
  34. // this function initialize the popup
  35. // this can be only done this way has popup can be cascaded
  36. function start_field_retrieve_{{ admin.uniqid }}_{{ field_element.id }}(event) {
  37. event.preventDefault();
  38. // remove the html event a
  39. var a = jQuery(event.target).closest('a');
  40. a.attr('onclick', '');
  41. // initialize component
  42. field_widget_{{ admin.uniqid }}_{{ field_element.id }} = jQuery("#field_widget_{{ admin.uniqid }}_{{ field_element.id}}");
  43. // add the jQuery event to the a element
  44. a.click(field_add_{{ admin.uniqid }}_{{ field_element.id }});
  45. // trigger the event
  46. a.trigger('click');
  47. return false;
  48. }
  49. <!-- edit one association -->
  50. </script>
  51. {% endautoescape %}