fix for #288
This commit is contained in:
96
dist/swagger-ui.js
vendored
96
dist/swagger-ui.js
vendored
@@ -1470,6 +1470,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
return _ref4;
|
||||
}
|
||||
|
||||
OperationView.prototype.invocationUrl = null;
|
||||
|
||||
OperationView.prototype.events = {
|
||||
'submit .sandbox': 'submitOperation',
|
||||
'click .submit': 'submitOperation',
|
||||
@@ -1554,7 +1556,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
};
|
||||
|
||||
OperationView.prototype.submitOperation = function(e) {
|
||||
var error_free, form, map, o, opts, val, _i, _j, _k, _len, _len1, _len2, _ref5, _ref6, _ref7;
|
||||
var error_free, form, isFileUpload, map, o, opts, val, _i, _j, _k, _len, _len1, _len2, _ref5, _ref6, _ref7;
|
||||
if (e != null) {
|
||||
e.preventDefault();
|
||||
}
|
||||
@@ -1578,12 +1580,16 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
opts = {
|
||||
parent: this
|
||||
};
|
||||
isFileUpload = false;
|
||||
_ref5 = form.find("input");
|
||||
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
||||
o = _ref5[_i];
|
||||
if ((o.value != null) && jQuery.trim(o.value).length > 0) {
|
||||
map[o.name] = o.value;
|
||||
}
|
||||
if (o.type === "file") {
|
||||
isFileUpload = true;
|
||||
}
|
||||
}
|
||||
_ref6 = form.find("textarea");
|
||||
for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
|
||||
@@ -1603,7 +1609,11 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
opts.responseContentType = $("div select[name=responseContentType]", $(this.el)).val();
|
||||
opts.requestContentType = $("div select[name=parameterContentType]", $(this.el)).val();
|
||||
$(".response_throbber", $(this.el)).show();
|
||||
return this.model["do"](map, opts, this.showCompleteStatus, this.showErrorStatus, this);
|
||||
if (isFileUpload) {
|
||||
return this.handleFileUpload(map, form);
|
||||
} else {
|
||||
return this.model["do"](map, opts, this.showCompleteStatus, this.showErrorStatus, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1611,6 +1621,82 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
return parent.showCompleteStatus(response);
|
||||
};
|
||||
|
||||
OperationView.prototype.handleFileUpload = function(map, form) {
|
||||
var bodyParam, headerParams, o, obj, param, _i, _j, _k, _len, _len1, _len2, _ref5, _ref6, _ref7,
|
||||
_this = this;
|
||||
console.log("it's a file upload");
|
||||
_ref5 = form.serializeArray();
|
||||
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
||||
o = _ref5[_i];
|
||||
if ((o.value != null) && jQuery.trim(o.value).length > 0) {
|
||||
map[o.name] = o.value;
|
||||
}
|
||||
}
|
||||
bodyParam = new FormData();
|
||||
_ref6 = this.model.parameters;
|
||||
for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
|
||||
param = _ref6[_j];
|
||||
if (param.paramType === 'form') {
|
||||
bodyParam.append(param.name, map[param.name]);
|
||||
}
|
||||
}
|
||||
headerParams = {};
|
||||
_ref7 = this.model.parameters;
|
||||
for (_k = 0, _len2 = _ref7.length; _k < _len2; _k++) {
|
||||
param = _ref7[_k];
|
||||
if (param.paramType === 'header') {
|
||||
headerParams[param.name] = map[param.name];
|
||||
}
|
||||
}
|
||||
console.log(headerParams);
|
||||
$.each($('input[type~="file"]'), function(i, el) {
|
||||
return bodyParam.append($(el).attr('name'), el.files[0]);
|
||||
});
|
||||
console.log(bodyParam);
|
||||
this.invocationUrl = this.model.supportHeaderParams() ? (headerParams = this.model.getHeaderParams(map), this.model.urlify(map, false)) : this.model.urlify(map, true);
|
||||
$(".request_url", $(this.el)).html("<pre>" + this.invocationUrl + "</pre>");
|
||||
obj = {
|
||||
type: this.model.method,
|
||||
url: this.invocationUrl,
|
||||
headers: headerParams,
|
||||
data: bodyParam,
|
||||
dataType: 'json',
|
||||
contentType: false,
|
||||
processData: false,
|
||||
error: function(data, textStatus, error) {
|
||||
return _this.showErrorStatus(_this.wrap(data), _this);
|
||||
},
|
||||
success: function(data) {
|
||||
return _this.showResponse(data, _this);
|
||||
},
|
||||
complete: function(data) {
|
||||
return _this.showCompleteStatus(_this.wrap(data), _this);
|
||||
}
|
||||
};
|
||||
if (window.authorizations) {
|
||||
window.authorizations.apply(obj);
|
||||
}
|
||||
jQuery.ajax(obj);
|
||||
return false;
|
||||
};
|
||||
|
||||
OperationView.prototype.wrap = function(data) {
|
||||
var o,
|
||||
_this = this;
|
||||
o = {};
|
||||
o.content = {};
|
||||
o.content.data = data.responseText;
|
||||
o.getHeaders = function() {
|
||||
return {
|
||||
"Content-Type": data.getResponseHeader("Content-Type")
|
||||
};
|
||||
};
|
||||
o.request = {};
|
||||
o.request.url = this.invocationUrl;
|
||||
o.status = data.status;
|
||||
return o;
|
||||
};
|
||||
|
||||
OperationView.prototype.getSelectedValue = function(select) {
|
||||
var opt, options, _i, _len, _ref5;
|
||||
if (!select.multiple) {
|
||||
@@ -1744,15 +1830,17 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
} else if (contentType.indexOf("text/html") === 0) {
|
||||
code = $('<code />').html(content);
|
||||
pre = $('<pre class="xml" />').append(code);
|
||||
} else if (contentType.indexOf("image/") === 0) {
|
||||
pre = $('<img>').attr('src', data.request.url);
|
||||
} else {
|
||||
code = $('<code />').text(content);
|
||||
pre = $('<pre class="json" />').append(code);
|
||||
}
|
||||
response_body = pre;
|
||||
$(".request_url").html("<pre>" + data.request.url + "</pre>");
|
||||
$(".request_url", $(this.el)).html("<pre>" + data.request.url + "</pre>");
|
||||
$(".response_code", $(this.el)).html("<pre>" + data.status + "</pre>");
|
||||
$(".response_body", $(this.el)).html(response_body);
|
||||
$(".response_headers", $(this.el)).html("<pre>" + JSON.stringify(data.getHeaders()) + "</pre>");
|
||||
$(".response_headers", $(this.el)).html("<pre>" + JSON.stringify(data.getHeaders(), null, " ").replace(/\n/g, "<br>") + "</pre>");
|
||||
$(".response", $(this.el)).slideDown();
|
||||
$(".response_hider", $(this.el)).show();
|
||||
$(".response_throbber", $(this.el)).hide();
|
||||
|
||||
Reference in New Issue
Block a user