123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- {#
- This file is part of the Sonata package.
- (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- For the full copyright and license information, please view the LICENSE
- file that was distributed with this source code.
- #}
- {#
- This code manage the one-to-many association field popup
- #}
- {% autoescape false %}
- <!-- edit one association -->
- <script type="text/javascript">
- // handle the add link
- var field_add_{{ id }} = function(event) {
- event.preventDefault();
- event.stopPropagation();
- var form = jQuery(this).closest('form');
- // the ajax post
- jQuery(form).ajaxSubmit({
- url: '{{ url('sonata_admin_append_form_element', {
- 'code': sonata_admin.admin.root.code,
- 'elementId': id,
- 'objectId': sonata_admin.admin.root.id(sonata_admin.admin.root.subject),
- 'uniqid': sonata_admin.admin.root.uniqid
- } + sonata_admin.field_description.getOption('link_parameters', {})) }}',
- type: "POST",
- dataType: 'html',
- data: { _xml_http_request: true },
- success: function(html) {
- jQuery('#field_container_{{ id }}').replaceWith(html); // replace the html
- if(jQuery(form + 'input[type="file"]').length > 0) {
- jQuery(form).attr('enctype', 'multipart/form-data');
- jQuery(form).attr('encoding', 'multipart/form-data');
- }
- jQuery('#sonata-ba-field-container-{{ id }}').trigger('sonata.add_element');
- jQuery('#field_container_{{ id }}').trigger('sonata.add_element');
- }
- });
- return false;
- };
- var field_widget_{{ id }} = false;
- // this function initialize the popup
- // this can be only done this way has popup can be cascaded
- function start_field_retrieve_{{ id }}(link) {
- link.onclick = null;
- // initialize component
- field_widget_{{ id }} = jQuery("#field_widget_{{ id }}");
- // add the jQuery event to the a element
- jQuery(link)
- .click(field_add_{{ id }})
- .trigger('click')
- ;
- return false;
- }
- </script>
- <!-- / edit one association -->
- {% endautoescape %}
|