Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy committed Jun 4, 2015
2 parents 0e2102d + 8883821 commit 62afd58
Showing 1 changed file with 7 additions and 65 deletions.
72 changes: 7 additions & 65 deletions src/main/javascript/view/OperationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,13 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
opts.requestContentType = $('div select[name=parameterContentType]', $(this.el)).val();
$('.response_throbber', $(this.el)).show();
if (isFileUpload) {
return this.handleFileUpload(map, form);
$('.request_url', $(this.el)).html('<pre></pre>');
$('.request_url pre', $(this.el)).text(this.invocationUrl);

opts.useJQuery = true;
map.parameterContentType = 'multipart/form-data';

return this.model.execute(map, opts, this.showCompleteStatus, this.showErrorStatus, this);
} else {
return this.model.execute(map, opts, this.showCompleteStatus, this.showErrorStatus, this);
}
Expand Down Expand Up @@ -364,71 +370,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
parent.showCompleteStatus(response);
},

// Note: This is compiled code
// TODO: Refactor
handleFileUpload: function(map, form) {
var bodyParam, el, headerParams, l, len, len1, len3, m, o, p, param, params, ref1, ref2, ref4;
ref1 = form.serializeArray();
for (l = 0, len = ref1.length; l < len; l++) {
o = ref1[l];
if ((o.value !== null) && jQuery.trim(o.value).length > 0) {
map[o.name] = o.value;
}
}
bodyParam = new FormData();
params = 0;
ref2 = this.model.parameters;
for (m = 0, len1 = ref2.length; m < len1; m++) {
param = ref2[m];
if (param.paramType === 'form' || param['in'] === 'formData') {
if (param.type.toLowerCase() !== 'file' && map[param.name] !== void 0) {
bodyParam.append(param.name, map[param.name]);
}
}
}
ref4 = form.find('input[type~="file"]');
for (p = 0, len3 = ref4.length; p < len3; p++) {
el = ref4[p];
if (typeof el.files[0] !== 'undefined') {
bodyParam.append($(el).attr('name'), el.files[0]);
params += 1;
}
}
this.invocationUrl = this.model.supportHeaderParams() ? (headerParams = this.model.getHeaderParams(map), delete headerParams['Content-Type'], this.model.urlify(map, false)) : this.model.urlify(map, true);
$('.request_url', $(this.el)).html('<pre></pre>');
$('.request_url pre', $(this.el)).text(this.invocationUrl);

// TODO: don't use jQuery. Use SwaggerJS for handling the call.
var obj = {
type: this.model.method,
url: this.invocationUrl,
headers: headerParams,
data: bodyParam,
dataType: 'json',
contentType: false,
processData: false,
error: (function(_this) {
return function(data) {
return _this.showErrorStatus(_this.wrap(data), _this);
};
})(this),
success: (function(_this) {
return function(data) {
return _this.showResponse(data, _this);
};
})(this),
complete: (function(_this) {
return function(data) {
return _this.showCompleteStatus(_this.wrap(data), _this);
};
})(this)
};
jQuery.ajax(obj);
return false;
// end of file-upload nastiness
},
// wraps a jquery response as a shred response

wrap: function(data) {
var h, headerArray, headers, i, l, len, o;
headers = {};
Expand Down

0 comments on commit 62afd58

Please sign in to comment.