CRM-12527 - Show devel footer in api explorer output
authorColeman Watts <coleman@civicrm.org>
Sat, 8 Aug 2015 00:04:46 +0000 (20:04 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 8 Aug 2015 00:04:46 +0000 (20:04 -0400)
CRM/Utils/REST.php
templates/CRM/Admin/Page/APIExplorer.js

index b5b3880ed46ae52a1cdff7e78393a25c091b253d..f00f96a3afb22869c0b938e54b84cf92f210955a 100644 (file)
@@ -145,11 +145,11 @@ class CRM_Utils_REST {
     }
 
     if (!empty($requestParams['json'])) {
-      CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
       if (!empty($requestParams['prettyprint'])) {
-        // Used by the api explorer
+        // Don't set content-type header for api explorer output
         return self::jsonFormated(array_merge($result));
       }
+      CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
       return json_encode(array_merge($result));
     }
 
index 35a7701c7b1222d1c0c05136503f0c34bb507567..1c8499dc466af7cc38a7bf651254ec3e96256c02 100644 (file)
    * Note: We have to manually execute the ajax in order to add the secret extra "prettyprint" param
    */
   function execute() {
+    var footer;
     $('#api-result').html('<div class="crm-loading-element"></div>');
     $.ajax({
       url: CRM.url('civicrm/ajax/rest'),
       type: _.includes(action, 'get') ? 'GET' : 'POST',
       dataType: 'text'
     }).done(function(text) {
+      // There may be debug information appended to the end of the json string
+      var footerPos = text.indexOf("\n}<");
+      if (footerPos) {
+        footer = text.substr(footerPos + 2);
+        text = text.substr(0, footerPos + 2);
+      }
       $('#api-result').text(text);
       prettyPrint('#api-result');
+      if (footer) {
+        $('#api-result').append(footer);
+      }
     });
   }