edit_orm_one_association_script.html.twig 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_{{ id }} = function(event) {
  15. event.preventDefault();
  16. event.stopPropagation();
  17. var form = jQuery(this).closest('form');
  18. // the ajax post
  19. jQuery(form).ajaxSubmit({
  20. url: '{{ url('sonata_admin_append_form_element', {
  21. 'code': sonata_admin.admin.root.code,
  22. 'elementId': id,
  23. 'objectId': sonata_admin.admin.root.subject.id,
  24. 'uniqid': sonata_admin.admin.root.uniqid
  25. }) }}',
  26. type: "POST",
  27. data: { _xml_http_request: true },
  28. success: function(html) {
  29. jQuery('#field_container_{{ id }}')
  30. .replaceWith(html) // replace the html
  31. .trigger('sonata.add_element');
  32. }
  33. });
  34. return false;
  35. };
  36. var field_widget_{{ id }} = false;
  37. // this function initialize the popup
  38. // this can be only done this way has popup can be cascaded
  39. function start_field_retrieve_{{ id }}(event) {
  40. event.preventDefault();
  41. // remove the html event a
  42. var a = jQuery(event.target).closest('a');
  43. a.attr('onclick', '');
  44. // initialize component
  45. field_widget_{{ id }} = jQuery("#field_widget_{{ id }}");
  46. // add the jQuery event to the a element
  47. a.click(field_add_{{ id }});
  48. // trigger the event
  49. a.trigger('click');
  50. return false;
  51. }
  52. <!-- edit one association -->
  53. </script>
  54. {% endautoescape %}