Explorar el Código

Merge pull request #1221 from WesleyVanOpdorp/XmlHttpDeleteAction

Added isXmlHttp check
Thomas hace 12 años
padre
commit
eefc5316ad
Se han modificado 1 ficheros con 11 adiciones y 0 borrados
  1. 11 0
      Controller/CRUDController.php

+ 11 - 0
Controller/CRUDController.php

@@ -214,8 +214,19 @@ class CRUDController extends Controller
         if ($this->getRequest()->getMethod() == 'DELETE') {
         if ($this->getRequest()->getMethod() == 'DELETE') {
             try {
             try {
                 $this->admin->delete($object);
                 $this->admin->delete($object);
+
+                if ($this->isXmlHttpRequest()) {
+                    return $this->renderJson(array('result' => 'ok'));
+                }
+
                 $this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');
                 $this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');
+
             } catch (ModelManagerException $e) {
             } catch (ModelManagerException $e) {
+
+                if ($this->isXmlHttpRequest()) {
+                    return $this->renderJson(array('result' => 'error'));
+                }
+
                 $this->get('session')->setFlash('sonata_flash_error', 'flash_delete_error');
                 $this->get('session')->setFlash('sonata_flash_error', 'flash_delete_error');
             }
             }