diff --git a/src/main/javascript/view/OperationView.js b/src/main/javascript/view/OperationView.js index f39d2c3d..502b5c27 100644 --- a/src/main/javascript/view/OperationView.js +++ b/src/main/javascript/view/OperationView.js @@ -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('
'); + $('.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); } @@ -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(''); - $('.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 = {};