Merge pull request #95 from pose/json-response-pretty-print
Adding JSON sample UI to response
This commit is contained in:
@@ -14,6 +14,18 @@ class OperationView extends Backbone.View
|
||||
|
||||
$(@el).html(Handlebars.templates.operation(@model))
|
||||
|
||||
if @model.responseClassSignature and @model.responseClassSignature != 'string'
|
||||
signatureModel =
|
||||
sampleJSON: @model.responseSampleJSON
|
||||
isParam: false
|
||||
signature: @model.responseClassSignature
|
||||
|
||||
responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'})
|
||||
$('.model-signature', $(@el)).append responseSignatureView.render().el
|
||||
else
|
||||
$('.model-signature', $(@el)).html(@model.responseClass)
|
||||
|
||||
|
||||
# Render each parameter
|
||||
@addParameter param for param in @model.parameters
|
||||
|
||||
|
||||
@@ -8,8 +8,13 @@ class ParameterView extends Backbone.View
|
||||
template = @template()
|
||||
$(@el).html(template(@model))
|
||||
|
||||
signatureModel =
|
||||
sampleJSON: @model.sampleJSON
|
||||
isParam: true
|
||||
signature: @model.signature
|
||||
|
||||
if @model.sampleJSON
|
||||
signatureView = new SignatureView({model: @model, tagName: 'div'})
|
||||
signatureView = new SignatureView({model: signatureModel, tagName: 'div'})
|
||||
$('.model-signature', $(@el)).append signatureView.render().el
|
||||
else
|
||||
$('.model-signature', $(@el)).html(@model.signature)
|
||||
|
||||
@@ -13,6 +13,11 @@ class SignatureView extends Backbone.View
|
||||
|
||||
@switchToDescription()
|
||||
|
||||
@isParam = @model.isParam
|
||||
|
||||
if @isParam
|
||||
$('.notice', $(@el)).text('Click to set as parameter value')
|
||||
|
||||
@
|
||||
|
||||
template: ->
|
||||
@@ -36,8 +41,11 @@ class SignatureView extends Backbone.View
|
||||
|
||||
# handler for snippet to text area
|
||||
snippetToTextArea: (e) ->
|
||||
e?.preventDefault()
|
||||
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
|
||||
if $.trim(textArea.val()) == ''
|
||||
if @isParam
|
||||
e?.preventDefault()
|
||||
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
|
||||
if $.trim(textArea.val()) == ''
|
||||
textArea.val(@model.sampleJSON)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,12 +22,8 @@
|
||||
<p>{{{notes}}}</p>
|
||||
{{/if}}
|
||||
{{#if responseClass}}
|
||||
<h4>Response Class</h4>
|
||||
{{#if responseClassSignature}}
|
||||
<p><span class="model-signature">{{{responseClassSignature}}}</span></p>
|
||||
{{else}}
|
||||
<p>{{{responseClass}}}</p>
|
||||
{{/if}}
|
||||
<h4>Response Model</h4>
|
||||
<span class="model-signature"></span>
|
||||
{{/if}}
|
||||
<form accept-charset='UTF-8' class='sandbox'>
|
||||
<div style='margin:0;padding:0;display:inline'></div>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<div class="snippet">
|
||||
<pre><code>{{sampleJSON}}</code></pre>
|
||||
<small>Click to set as parameter value</small>
|
||||
<small class="notice"></small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user