Преглед изворни кода

Migrate and Fix code to work with jQuery 1.7

Thomas Rabaix пре 13 година
родитељ
комит
4d768b4ea1

+ 29 - 32
Resources/views/CRUD/edit_orm_many_association_script.html.twig

@@ -18,8 +18,9 @@ This code manage the many-to-[one|many] association field popup
 
 {% autoescape false %}
 
-<script>
-    <!-- edit many association -->
+<!-- edit many association -->
+
+<script type="text/javascript">
 
     {#
       handle link click in a list :
@@ -94,6 +95,7 @@ This code manage the many-to-[one|many] association field popup
                     jQuery(form).ajaxSubmit({
                         type: form.attr('method'),
                         url: form.attr('action'),
+                        dataType: 'html',
                         data: {_xml_http_request: true},
                         success: function(html) {
                            field_dialog_{{ id }}.html(html);
@@ -134,6 +136,7 @@ This code manage the many-to-[one|many] association field popup
         // retrieve the form element from the related admin generator
         jQuery.ajax({
             url: a.attr('href'),
+            dataType: 'html',
             success: function(html) {
 
                 Admin.log('[{{ id }}|field_dialog_form_add] ajax success', field_dialog_{{ id }});
@@ -151,6 +154,7 @@ This code manage the many-to-[one|many] association field popup
                     height: 'auto',
                     width: 650,
                     modal: true,
+                    autoOpen: true,
                     resizable: false,
                     title: '{{ sonata_admin.field_description.associationadmin.label }}',
                     close: function(event, ui) {
@@ -270,7 +274,7 @@ This code manage the many-to-[one|many] association field popup
             field_dialog_{{ id }} = jQuery("#field_dialog_{{ id }}");
 
             // move the dialog as a child of the root element, nested form breaks html ...
-            jQuery(document).append(field_dialog_{{ id }});
+            jQuery(document.body).append(field_dialog_{{ id }});
 
             Admin.log('[{{ id }}|field_dialog] move dialog container as a document child');
         }
@@ -281,21 +285,18 @@ This code manage the many-to-[one|many] association field popup
     #}
     // this function initialize the popup
     // this can be only done this way has popup can be cascaded
-    function start_field_dialog_form_add_{{ id }}(event) {
-
-        var targetElement = Admin.stopEvent(event);
+    function start_field_dialog_form_add_{{ id }}(link) {
 
-        // remove the html event a
-        var a = jQuery(targetElement).closest('a');
-        a.removeAttr('onclick');
+        // remove the html event
+        link.onclick = null;
 
         initialize_popup_{{ id }}();
 
-       // add the jQuery event to the a element
-        a.click(field_dialog_form_add_{{ id }});
-
-        // trigger the event
-        a.trigger('click');
+        // add the jQuery event to the a element
+        jQuery(link)
+            .click(field_dialog_form_add_{{ id }})
+            .trigger('click')
+        ;
 
         return false;
     }
@@ -309,34 +310,29 @@ This code manage the many-to-[one|many] association field popup
         #}
         // this function initialize the popup
         // this can be only done this way has popup can be cascaded
-        function start_field_dialog_form_list_{{ id }}(event) {
-            var targetElement = Admin.stopEvent(event);
+        function start_field_dialog_form_list_{{ id }}(link) {
 
-            // remove the html event a
-            var a = jQuery(targetElement).closest('a');
-            a.removeAttr('onclick');
+            link.onclick = null;
 
             initialize_popup_{{ id }}();
 
             // add the jQuery event to the a element
-            a.click(field_dialog_form_list_{{ id }});
-
-            // trigger the event
-            a.trigger('click');
+            jQuery(link)
+                .click(field_dialog_form_list_{{ id }})
+                .trigger('click')
+            ;
 
             return false;
         }
 
-        function remove_selected_element_{{ id }}(event) {
-            var targetElement = Admin.stopEvent(event);
-
-            // remove the html event a
-            var a = jQuery(targetElement).closest('a');
-            a.removeAttr('onclick');
+        function remove_selected_element_{{ id }}(link) {
 
-            a.click(field_remove_element_{{ id}});
+            link.onclick = null;
 
-            a.trigger('click');
+            jQuery(link)
+                .click(field_remove_element_{{ id}})
+                .trigger('click')
+            ;
 
             return false;
         }
@@ -378,7 +374,8 @@ This code manage the many-to-[one|many] association field popup
 
     {% endif %}
 
-    <!-- / edit many association -->
+
 </script>
+<!-- / edit many association -->
 
 {% endautoescape %}

+ 1 - 1
Resources/views/CRUD/edit_orm_many_to_many.html.twig

@@ -19,7 +19,7 @@ file that was distributed with this source code.
             {% if sonata_admin.field_description.associationadmin.hasRoute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') %}
                 <a
                     href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
-                    onclick="start_field_dialog_form_add_{{ id }}(event)"
+                    onclick="return start_field_dialog_form_add_{{ id }}(this);"
                     class="sonata-ba-action"
                     >
                         <img

+ 3 - 3
Resources/views/CRUD/edit_orm_many_to_one.html.twig

@@ -42,7 +42,7 @@ file that was distributed with this source code.
 
             {% if sonata_admin.edit == 'list' and sonata_admin.field_description.associationadmin.hasRoute('list') and sonata_admin.field_description.associationadmin.isGranted('LIST') %}
                 <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('list') }}"
-                    onclick="start_field_dialog_form_list_{{ id }}(event)"
+                    onclick="return start_field_dialog_form_list_{{ id }}(this);"
                     class="sonata-ba-action"
                     >
                     <img src="{{ asset('bundles/sonataadmin/famfamfam/application_view_list.png') }}"
@@ -53,7 +53,7 @@ file that was distributed with this source code.
 
             {% if sonata_admin.field_description.associationadmin.hasRoute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') %}
                 <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
-                    onclick="start_field_dialog_form_add_{{ id }}(event)"
+                    onclick="return start_field_dialog_form_add_{{ id }}(this);"
                     class="sonata-ba-action"
                     >
                         <img src="{{ asset('bundles/sonataadmin/famfamfam/add.png') }}" alt="{% trans from 'SonataAdminBundle' %}btn_add{% endtrans %}" />
@@ -62,7 +62,7 @@ file that was distributed with this source code.
 
             {% if sonata_admin.edit == 'list' and sonata_admin.field_description.associationadmin.hasRoute('list') and sonata_admin.field_description.associationadmin.isGranted('LIST') %}
                 <a  href=""
-                    onclick="remove_selected_element_{{ id }}(event)"
+                    onclick="return remove_selected_element_{{ id }}(this);"
                     class="sonata-ba-action"
                     >
                     <img src="{{ asset('bundles/sonataadmin/famfamfam/cancel.png') }}"

+ 12 - 15
Resources/views/CRUD/edit_orm_one_association_script.html.twig

@@ -18,9 +18,9 @@ This code manage the one-to-many association field popup
 
 {% autoescape false %}
 
-<script>
+<!-- edit one association -->
 
-    <!-- edit one association -->
+<script type="text/javascript">
 
     // handle the add link
     var field_add_{{ id }} = function(event) {
@@ -43,7 +43,8 @@ This code manage the one-to-many association field popup
             success: function(html) {
                 jQuery('#field_container_{{ id }}')
                     .replaceWith(html) // replace the html
-                    .trigger('sonata.add_element');
+                    .trigger('sonata.add_element')
+                ;
             }
         });
 
@@ -54,27 +55,23 @@ This code manage the one-to-many association field popup
 
     // this function initialize the popup
     // this can be only done this way has popup can be cascaded
-    function start_field_retrieve_{{ id }}(event) {
-        var targetElement = Admin.stopEvent(event);
+    function start_field_retrieve_{{ id }}(link) {
 
-        // remove the html event a
-        var a = jQuery(targetElement).closest('a');
-        a.removeAttr('onclick');
+        link.onclick = null;
 
         // initialize component
         field_widget_{{ id }} = jQuery("#field_widget_{{ id }}");
 
         // add the jQuery event to the a element
-        a.click(field_add_{{ id }});
-
-        // trigger the event
-        a.trigger('click');
+        jQuery(link)
+            .click(field_add_{{ id }})
+            .trigger('click')
+        ;
 
         return false;
     }
-
-    <!-- edit one association -->
-
 </script>
 
+<!-- / edit one association -->
+
 {% endautoescape %}

+ 3 - 3
Resources/views/CRUD/edit_orm_one_to_many.html.twig

@@ -80,7 +80,7 @@ file that was distributed with this source code.
                 <span id="field_actions_{{ id }}" >
                     <a
                         href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
-                        onclick="start_field_retrieve_{{ id }}(event)"
+                        onclick="return start_field_retrieve_{{ id }}(this);"
                         class="sonata-ba-action"
                         >
                         <img
@@ -93,7 +93,7 @@ file that was distributed with this source code.
 
             {# add code for the sortable options #}
             {% if sonata_admin.field_description.options.sortable is defined %}
-                <script>
+                <script type="text/javascript">
                     jQuery('div#field_container_{{ id }} tbody.sonata-ba-tbody').sortable({
                         axis: 'y',
                         opacity: 0.6,
@@ -134,7 +134,7 @@ file that was distributed with this source code.
                 {% if sonata_admin.field_description.associationadmin.hasroute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') %}
                     <a
                         href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
-                        onclick="start_field_dialog_form_add_{{ id }}(event)"
+                        onclick="return start_field_dialog_form_add_{{ id }}(this);"
                         class="sonata-ba-action"
                         >
                         <img

+ 3 - 3
Resources/views/CRUD/edit_orm_one_to_one.html.twig

@@ -42,7 +42,7 @@ file that was distributed with this source code.
             {% if sonata_admin.edit == 'list' and sonata_admin.field_description.associationadmin.hasroute('list') and sonata_admin.field_description.associationadmin.isGranted('LIST') %}
 
                 <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('list') }}"
-                    onclick="start_field_dialog_form_list_{{ id }}(event)"
+                    onclick="return start_field_dialog_form_list_{{ id }}(this);"
                     class="sonata-ba-action"
                     >
                         <img
@@ -54,7 +54,7 @@ file that was distributed with this source code.
 
             {% if sonata_admin.field_description.associationadmin.hasroute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') %}
                 <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
-                    onclick="start_field_dialog_form_add_{{ id }}(event)"
+                    onclick="return start_field_dialog_form_add_{{ id }}(this);"
                     class="sonata-ba-action"
                     >
                         <img
@@ -66,7 +66,7 @@ file that was distributed with this source code.
 
             {% if sonata_admin.edit == 'list' and sonata_admin.field_description.associationadmin.hasRoute('list') and sonata_admin.field_description.associationadmin.isGranted('LIST') %}
                 <a  href=""
-                    onclick="remove_selected_element_{{ id }}(event)"
+                    onclick="return remove_selected_element_{{ id }}(this);"
                     class="sonata-ba-action"
                     >
                     <img src="{{ asset('bundles/sonataadmin/famfamfam/cancel.png') }}"

+ 1 - 1
Resources/views/CRUD/list_orm_many_to_many.html.twig

@@ -11,7 +11,7 @@ file that was distributed with this source code.
 
 {% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
 
-{% block field%}
+{% block field %}
     {% if field_description.hasassociationadmin and field_description.associationadmin.hasRoute('edit') and field_description.associationadmin.isGranted('edit')%}
         {% for element in value%}
             <a href="{{ field_description.associationadmin.generateObjectUrl('edit', element) }}">{{ element|render_relation_element(field_description) }}</a>

+ 1 - 1
Resources/views/CRUD/list_orm_one_to_many.html.twig

@@ -11,7 +11,7 @@ file that was distributed with this source code.
 
 {% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
 
-{% block field%}
+{% block field %}
     {% if field_description.hasassociationadmin and field_description.associationadmin.isGranted('EDIT') and field_description.associationadmin.hasRoute('edit') %}
         {% for element in value%}
             <a href="{{ field_description.associationadmin.generateObjectUrl('edit', element) }}">{{ element|render_relation_element(field_description) }}</a>