]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3127. Normalizing the json returned by the ajax action handler. Doing this...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 28 Apr 2011 02:02:26 +0000 (02:02 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 28 Apr 2011 02:02:26 +0000 (02:02 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@9039 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/actions.php

index 47e4dd4a47362d428b24470d7bf54762b3c5613d..df7c92de4140b185ee42df5cc1392ecbf25ac6e5 100644 (file)
@@ -411,6 +411,16 @@ function elgg_is_xhr() {
  */
 function ajax_forward_hook($hook, $type, $reason, $params) {
        if (elgg_is_xhr()) {
+               // always pass the full structure to avoid boilerplate JS code.
+               $params = array(
+                       'output' => '',
+                       'status' => 0,
+                       'system_messages' => array(
+                               'error' => array(),
+                               'success' => array()
+                       )
+               );
+
                //grab any data echo'd in the action
                $output = ob_get_clean();
 
@@ -423,9 +433,14 @@ function ajax_forward_hook($hook, $type, $reason, $params) {
                }
 
                //Grab any system messages so we can inject them via ajax too
-               $params['system_messages'] = system_messages(NULL, "");
+               $system_messages = system_messages(NULL, "");
+
+               if (isset($system_messages['success'])) {
+                       $params['system_messages']['success'] = $system_messages['success'];
+               }
 
-               if (isset($params['system_messages']['error'])) {
+               if (isset($system_messages['error'])) {
+                       $params['system_messages']['error'] = $system_messages['error'];
                        $params['status'] = -1;
                } else {
                        $params['status'] = 0;