mirror of https://github.com/MISP/MISP
fix: [UI] Redirect after add role modal to index page
parent
307a273e77
commit
b325ec58d4
|
@ -30,13 +30,11 @@ class CerebratesController extends AppController
|
|||
|
||||
public function add()
|
||||
{
|
||||
$this->set('menuData', array('menuList' => 'sync', 'menuItem' => 'add_cerebrate'));
|
||||
$params = [];
|
||||
$this->CRUD->add($params);
|
||||
if ($this->IndexFilter->isRest()) {
|
||||
if ($this->restResponsePayload) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$this->set('permFlags', $this->Role->permFlags);
|
||||
|
||||
$this->loadModel('Organisation');
|
||||
$orgs = $this->Organisation->find('list', [
|
||||
|
@ -48,6 +46,7 @@ class CerebratesController extends AppController
|
|||
'org_id' => $orgs
|
||||
];
|
||||
$this->set(compact('dropdownData'));
|
||||
$this->set('menuData', array('menuList' => 'sync', 'menuItem' => 'add_cerebrate'));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
|
@ -59,7 +58,6 @@ class CerebratesController extends AppController
|
|||
if ($this->IndexFilter->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$this->set('permFlags', $this->Role->permFlags);
|
||||
|
||||
$this->loadModel('Organisation');
|
||||
$orgs = $this->Organisation->find('list', [
|
||||
|
|
|
@ -115,7 +115,15 @@ class CRUDComponent extends Component
|
|||
$this->Controller->render($params['displayOnSuccess']);
|
||||
return;
|
||||
}
|
||||
$this->Controller->redirect(isset($params['redirect']) ? $params['redirect'] : ['action' => 'index']);
|
||||
|
||||
$redirect = isset($params['redirect']) ? $params['redirect'] : ['action' => 'index'];
|
||||
// For AJAX requests doesn't make sense to redirect, redirect must be done on javascript side in `submitGenericFormInPlace`
|
||||
if ($this->Controller->request->is('ajax')) {
|
||||
$redirect = Router::url($redirect);
|
||||
$this->Controller->restResponsePayload = $this->Controller->RestResponse->viewData(['redirect' => $redirect], 'json');
|
||||
} else {
|
||||
$this->Controller->redirect($redirect);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$message = __('%s could not be added.', $modelName);
|
||||
|
|
|
@ -37,9 +37,9 @@ class RolesController extends AppController
|
|||
|
||||
public function admin_add()
|
||||
{
|
||||
$params = ['redirect' => ['controller' => 'roles', 'action' => 'index']];
|
||||
$params = ['redirect' => ['action' => 'index', 'admin' => false]];
|
||||
$this->CRUD->add($params);
|
||||
if ($this->IndexFilter->isRest()) {
|
||||
if ($this->restResponsePayload) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$this->set('permFlags', $this->Role->permFlags);
|
||||
|
@ -70,7 +70,7 @@ class RolesController extends AppController
|
|||
return $this->RestResponse->viewData($role, $this->response->type());
|
||||
} else {
|
||||
$this->Flash->success(__('The Role has been saved'));
|
||||
$this->redirect(array('action' => 'index', 'controller' => 'role'));
|
||||
$this->redirect(array('action' => 'index', 'admin' => false));
|
||||
}
|
||||
} else {
|
||||
if ($this->_isRest()) {
|
||||
|
|
|
@ -5441,13 +5441,18 @@ function loadClusterRelations(clusterId) {
|
|||
}
|
||||
|
||||
function submitGenericFormInPlace() {
|
||||
var $genericForm = $('.genericForm');
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: $('.genericForm').attr('action'),
|
||||
data: $('.genericForm').serialize(), // serializes the form's elements.
|
||||
success: function(data)
|
||||
{
|
||||
$('#genericModal').remove();
|
||||
url: $genericForm.attr('action'),
|
||||
data: $genericForm.serialize(), // serializes the form's elements.
|
||||
success: function(data) {
|
||||
if (typeof data === "object" && data.hasOwnProperty('redirect')) {
|
||||
window.location = data.redirect;
|
||||
return;
|
||||
}
|
||||
|
||||
$('#genericModal').modal('hide').remove();
|
||||
$('body').append(data);
|
||||
$('#genericModal').modal();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue