edit_orm_one_association_script.html.twig 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. <!-- edit one association -->
  12. <script type="text/javascript">
  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.id(sonata_admin.admin.root.subject),
  24. 'uniqid': sonata_admin.admin.root.uniqid
  25. } + sonata_admin.field_description.getOption('link_parameters', {})) }}',
  26. type: "POST",
  27. dataType: 'html',
  28. data: { _xml_http_request: true },
  29. success: function(html) {
  30. jQuery('#field_container_{{ id }}').replaceWith(html); // replace the html
  31. if(jQuery(form + 'input[type="file"]').length > 0) {
  32. jQuery(form).attr('enctype', 'multipart/form-data');
  33. jQuery(form).attr('encoding', 'multipart/form-data');
  34. }
  35. jQuery('#sonata-ba-field-container-{{ id }}').trigger('sonata.add_element');
  36. jQuery('#field_container_{{ id }}').trigger('sonata.add_element');
  37. }
  38. });
  39. return false;
  40. };
  41. var field_widget_{{ id }} = false;
  42. // this function initialize the popup
  43. // this can be only done this way has popup can be cascaded
  44. function start_field_retrieve_{{ id }}(link) {
  45. link.onclick = null;
  46. // initialize component
  47. field_widget_{{ id }} = jQuery("#field_widget_{{ id }}");
  48. // add the jQuery event to the a element
  49. jQuery(link)
  50. .click(field_add_{{ id }})
  51. .trigger('click')
  52. ;
  53. return false;
  54. }
  55. </script>
  56. <!-- / edit one association -->
  57. {% endautoescape %}