This commit is contained in:
Tony Tam
2013-07-17 16:02:47 -07:00
parent e72dbd6bc6
commit df20d2bd5e
6 changed files with 67 additions and 16 deletions

View File

@@ -41,7 +41,12 @@ class SwaggerUi extends Backbone.Router
load: ->
# Initialize the API object
@mainView?.clear()
@headerView.update(@options.url)
url = @options.url
if url.indexOf("http") isnt 0
url = @buildUrl(window.location.href.toString(), url)
@options.url = url
@headerView.update(url)
@api = new SwaggerApi(@options)
@api.build()
@api
@@ -62,6 +67,16 @@ class SwaggerUi extends Backbone.Router
400
)
buildUrl: (base, url) ->
console.log "base is " + base
parts = base.split("/")
base = parts[0] + "//" + parts[2]
if url.indexOf("/") is 0
base + url
else
base + "/" + url
# Shows message on topbar of the ui
showMessage: (data = '') ->
$('#message-bar').removeClass 'message-fail'

View File

@@ -31,6 +31,13 @@ class OperationView extends Backbone.View
contentTypeModel.consumes = @model.consumes
contentTypeModel.produces = @model.produces
for param in @model.parameters
console.log "looking at " + param.dataType
if param.dataType.toLowerCase() == 'file'
if !contentTypeModel.consumes
console.log "set content type "
contentTypeModel.consumes = 'multipart/form-data'
responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel})
$('.response-content-type', $(@el)).append responseContentTypeView.render().el
@@ -74,7 +81,7 @@ class OperationView extends Backbone.View
#if(o.value? && jQuery.trim(o.value).length > 0)
#map[o.name] = o.value
for o in form.find(".body-textarea,.parameter")
for o in form.find("input")
if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = encodeURI(o.value)

View File

@@ -3,7 +3,7 @@ class ParameterView extends Backbone.View
render: ->
@model.isBody = true if @model.paramType == 'body'
@model.isFile = true if @model.dataType == 'file'
@model.isFile = true if @model.dataType.toLowerCase() == 'file'
template = @template()
$(@el).html(template(@model))

View File

@@ -4,6 +4,7 @@
{{#if isBody}}
{{#if isFile}}
<input type="file" name='{{name}}'/>
<div class="parameter-content-type" />
{{else}}
{{#if defaultValue}}
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea>