提交 55f0c1a2 编写于 作者: T Tony Tam

Merge pull request #95 from pose/json-response-pretty-print

Adding JSON sample UI to response
......@@ -445,6 +445,7 @@
}
if (this.responseClass != null) {
this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
}
this.errorResponses = this.errorResponses || [];
_ref1 = this.parameters;
......
......@@ -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>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册