[ticket/416] Add method for handling ajax requests

B3P-416
This commit is contained in:
Marc Alexander
2014-11-27 23:45:32 +01:00
parent a6b1e82e56
commit 8c0d537841
2 changed files with 28 additions and 16 deletions

View File

@@ -542,8 +542,7 @@ class portal_module
$this->template->set_filenames(array(
'body' => 'portal/acp_portal_modules.html')
);
$json_response = new \phpbb\json_response;
$json_response->send(array(
$this->modules_manager->handle_ajax_request(array(
'MESSAGE_BODY' => $this->template->assign_display('body'),
'MESSAGE_TITLE' => $this->user->lang['ADD_MODULE'],
'MESSAGE_TEXT' => $this->user->lang['ADD_MODULE'],

View File

@@ -113,6 +113,23 @@ class manager
}
}
/**
* Handle ajax request.
* Method will return supplied data if request is an ajax request
*
* @param array $data Data to send
*
* @return null
*/
public function handle_ajax_request($data)
{
if ($this->request->is_ajax())
{
$json_response = new \phpbb\json_response;
$json_response->send($data);
}
}
/**
* Reset module settings to default options
*
@@ -188,11 +205,9 @@ class manager
$this->cache->destroy('portal_modules');
if ($this->request->is_ajax())
{
$json_response = new \phpbb\json_response;
$json_response->send(array('success' => true));
}
// Handle ajax requests
$this->handle_ajax_request(array('success' => true));
redirect($this->u_action); // redirect in order to get rid of excessive URL parameters
}
@@ -499,15 +514,13 @@ class manager
$this->cache->purge(); // make sure we don't get errors after re-adding a module
if ($this->request->is_ajax())
{
$json_response = new \phpbb\json_response;
$json_response->send(array(
'success' => true,
'MESSAGE_TITLE' => $this->user->lang['INFORMATION'],
'MESSAGE_TEXT' => $this->user->lang['SUCCESS_DELETE'],
));
}
// Handle ajax request
$this->handle_ajax_request(array(
'success' => true,
'MESSAGE_TITLE' => $this->user->lang['INFORMATION'],
'MESSAGE_TEXT' => $this->user->lang['SUCCESS_DELETE'],
));
trigger_error($this->user->lang['SUCCESS_DELETE'] . adm_back_link($this->u_action));
}
else