diff --git a/dist/index.html b/dist/index.html index 2f092c1f..481b4cca 100644 --- a/dist/index.html +++ b/dist/index.html @@ -5,7 +5,7 @@ - + diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index 4589cc51..56f284a2 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -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("
" + this.invocationUrl + ""); + 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 = $('
').html(content);
pre = $('').append(code);
+ } else if (contentType.indexOf("image/") === 0) {
+ pre = $('').text(content);
pre = $('').append(code);
}
response_body = pre;
- $(".request_url").html("" + data.request.url + ""); + $(".request_url", $(this.el)).html("
" + data.request.url + ""); $(".response_code", $(this.el)).html("
" + data.status + ""); $(".response_body", $(this.el)).html(response_body); - $(".response_headers", $(this.el)).html("
" + JSON.stringify(data.getHeaders()) + ""); + $(".response_headers", $(this.el)).html("
" + JSON.stringify(data.getHeaders(), null, " ").replace(/\n/g, ""); $(".response", $(this.el)).slideDown(); $(".response_hider", $(this.el)).show(); $(".response_throbber", $(this.el)).hide(); diff --git a/dist/swagger-ui.min.js b/dist/swagger-ui.min.js index df0b1545..be2c1052 100644 --- a/dist/swagger-ui.min.js +++ b/dist/swagger-ui.min.js @@ -1 +1 @@ -$(function(){$.fn.vAlign=function(){return this.each(function(c){var a=$(this).height();var d=$(this).parent().height();var b=(d-a)/2;$(this).css("margin-top",b)})};$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(b){var d=$(this).closest("form").innerWidth();var c=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10);var a=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",d-c-a)})};$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent();$("ul.downplayed li div.content p").vAlign();$("form.sandbox").submit(function(){var a=true;$(this).find("input.required").each(function(){$(this).removeClass("error");if($(this).val()==""){$(this).addClass("error");$(this).wiggle();a=false}});return a})});function clippyCopiedCallback(b){$("#api_key_copied").fadeIn().delay(1000).fadeOut()}function log(){if(window.console){console.log.apply(console,arguments)}}if(Function.prototype.bind&&console&&typeof console.log=="object"){["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(a){console[a]=this.bind(console[a],console)},Function.prototype.call)}var Docs={shebang:function(){var b=$.param.fragment().split("/");b.shift();switch(b.length){case 1:var d="resource_"+b[0];Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});break;case 2:Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});var c=b.join("_");var a=c+"_content";Docs.expandOperation($("#"+a));$("#"+c).slideto({highlight:false});break}},toggleEndpointListForResource:function(b){var a=$("li#resource_"+Docs.escapeResourceName(b)+" ul.endpoints");if(a.is(":visible")){Docs.collapseEndpointListForResource(b)}else{Docs.expandEndpointListForResource(b)}},expandEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);if(b==""){$(".resource ul.endpoints").slideDown();return}$("li#resource_"+b).addClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideDown()},collapseEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);$("li#resource_"+b).removeClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideUp()},expandOperationsForResource:function(a){Docs.expandEndpointListForResource(a);if(a==""){$(".resource ul.endpoints li.operation div.content").slideDown();return}$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(a){Docs.expandEndpointListForResource(a);$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(a){return a.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(a){a.slideDown()},collapseOperation:function(a){a.slideUp()}};(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.content_type=b(function(g,l,f,k,j){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);j=j||{};var i="",c,h="function",m=this;function e(r,q){var o="",p;o+="\n ";p=f.each.call(r,r.produces,{hash:{},inverse:m.noop,fn:m.program(2,d,q),data:q});if(p||p===0){o+=p}o+="\n";return o}function d(r,q){var o="",p;o+='\n \n ";return o}function n(p,o){return'\n \n'}i+='\n\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.main=b(function(g,m,f,l,k){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);k=k||{};var i="",c,h="function",j=this.escapeExpression,p=this;function e(v,u){var r="",t,s;r+='\n
") + "
";if(t=g.notes){t=t.call(v,{hash:{},data:u})}else{t=v.notes;t=typeof t===i?t.apply(v):t}if(t||t===0){s+=t}s+="
\n ";return s}function c(t,s){return'\n\n
| Parameter | \nValue | \nDescription | \nParameter Type | \nData Type | \n
|---|
| HTTP Status Code | \nReason | \n
|---|
';if(c=d.sampleJSON){c=c.call(k,{hash:{},data:i})}else{c=k.sampleJSON;c=typeof c===f?c.apply(k):c}g+=h(c)+'\n \n ").text(JSON.stringify(JSON.parse(B),null,2));E=$('').append(C)}else{if(G.indexOf("application/xml")===0){C=$("").text(this.formatXml(B));E=$('').append(C)}else{if(G.indexOf("text/html")===0){C=$("").html(B);E=$('').append(C)}else{C=$("").text(B);E=$('').append(C)}}}}A=E;$(".request_url").html(""+D.request.url+"");$(".response_code",$(this.el)).html("
"+D.status+"");$(".response_body",$(this.el)).html(A);$(".response_headers",$(this.el)).html("
"+JSON.stringify(D.getHeaders())+"");$(".response",$(this.el)).slideDown();$(".response_hider",$(this.el)).show();$(".response_throbber",$(this.el)).hide();return hljs.highlightBlock($(".response_body",$(this.el))[0])};y.prototype.toggleOperationContent=function(){var A;A=$("#"+Docs.escapeResourceName(this.model.resourceName)+"_"+this.model.nickname+"_"+this.model.method+"_"+this.model.number+"_content");if(A.is(":visible")){return Docs.collapseOperation(A)}else{return Docs.expandOperation(A)}};return y})(Backbone.View);p=(function(z){v(y,z);function y(){d=y.__super__.constructor.apply(this,arguments);return d}y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));return this};y.prototype.template=function(){return Handlebars.templates.status_code};return y})(Backbone.View);k=(function(z){v(y,z);function y(){b=y.__super__.constructor.apply(this,arguments);return b}y.prototype.initialize=function(){};y.prototype.render=function(){var G,A,C,F,B,H,E,D;D=this.model.type||this.model.dataType;if(this.model.paramType==="body"){this.model.isBody=true}if(D.toLowerCase()==="file"){this.model.isFile=true}E=this.template();$(this.el).html(E(this.model));B={sampleJSON:this.model.sampleJSON,isParam:true,signature:this.model.signature};if(this.model.sampleJSON){H=new i({model:B,tagName:"div"});$(".model-signature",$(this.el)).append(H.render().el)}else{$(".model-signature",$(this.el)).html(this.model.signature)}A=false;if(this.model.isBody){A=true}G={isParam:A};G.consumes=this.model.consumes;if(A){C=new l({model:G});$(".parameter-content-type",$(this.el)).append(C.render().el)}else{F=new m({model:G});$(".response-content-type",$(this.el)).append(F.render().el)}return this};y.prototype.template=function(){if(this.model.isList){return Handlebars.templates.param_list}else{if(this.options.readOnly){if(this.model.required){return Handlebars.templates.param_readonly_required}else{return Handlebars.templates.param_readonly}}else{if(this.model.required){return Handlebars.templates.param_required}else{return Handlebars.templates.param}}}};return y})(Backbone.View);i=(function(z){v(y,z);function y(){a=y.__super__.constructor.apply(this,arguments);return a}y.prototype.events={"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"};y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));this.switchToDescription();this.isParam=this.model.isParam;if(this.isParam){$(".notice",$(this.el)).text("Click to set as parameter value")}return this};y.prototype.template=function(){return Handlebars.templates.signature};y.prototype.switchToDescription=function(A){if(A!=null){A.preventDefault()}$(".snippet",$(this.el)).hide();$(".description",$(this.el)).show();$(".description-link",$(this.el)).addClass("selected");return $(".snippet-link",$(this.el)).removeClass("selected")};y.prototype.switchToSnippet=function(A){if(A!=null){A.preventDefault()}$(".description",$(this.el)).hide();$(".snippet",$(this.el)).show();$(".snippet-link",$(this.el)).addClass("selected");return $(".description-link",$(this.el)).removeClass("selected")};y.prototype.snippetToTextArea=function(A){var B;if(this.isParam){if(A!=null){A.preventDefault()}B=$("textarea",$(this.el.parentNode.parentNode.parentNode));if($.trim(B.val())===""){return B.val(this.model.sampleJSON)}}};return y})(Backbone.View);j=(function(y){v(z,y);function z(){x=z.__super__.constructor.apply(this,arguments);return x}z.prototype.initialize=function(){};z.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=contentType]",$(this.el)).text("Response Content Type");return this};z.prototype.template=function(){return Handlebars.templates.content_type};return z})(Backbone.View);m=(function(y){v(z,y);function z(){w=z.__super__.constructor.apply(this,arguments);return w}z.prototype.initialize=function(){};z.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=responseContentType]",$(this.el)).text("Response Content Type");return this};z.prototype.template=function(){return Handlebars.templates.response_content_type};return z})(Backbone.View);l=(function(z){v(y,z);function y(){c=y.__super__.constructor.apply(this,arguments);return c}y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:");return this};y.prototype.template=function(){return Handlebars.templates.parameter_content_type};return y})(Backbone.View)}).call(this); \ No newline at end of file +$(function(){$.fn.vAlign=function(){return this.each(function(c){var a=$(this).height();var d=$(this).parent().height();var b=(d-a)/2;$(this).css("margin-top",b)})};$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(b){var d=$(this).closest("form").innerWidth();var c=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10);var a=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",d-c-a)})};$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent();$("ul.downplayed li div.content p").vAlign();$("form.sandbox").submit(function(){var a=true;$(this).find("input.required").each(function(){$(this).removeClass("error");if($(this).val()==""){$(this).addClass("error");$(this).wiggle();a=false}});return a})});function clippyCopiedCallback(b){$("#api_key_copied").fadeIn().delay(1000).fadeOut()}function log(){if(window.console){console.log.apply(console,arguments)}}if(Function.prototype.bind&&console&&typeof console.log=="object"){["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(a){console[a]=this.bind(console[a],console)},Function.prototype.call)}var Docs={shebang:function(){var b=$.param.fragment().split("/");b.shift();switch(b.length){case 1:var d="resource_"+b[0];Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});break;case 2:Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});var c=b.join("_");var a=c+"_content";Docs.expandOperation($("#"+a));$("#"+c).slideto({highlight:false});break}},toggleEndpointListForResource:function(b){var a=$("li#resource_"+Docs.escapeResourceName(b)+" ul.endpoints");if(a.is(":visible")){Docs.collapseEndpointListForResource(b)}else{Docs.expandEndpointListForResource(b)}},expandEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);if(b==""){$(".resource ul.endpoints").slideDown();return}$("li#resource_"+b).addClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideDown()},collapseEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);$("li#resource_"+b).removeClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideUp()},expandOperationsForResource:function(a){Docs.expandEndpointListForResource(a);if(a==""){$(".resource ul.endpoints li.operation div.content").slideDown();return}$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(a){Docs.expandEndpointListForResource(a);$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(a){return a.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(a){a.slideDown()},collapseOperation:function(a){a.slideUp()}};(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.content_type=b(function(g,l,f,k,j){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);j=j||{};var i="",c,h="function",m=this;function e(r,q){var o="",p;o+="\n ";p=f.each.call(r,r.produces,{hash:{},inverse:m.noop,fn:m.program(2,d,q),data:q});if(p||p===0){o+=p}o+="\n";return o}function d(r,q){var o="",p;o+='\n \n ";return o}function n(p,o){return'\n \n'}i+='\n\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.main=b(function(g,m,f,l,k){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);k=k||{};var i="",c,h="function",j=this.escapeExpression,p=this;function e(v,u){var r="",t,s;r+='\n
";if(t=g.notes){t=t.call(v,{hash:{},data:u})}else{t=v.notes;t=typeof t===i?t.apply(v):t}if(t||t===0){s+=t}s+="
\n ";return s}function c(t,s){return'\n\n
| Parameter | \nValue | \nDescription | \nParameter Type | \nData Type | \n
|---|
| HTTP Status Code | \nReason | \n
|---|
';if(c=d.sampleJSON){c=c.call(k,{hash:{},data:i})}else{c=k.sampleJSON;c=typeof c===f?c.apply(k):c}g+=h(c)+'\n \n ").text(JSON.stringify(JSON.parse(B),null,2));E=$('').append(C)}else{if(G.indexOf("application/xml")===0){C=$("").text(this.formatXml(B));E=$('').append(C)}else{if(G.indexOf("text/html")===0){C=$("").html(B);E=$('').append(C)}else{if(G.indexOf("image/")===0){E=$("").text(B);E=$('').append(C)}}}}}A=E;$(".request_url",$(this.el)).html(""+D.request.url+"");$(".response_code",$(this.el)).html("
"+D.status+"");$(".response_body",$(this.el)).html(A);$(".response_headers",$(this.el)).html("
"+JSON.stringify(D.getHeaders(),null," ").replace(/\n/g,"");$(".response",$(this.el)).slideDown();$(".response_hider",$(this.el)).show();$(".response_throbber",$(this.el)).hide();return hljs.highlightBlock($(".response_body",$(this.el))[0])};y.prototype.toggleOperationContent=function(){var A;A=$("#"+Docs.escapeResourceName(this.model.resourceName)+"_"+this.model.nickname+"_"+this.model.method+"_"+this.model.number+"_content");if(A.is(":visible")){return Docs.collapseOperation(A)}else{return Docs.expandOperation(A)}};return y})(Backbone.View);p=(function(z){v(y,z);function y(){d=y.__super__.constructor.apply(this,arguments);return d}y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));return this};y.prototype.template=function(){return Handlebars.templates.status_code};return y})(Backbone.View);k=(function(z){v(y,z);function y(){b=y.__super__.constructor.apply(this,arguments);return b}y.prototype.initialize=function(){};y.prototype.render=function(){var G,A,C,F,B,H,E,D;D=this.model.type||this.model.dataType;if(this.model.paramType==="body"){this.model.isBody=true}if(D.toLowerCase()==="file"){this.model.isFile=true}E=this.template();$(this.el).html(E(this.model));B={sampleJSON:this.model.sampleJSON,isParam:true,signature:this.model.signature};if(this.model.sampleJSON){H=new i({model:B,tagName:"div"});$(".model-signature",$(this.el)).append(H.render().el)}else{$(".model-signature",$(this.el)).html(this.model.signature)}A=false;if(this.model.isBody){A=true}G={isParam:A};G.consumes=this.model.consumes;if(A){C=new l({model:G});$(".parameter-content-type",$(this.el)).append(C.render().el)}else{F=new m({model:G});$(".response-content-type",$(this.el)).append(F.render().el)}return this};y.prototype.template=function(){if(this.model.isList){return Handlebars.templates.param_list}else{if(this.options.readOnly){if(this.model.required){return Handlebars.templates.param_readonly_required}else{return Handlebars.templates.param_readonly}}else{if(this.model.required){return Handlebars.templates.param_required}else{return Handlebars.templates.param}}}};return y})(Backbone.View);i=(function(z){v(y,z);function y(){a=y.__super__.constructor.apply(this,arguments);return a}y.prototype.events={"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"};y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));this.switchToDescription();this.isParam=this.model.isParam;if(this.isParam){$(".notice",$(this.el)).text("Click to set as parameter value")}return this};y.prototype.template=function(){return Handlebars.templates.signature};y.prototype.switchToDescription=function(A){if(A!=null){A.preventDefault()}$(".snippet",$(this.el)).hide();$(".description",$(this.el)).show();$(".description-link",$(this.el)).addClass("selected");return $(".snippet-link",$(this.el)).removeClass("selected")};y.prototype.switchToSnippet=function(A){if(A!=null){A.preventDefault()}$(".description",$(this.el)).hide();$(".snippet",$(this.el)).show();$(".snippet-link",$(this.el)).addClass("selected");return $(".description-link",$(this.el)).removeClass("selected")};y.prototype.snippetToTextArea=function(A){var B;if(this.isParam){if(A!=null){A.preventDefault()}B=$("textarea",$(this.el.parentNode.parentNode.parentNode));if($.trim(B.val())===""){return B.val(this.model.sampleJSON)}}};return y})(Backbone.View);j=(function(y){v(z,y);function z(){x=z.__super__.constructor.apply(this,arguments);return x}z.prototype.initialize=function(){};z.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=contentType]",$(this.el)).text("Response Content Type");return this};z.prototype.template=function(){return Handlebars.templates.content_type};return z})(Backbone.View);m=(function(y){v(z,y);function z(){w=z.__super__.constructor.apply(this,arguments);return w}z.prototype.initialize=function(){};z.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=responseContentType]",$(this.el)).text("Response Content Type");return this};z.prototype.template=function(){return Handlebars.templates.response_content_type};return z})(Backbone.View);l=(function(z){v(y,z);function y(){c=y.__super__.constructor.apply(this,arguments);return c}y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:");return this};y.prototype.template=function(){return Handlebars.templates.parameter_content_type};return y})(Backbone.View)}).call(this); \ No newline at end of file diff --git a/src/main/coffeescript/view/OperationView.coffee b/src/main/coffeescript/view/OperationView.coffee index ff0472a9..e8000060 100644 --- a/src/main/coffeescript/view/OperationView.coffee +++ b/src/main/coffeescript/view/OperationView.coffee @@ -1,4 +1,6 @@ class OperationView extends Backbone.View + invocationUrl: null + events: { 'submit .sandbox' : 'submitOperation' 'click .submit' : 'submitOperation' @@ -77,13 +79,14 @@ class OperationView extends Backbone.View if error_free map = {} opts = {parent: @} - #for o in form.serializeArray() - #if(o.value? && jQuery.trim(o.value).length > 0) - #map[o.name] = o.value + + isFileUpload = false for o in form.find("input") if(o.value? && jQuery.trim(o.value).length > 0) map[o.name] = o.value + if o.type is "file" + isFileUpload = true for o in form.find("textarea") if(o.value? && jQuery.trim(o.value).length > 0) @@ -98,12 +101,85 @@ class OperationView extends Backbone.View opts.requestContentType = $("div select[name=parameterContentType]", $(@el)).val() $(".response_throbber", $(@el)).show() - - @model.do(map, opts, @showCompleteStatus, @showErrorStatus, @) + if isFileUpload + @handleFileUpload map, form + else + @model.do(map, opts, @showCompleteStatus, @showErrorStatus, @) success: (response, parent) -> parent.showCompleteStatus response - + + handleFileUpload: (map, form) -> + console.log "it's a file upload" + for o in form.serializeArray() + if(o.value? && jQuery.trim(o.value).length > 0) + map[o.name] = o.value + + # requires HTML5 compatible browser + bodyParam = new FormData() + + # add params + for param in @model.parameters + if param.paramType is 'form' + bodyParam.append(param.name, map[param.name]) + + # headers in operation + headerParams = {} + for param in @model.parameters + if param.paramType is 'header' + headerParams[param.name] = map[param.name] + + console.log headerParams + + # add files + $.each $('input[type~="file"]'), (i, el) -> + bodyParam.append($(el).attr('name'), el.files[0]) + + console.log(bodyParam) + + @invocationUrl = + if @model.supportHeaderParams() + headerParams = @model.getHeaderParams(map) + @model.urlify(map, false) + else + @model.urlify(map, true) + + $(".request_url", $(@el)).html "
")+"
" + @invocationUrl + "" + + obj = + type: @model.method + url: @invocationUrl + headers: headerParams + data: bodyParam + dataType: 'json' + contentType: false + processData: false + error: (data, textStatus, error) => + @showErrorStatus(@wrap(data), @) + success: (data) => + @showResponse(data, @) + complete: (data) => + @showCompleteStatus(@wrap(data), @) + + # apply authorizations + if window.authorizations + window.authorizations.apply obj + + jQuery.ajax(obj) + false + # end of file-upload nastiness + + # wraps a jquery response as a shred response + wrap: (data) -> + o = {} + o.content = {} + o.content.data = data.responseText + o.getHeaders = () => {"Content-Type": data.getResponseHeader("Content-Type")} + o.request = {} + o.request.url = @invocationUrl + o.status = data.status + o + getSelectedValue: (select) -> if !select.multiple select.value @@ -225,7 +301,7 @@ class OperationView extends Backbone.View $(".request_url", $(@el)).html "
" + data.request.url + "" $(".response_code", $(@el)).html "
" + data.status + "" $(".response_body", $(@el)).html response_body - $(".response_headers", $(@el)).html "
" + JSON.stringify(data.getHeaders()) + "" + $(".response_headers", $(@el)).html "
" + JSON.stringify(data.getHeaders(), null, " ").replace(/\n/g, "" $(".response", $(@el)).slideDown() $(".response_hider", $(@el)).show() $(".response_throbber", $(@el)).hide()
") + "