vendor/sonata-project/admin-bundle/src/Resources/views/CRUD/Association/edit_one_script.html.twig line 1

Open in your IDE?
  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 manages 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: '{{ path('sonata_admin_append_form_element', {
  21.                 '_sonata_admin': sonata_admin.admin.root.baseCodeRoute,
  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.             + (
  27.                 sonata_admin.admin.root.hasRequest()
  28.                 ? sonata_admin.admin.root.request.attributes.get('_route_params', {})
  29.                 : {}
  30.             ) + app.request.query.all|default({})
  31.             ) }}',
  32.             type: "POST",
  33.             dataType: 'html',
  34.             data: { _xml_http_request: true },
  35.             success: function(html) {
  36.                 if (!html.length) {
  37.                     return;
  38.                 }
  39.                 var $newForm = jQuery(html);
  40.                 var $oldForm = jQuery('#field_container_{{ id }}');
  41.                 // Maintain state of file inputs
  42.                 $oldForm.find('input[type="file"]').each(function(){
  43.                     var id = '#'+$(this).attr('id');
  44.                     $newForm.find(id).replaceWith($(this));
  45.                 });
  46.                 $oldForm.replaceWith($newForm); // replace the html
  47.                 Admin.shared_setup(jQuery('#field_container_{{ id }}'));
  48.                 if(jQuery('input[type="file"]', form).length > 0) {
  49.                     jQuery(form).attr('enctype', 'multipart/form-data');
  50.                     jQuery(form).attr('encoding', 'multipart/form-data');
  51.                 }
  52.                 jQuery('#sonata-ba-field-container-{{ id }}').trigger('sonata.add_element');
  53.                 jQuery('#field_container_{{ id }}').trigger('sonata.add_element');
  54.             }
  55.         });
  56.         return false;
  57.     };
  58.     var field_widget_{{ id }} = false;
  59.     // this function initializes the popup
  60.     // this can be only done this way as popup can be cascaded
  61.     function start_field_retrieve_{{ id }}(link) {
  62.         link.onclick = null;
  63.         // initialize component
  64.         field_widget_{{ id }} = jQuery("#field_widget_{{ id }}");
  65.         // add the jQuery event to the a element
  66.         jQuery(link)
  67.             .click(field_add_{{ id }})
  68.             .trigger('click')
  69.         ;
  70.         return false;
  71.     }
  72. </script>
  73. <!-- / edit one association -->
  74. {% endautoescape %}