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)
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
for param in @model.parameters
if param.paramType is 'body'
@@ -79,6 +96,7 @@ class OperationView extends Backbone.View
headers: headerParams
data: bodyParam
dataType: 'json'
processData: false
error: (xhr, textStatus, error) =>
@showErrorStatus(xhr, textStatus, error)
success: (data) =>
@@ -87,7 +105,7 @@ class OperationView extends Backbone.View
@showCompleteStatus(data)
obj.contentType = "application/json" if (obj.type.toLowerCase() == "put" or obj.type.toLowerCase() == "patch")
obj.contentType = false if isFileUpload
jQuery.ajax(obj)
false
# $.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: ->
@model.isBody = true if @model.paramType == 'body'
@model.isFile = true if @model.dataType == 'file'
template = @template()
$(@el).html(template(@model))

View File

@@ -2,12 +2,15 @@
<td>
{{#if isBody}}
{{#if defaultValue}}
<textarea class='body-textarea' name='{{name}}'>{{defaultValue}}</textarea>
{{#if isFile}}
<input type="file" name='{{name}}'/>
{{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}}
{{else}}
{{#if defaultValue}}
<input minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/>

View File

@@ -1,17 +1,24 @@
<td class='code required'>{{name}}</td>
<td>
{{#if isBody}}
{{#if defaultValue}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'>{{defaultValue}}</textarea>
{{#if isFile}}
<input type="file" name='{{name}}'/>
{{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}}
{{else}}
{{#if defaultValue}}
<input class='required' minlength='1' name='{{name}}' placeholder='(required)' type='text' value='{{defaultValue}}'/>
{{#if isFile}}
<input class='required' type='file' name='{{name}}'/>
{{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}}
</td>