   $scope.hasParams = -> Object.keys($scope.params).length > 0
   $scope.parsedData = []
   $scope.tree = expanded: false
+  $scope.totalPromises = 0
+  $scope.currentParsed = 0
+  $scope.percentDone = 0
+
+  startId = TreeParsing.nextId()
 
   ct = ($scope.headers['content-type'] ? '')
-  promises = []
-  if $scope.res.response?.length
-    if ct.match(/^application\/json/)
-      parsed = try
-        JSON.parse($scope.res.response)
-      catch e
-        {}
-      for k, v of parsed
-        promises.push TreeParsing.parseObj k, v
-    else if /^text\/xml/.test(ct) or /^application\/xml/.test(ct)
-      try
-        dom = xmlParser.parse $scope.res.response
-        promises.push TreeParsing.parseDOMElem(dom.documentElement)
-      catch e
-        $log.error 'Error parsing xml', e
+  if APPL_JSON.test ct
+    parsed = try
+      JSON.parse($scope.res.response)
+    catch e
+      {}
+    $scope.formattedResponse = JSON.stringify(parsed, null, 2) if parsed?
 
   setTree = (tree) ->
     $scope.parsedData = tree
     $log.debug "Next id = #{ TreeParsing.nextId() }"
-
-  if promises.length
-    $q.all(promises)
-      .then((parsed) -> TreeParsing.expandTree parsed, not $scope.tree.expanded)
-      .then setTree, $log.error
-
-  $scope.isHTML = -> !!ct?.match /^text\/html/
+  
+  $scope.makeBrowseableResponse = ->
+    return if $scope.parsedData.length # Already done.
+    promises = []
+    if $scope.res.response?.length
+      if APPL_JSON.test ct
+        parsed = try
+          JSON.parse($scope.res.response)
+        catch e
+          {}
+        for k, v of parsed
+          promises.push TreeParsing.parseObj k, v
+      else if TEXT_XML.test(ct) or APPL_XML.test(ct)
+        try
+          dom = xmlParser.parse $scope.res.response
+          promises.push TreeParsing.parseDOMElem(dom.documentElement)
+        catch e
+          $log.error 'Error parsing xml', e
+
+    if promises.length
+      $q.all(promises)
+        .then((parsed) -> TreeParsing.expandTree parsed, not $scope.tree.expanded)
+        .then setTree, $log.error
+
+  $scope.browseable = APPL_JSON.test(ct) or APPL_XML.test(ct) or TEXT_XML.test(ct)
+
+  $scope.isHTML = TEXT_HTML.test ct
 
   processingInstructions = /<\?[^?]*\?>/g
   $scope.cleanHTML = $scope.res.response.replace(processingInstructions, '')


getCurrentValue = (ps, name) -> return p.currentValue for p in ps when p.Name is name


Controllers.controller 'MethodCtrl', ($scope, $q, $log, $http, Suggestions, Defaults, ParamUtils, Storage, parameterHistoryKey, Counter, Markdown) ->
  $scope.params = angular.copy($scope.m.parameters)

  do initParams = ->

    return $location.path '/'

  m.active = false for m in $scope.endpoint.methods
  $scope.currentMethod.active = true

  $log.debug 'CURRENT METHOD', $scope.currentMethod

