merged pull request #42 from @tim-vandecasteele

This commit is contained in:
Ayush Gupta
2012-11-15 11:01:28 +05:30
parent 086b24bb04
commit 2bfa39295a
4 changed files with 43 additions and 14 deletions

View File

@@ -52,6 +52,23 @@ class OperationView extends Backbone.View
if(o.value? && jQuery.trim(o.value).length > 0) if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = o.value map[o.name] = o.value
isFileUpload = $('input[type~="file"]').size != 0
if isFileUpload
# requires HTML5 compatible browser
bodyParam = new FormData()
# add params
for param in @model.parameters
if param.paramType is 'body'
bodyParam.append(param.name, map[param.name])
# add files
$.each $('input[type~="file"]'), (i, el) ->
bodyParam.append($(el).attr('name'), el.files[0])
console.log(bodyParam)
else
bodyParam = null bodyParam = null
for param in @model.parameters for param in @model.parameters
if param.paramType is 'body' if param.paramType is 'body'
@@ -79,6 +96,7 @@ class OperationView extends Backbone.View
headers: headerParams headers: headerParams
data: bodyParam data: bodyParam
dataType: 'json' dataType: 'json'
processData: false
error: (xhr, textStatus, error) => error: (xhr, textStatus, error) =>
@showErrorStatus(xhr, textStatus, error) @showErrorStatus(xhr, textStatus, error)
success: (data) => success: (data) =>
@@ -87,7 +105,7 @@ class OperationView extends Backbone.View
@showCompleteStatus(data) @showCompleteStatus(data)
obj.contentType = "application/json" if (obj.type.toLowerCase() == "put" or obj.type.toLowerCase() == "patch") obj.contentType = "application/json" if (obj.type.toLowerCase() == "put" or obj.type.toLowerCase() == "patch")
obj.contentType = false if isFileUpload
jQuery.ajax(obj) jQuery.ajax(obj)
false false
# $.getJSON(invocationUrl, (r) => @showResponse(r)).complete((r) => @showCompleteStatus(r)).error (r) => @showErrorStatus(r) # $.getJSON(invocationUrl, (r) => @showResponse(r)).complete((r) => @showCompleteStatus(r)).error (r) => @showErrorStatus(r)

View File

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

View File

@@ -1,13 +1,16 @@
<td class='code'>{{name}}</td> <td class='code'>{{name}}</td>
<td> <td>
{{#if isBody}} {{#if isBody}}
{{#if defaultValue}} {{#if isFile}}
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea> <input type="file" name='{{name}}'/>
{{else}} {{else}}
<textarea class='body-textarea' name='{{name}}'></textarea> {{#if defaultValue}}
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea>
{{else}}
<textarea class='body-textarea' name='{{name}}'></textarea>
{{/if}}
{{/if}} {{/if}}
{{else}} {{else}}
{{#if defaultValue}} {{#if defaultValue}}
<input minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/> <input minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/>

View File

@@ -1,21 +1,28 @@
<td class='code required'>{{name}}</td> <td class='code required'>{{name}}</td>
<td> <td>
{{#if isBody}} {{#if isBody}}
{{#if defaultValue}} {{#if isFile}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'>{{defaultValue}}</textarea> <input type="file" name='{{name}}'/>
{{else}} {{else}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea> {{#if defaultValue}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'>{{defaultValue}}</textarea>
{{else}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea>
{{/if}}
{{/if}} {{/if}}
{{else}} {{else}}
{{#if defaultValue}} {{#if isFile}}
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value='{{defaultValue}}'/> <input class='required' type='file' name='{{name}}'/>
{{else}} {{else}}
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value=''/> {{#if defaultValue}}
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value='{{defaultValue}}'/>
{{else}}
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value=''/>
{{/if}}
{{/if}} {{/if}}
{{/if}} {{/if}}
</td> </td>
<td> <td>
<strong>{{{description}}}</strong> <strong>{{{description}}}</strong>
</td> </td>
<td><span class="model-signature">{{{signature}}}</span></td> <td><span class="model-signature">{{{signature}}}</span></td>