diff --git a/source/index.html.haml b/source/index.html.haml index bc50a1df..c7fe263d 100644 --- a/source/index.html.haml +++ b/source/index.html.haml @@ -71,6 +71,29 @@ %h4 Response Headers .block.response_headers += jquery_template :paramTemplate do + %tr + %td.code ${name} + %td + %input{:minlength => "0", :name => "${name}", :placeholder => "", :type => "text", :value => ""} + %td{:width => "500"} ${description} + + += jquery_template :paramTemplateSelect do + %tr + %td.code ${name} + %td + %select{:name => "${name}"} + {{each allowableValues}} + {{if $value == defaultValue }} + %option{:value => "${$value}", :selected => 'selected'} ${$value} + {{else}} + %option{:value => "${$value}"} ${$value} + {{/if}} + {{/each}} + + %td{:width => "500"} ${description} + = jquery_template :paramTemplateRequired do %tr %td.code.required ${name} @@ -79,13 +102,6 @@ %td{:width => "500"} %strong ${description} -= jquery_template :paramTemplate do - %tr - %td.code ${name} - %td - %input{:minlength => "0", :name => "${name}", :placeholder => "", :type => "text", :value => ""} - %td{:width => "500"} ${description} - = jquery_template :paramTemplateRequiredReadOnly do %tr %td.code.required ${name} diff --git a/source/javascripts/app.js b/source/javascripts/app.js index beafec11..6d9f93c1 100644 --- a/source/javascripts/app.js +++ b/source/javascripts/app.js @@ -6,4 +6,5 @@ //= require "jquery.wiggle.min" //= require "chosen.jquery" //= require "doc" -//= require "spine" +//= require "underscore-min" +//= require "spine" \ No newline at end of file diff --git a/source/javascripts/swagger-ui.js b/source/javascripts/swagger-ui.js index 82b94cbc..2ecc5a7c 100644 --- a/source/javascripts/swagger-ui.js +++ b/source/javascripts/swagger-ui.js @@ -215,6 +215,36 @@ jQuery(function($) { } }); + + // Param Model + // ---------------------------------------------------------------------------------------------- + var Param = Spine.Model.setup( + "Param", + ["name", "defaultValue", 'description', 'required', 'dataType', 'allowableValues', 'paramType', 'allowMultiple', "readOnly"] + ); + + Param.include({ + + cleanup: function() { + this.defaultValue = this.defaultValue || ''; + }, + + templateName: function(){ + var n = "#paramTemplate"; + + if (this.allowableValues && this.allowableValues.length > 0) { + n += "Select"; + } else { + if (this.required) n += "Required"; + if (this.readOnly) n += "ReadOnly"; + } + + return(n); + } + + }); + + var OperationController = Spine.Controller.create({ proxied: ["submitOperation", "showResponse", "showErrorStatus", "showCompleteStatus"], @@ -230,7 +260,6 @@ jQuery(function($) { this.elementScope = "#" + this.operation.apiName + "_" + this.operation.nickname + "_" + this.operation.httpMethod; this.renderParams(); - }, render: function() { @@ -240,19 +269,14 @@ jQuery(function($) { renderParams: function() { if (this.operation.parameters && this.operation.parameters.count() > 0) { var operationParamsContainer = this.elementScope + "_params"; - // log("operationParamsContainer = " + operationParamsContainer); + for (var p = 0; p < this.operation.parameters.count(); p++) { - var param = this.operation.parameters.all()[p]; - - var templateName = "#paramTemplate"; - if (param.required) - templateName += "Required"; - - if (!this.isGetOperation) - templateName += "ReadOnly"; - - $(templateName).tmpl(param).appendTo(operationParamsContainer); - // log("adding " + $(templateName).tmpl(param) + " TO " + operationParamsContainer); + var param = Param.init(this.operation.parameters.all()[p]); + // Only GET operations display forms.. + param.readOnly = !this.isGetOperation; + param.cleanup(); + + $(param.templateName()).tmpl(param).appendTo(operationParamsContainer); } } @@ -273,7 +297,7 @@ jQuery(function($) { var error_free = true; var missing_input = null; - // Cycle through the forms required inputs + // Cycle through the form's required inputs form.find("input.required").each(function() { // Remove any existing error styles from the input @@ -289,9 +313,7 @@ jQuery(function($) { } }); - - // log("error_free = " + error_free); - + if (error_free) { var invocationUrl = this.operation.invocationUrl(form.serializeArray()); $(".request_url", this.elementScope + "_content_sandbox_response").html("
" + invocationUrl + ""); diff --git a/source/javascripts/underscore-min.js b/source/javascripts/underscore-min.js new file mode 100644 index 00000000..5983694c --- /dev/null +++ b/source/javascripts/underscore-min.js @@ -0,0 +1,27 @@ +// Underscore.js 1.1.7 +// (c) 2011 Jeremy Ashkenas, DocumentCloud Inc. +// Underscore is freely distributable under the MIT license. +// Portions of Underscore are inspired or borrowed from Prototype, +// Oliver Steele's Functional, and John Resig's Micro-Templating. +// For all details and documentation: +// http://documentcloud.github.com/underscore +(function(){var p=this,C=p._,m={},i=Array.prototype,n=Object.prototype,f=i.slice,D=i.unshift,E=n.toString,l=n.hasOwnProperty,s=i.forEach,t=i.map,u=i.reduce,v=i.reduceRight,w=i.filter,x=i.every,y=i.some,o=i.indexOf,z=i.lastIndexOf;n=Array.isArray;var F=Object.keys,q=Function.prototype.bind,b=function(a){return new j(a)};typeof module!=="undefined"&&module.exports?(module.exports=b,b._=b):p._=b;b.VERSION="1.1.7";var h=b.each=b.forEach=function(a,c,b){if(a!=null)if(s&&a.forEach===s)a.forEach(c,b);else if(a.length=== ++a.length)for(var e=0,k=a.length;e