Browse Source

Add a remove option for list mode

Thomas Rabaix 13 years ago
parent
commit
a6b917da90

+ 4 - 0
Builder/ORM/FormContractor.php

@@ -119,6 +119,10 @@ class FormContractor implements FormContractorInterface
 
             if ($fieldDescription->getOption('edit') == 'list') {
                 $options['parent'] = 'text';
+
+                if (!array_key_exists('required', $options)) {
+                    $options['required'] = false;
+                }
             }
 
         } else if ($type == 'sonata_type_admin') {

+ 13 - 1
Controller/HelperController.php

@@ -25,6 +25,10 @@ class HelperController extends Controller
         return $this->container->get('sonata.admin.helper');
     }
 
+    /**
+     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
     public function appendFormFieldElementAction()
     {
         $helper     = $this->getAdminHelper();
@@ -65,6 +69,10 @@ class HelperController extends Controller
         return new Response($extension->renderWidget($view));
     }
 
+    /**
+     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
     public function retrieveFormFieldElementAction()
     {
         $helper     = $this->getAdminHelper();
@@ -104,6 +112,10 @@ class HelperController extends Controller
         return new Response($extension->renderWidget($view));
     }
 
+    /**
+     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
     public function getShortObjectDescriptionAction()
     {
         $code       = $this->get('request')->query->get('code');
@@ -118,7 +130,7 @@ class HelperController extends Controller
         $object = $admin->getObject($objectId);
 
         if (!$object) {
-            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $objectId));
+            return new Response();
         }
 
         $description = 'no description available';

+ 22 - 0
Resources/views/CRUD/edit_orm_many_association_script.html.twig

@@ -315,12 +315,34 @@ This code manage the many-to-[one|many] association field popup
             return false;
         }
 
+        function remove_selected_element_{{ id }}(event) {
+            event.preventDefault();
+
+            var a = jQuery(event.target).closest('a');
+            a.attr('onclick', '');
+
+            a.click(field_remove_element_{{ id}});
+
+            a.trigger('click');
+
+            return false;
+        }
+
+        function field_remove_element_{{ id }}(event) {
+            event.preventDefault();
+
+            jQuery('#{{ id }}').val('');
+            jQuery('#{{ id }}').trigger('change');
+
+            return false;
+        }
         {#
           attach onchange event on the input
         #}
 
         // update the
         jQuery('#{{ id }}').live('change', function(event) {
+            jQuery('#field_widget_{{ id }}').html("{{ 'loading_information ...'|trans([], 'SonataAdminBundle') }}");
             jQuery.ajax({
                 type: 'GET',
                 url: '{{ url('sonata_admin_short_object_information', {

+ 12 - 1
Resources/views/CRUD/edit_orm_many_to_one.html.twig

@@ -17,7 +17,6 @@ file that was distributed with this source code.
     {% endfor %}
 {% else %}
     <div id="field_container_{{ id }}">
-
         {% if sonata_admin.edit == 'list' %}
             <span id="field_widget_{{ id }}" >
                 {% if sonata_admin.admin.id(sonata_admin.value) %}
@@ -60,6 +59,18 @@ file that was distributed with this source code.
                         <img src="{{ asset('bundles/sonataadmin/famfamfam/add.png') }}" alt="{% trans from 'SonataAdminBundle' %}btn_add{% endtrans %}" />
                 </a>
             {% endif %}
+
+            {% 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)"
+                    class="sonata-ba-action"
+                    >
+                    <img src="{{ asset('bundles/sonataadmin/famfamfam/cancel.png') }}"
+                         alt="{% trans from 'SonataAdminBundle' %}btn_cancel{% endtrans %}"
+                    />
+                </a>
+            {% endif %}
+
         </span>
 
         <div class="container sonata-ba-modal sonata-ba-modal-edit-one-to-one" style="display: none" id="field_dialog_{{ id }}">

+ 11 - 0
Resources/views/CRUD/edit_orm_one_to_one.html.twig

@@ -63,6 +63,17 @@ file that was distributed with this source code.
                         />
                 </a>
             {% endif %}
+
+            {% 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)"
+                    class="sonata-ba-action"
+                    >
+                    <img src="{{ asset('bundles/sonataadmin/famfamfam/cancel.png') }}"
+                         alt="{% trans from 'SonataAdminBundle' %}btn_cancel{% endtrans %}"
+                    />
+                </a>
+            {% endif %}
         </span>
 
         <div class="container sonata-ba-modal sonata-ba-modal-edit-one-to-one" style="display: none" id="field_dialog_{{ id }}">