|
@@ -148,14 +148,15 @@ class CRUDController extends Controller
|
|
return $this->render($this->admin->getListTemplate(), array(
|
|
return $this->render($this->admin->getListTemplate(), array(
|
|
'action' => 'list',
|
|
'action' => 'list',
|
|
'form' => $formView,
|
|
'form' => $formView,
|
|
- 'datagrid' => $this->admin->getDatagrid()
|
|
|
|
|
|
+ 'datagrid' => $datagrid
|
|
));
|
|
));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* execute a batch delete
|
|
* execute a batch delete
|
|
*
|
|
*
|
|
- * @param array $idx
|
|
|
|
|
|
+ * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
|
|
|
|
+ * @param $query
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
|
*/
|
|
*/
|
|
public function batchActionDelete($query)
|
|
public function batchActionDelete($query)
|
|
@@ -296,9 +297,20 @@ class CRUDController extends Controller
|
|
throw new \RuntimeException('invalid request type, POST expected');
|
|
throw new \RuntimeException('invalid request type, POST expected');
|
|
}
|
|
}
|
|
|
|
|
|
- $action = $this->get('request')->get('action');
|
|
|
|
- $idx = $this->get('request')->get('idx');
|
|
|
|
- $all_elements = $this->get('request')->get('all_elements', false);
|
|
|
|
|
|
+ if ($data = json_decode($this->get('request')->get('data'), true)) {
|
|
|
|
+ $action = $data['action'];
|
|
|
|
+ $idx = $data['idx'];
|
|
|
|
+ $all_elements = $data['all_elements'];
|
|
|
|
+ } else {
|
|
|
|
+ $action = $this->get('request')->get('action');
|
|
|
|
+ $idx = $this->get('request')->get('idx');
|
|
|
|
+ $all_elements = $this->get('request')->get('all_elements', false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $batchActions = $this->admin->getBatchActions();
|
|
|
|
+ if (!array_key_exists($action, $batchActions)) {
|
|
|
|
+ throw new \RuntimeException(sprintf('The `%s` batch action is not defined', $action));
|
|
|
|
+ }
|
|
|
|
|
|
if (count($idx) == 0 && !$all_elements) { // no item selected
|
|
if (count($idx) == 0 && !$all_elements) { // no item selected
|
|
$this->get('session')->setFlash('sonata_flash_notice', 'flash_batch_empty');
|
|
$this->get('session')->setFlash('sonata_flash_notice', 'flash_batch_empty');
|
|
@@ -306,8 +318,24 @@ class CRUDController extends Controller
|
|
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
|
|
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
|
|
}
|
|
}
|
|
|
|
|
|
- if (!array_key_exists($action, $this->admin->getBatchActions())) {
|
|
|
|
- throw new \RuntimeException(sprintf('The `%s` batch action is not defined', $action));
|
|
|
|
|
|
+ $askConfirmation = isset($batchActions[$action]['ask_confirmation']) ? $batchActions[$action]['ask_confirmation'] : true;
|
|
|
|
+
|
|
|
|
+ if ($askConfirmation && $this->get('request')->get('confirmation') != 'ok') {
|
|
|
|
+ $data = json_encode(array(
|
|
|
|
+ 'action' => $action,
|
|
|
|
+ 'idx' => $idx,
|
|
|
|
+ 'all_elements' => $all_elements,
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ $datagrid = $this->admin->getDatagrid();
|
|
|
|
+ $formView = $datagrid->getForm()->createView();
|
|
|
|
+
|
|
|
|
+ return $this->render('SonataAdminBundle:CRUD:batch_confirmation.html.twig', array(
|
|
|
|
+ 'action' => 'list',
|
|
|
|
+ 'datagrid' => $datagrid,
|
|
|
|
+ 'form' => $formView,
|
|
|
|
+ 'data' => $data,
|
|
|
|
+ ));
|
|
}
|
|
}
|
|
|
|
|
|
// execute the action, batchActionXxxxx
|
|
// execute the action, batchActionXxxxx
|
|
@@ -328,6 +356,7 @@ class CRUDController extends Controller
|
|
if (count($idx) > 0) {
|
|
if (count($idx) > 0) {
|
|
$this->admin->getModelManager()->addIdentifiersToQuery($this->admin->getClass(), $query, $idx);
|
|
$this->admin->getModelManager()->addIdentifiersToQuery($this->admin->getClass(), $query, $idx);
|
|
}
|
|
}
|
|
|
|
+
|
|
return call_user_func(array($this, $final_action), $query);
|
|
return call_user_func(array($this, $final_action), $query);
|
|
}
|
|
}
|
|
|
|
|