closes #84
This commit is contained in:
@@ -134,7 +134,7 @@ class OperationView extends Backbone.View
|
||||
# puts the response data in UI
|
||||
showStatus: (data) ->
|
||||
try
|
||||
response_body = "<pre>" + JSON.stringify(JSON.parse(data.responseText), null, 2).replace(/\n/g, "<br>") + "</pre>"
|
||||
response_body = '<pre class="json"><code>' + JSON.stringify(JSON.parse(data.responseText), null, 2) + "</code></pre>"
|
||||
catch error
|
||||
response_body = "<span style='color:red'> [unable to parse as json; raw response below]</span><br><pre>" + data.responseText + "</pre>"
|
||||
$(".response_code", $(@el)).html "<pre>" + data.status + "</pre>"
|
||||
@@ -143,6 +143,7 @@ class OperationView extends Backbone.View
|
||||
$(".response", $(@el)).slideDown()
|
||||
$(".response_hider", $(@el)).show()
|
||||
$(".response_throbber", $(@el)).hide()
|
||||
hljs.highlightBlock($('.response_body', $(@el))[0])
|
||||
|
||||
toggleOperationContent: ->
|
||||
elem = $('#' + @model.resourceName + "_" + @model.nickname + "_" + @model.httpMethod + "_content");
|
||||
|
||||
@@ -8,6 +8,12 @@ class ParameterView extends Backbone.View
|
||||
template = @template()
|
||||
$(@el).html(template(@model))
|
||||
|
||||
if @model.sampleJSON
|
||||
signatureView = new SignatureView({model: @model, tagName: 'div'})
|
||||
$('.model-signature', $(@el)).append signatureView.render().el
|
||||
else
|
||||
$('.model-signature', $(@el)).html(@model.signature)
|
||||
|
||||
@
|
||||
|
||||
# Return an appropriate template based on if the parameter is a list, readonly, required
|
||||
|
||||
43
src/main/coffeescript/view/SignatureView.coffee
Normal file
43
src/main/coffeescript/view/SignatureView.coffee
Normal file
@@ -0,0 +1,43 @@
|
||||
class SignatureView extends Backbone.View
|
||||
events: {
|
||||
'click a.description-link' : 'switchToDescription'
|
||||
'click a.snippet-link' : 'switchToSnippet'
|
||||
'mousedown .snippet' : 'snippetToTextArea'
|
||||
}
|
||||
|
||||
initialize: ->
|
||||
|
||||
render: ->
|
||||
template = @template()
|
||||
$(@el).html(template(@model))
|
||||
|
||||
@switchToDescription()
|
||||
|
||||
@
|
||||
|
||||
template: ->
|
||||
Handlebars.templates.signature
|
||||
|
||||
# handler for show signature
|
||||
switchToDescription: (e) ->
|
||||
e?.preventDefault()
|
||||
$(".snippet", $(@el)).hide()
|
||||
$(".description", $(@el)).show()
|
||||
$('.description-link', $(@el)).addClass('selected')
|
||||
$('.snippet-link', $(@el)).removeClass('selected')
|
||||
|
||||
# handler for show sample
|
||||
switchToSnippet: (e) ->
|
||||
e?.preventDefault()
|
||||
$(".description", $(@el)).hide()
|
||||
$(".snippet", $(@el)).show()
|
||||
$('.snippet-link', $(@el)).addClass('selected')
|
||||
$('.description-link', $(@el)).removeClass('selected')
|
||||
|
||||
# handler for snippet to text area
|
||||
snippetToTextArea: (e) ->
|
||||
e?.preventDefault()
|
||||
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
|
||||
if $.trim(textArea.val()) == ''
|
||||
textArea.val(@model.sampleJSON)
|
||||
|
||||
Reference in New Issue
Block a user