\n\n
\n
\n ";
if (stack1 = helpers.signature) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.signature; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n
\n\n
\n
";
if (stack1 = helpers.sampleJSON) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.sampleJSON; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ "
\n
\n
\n
\n\n";
return buffer;
});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['status_code'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;
buffer += "
";
if (stack1 = helpers.code) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.code; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ " | \n
";
if (stack1 = helpers.reason) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.reason; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += " | \n\n";
return buffer;
});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['param_readonly'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
function program1(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n ";
return buffer;
}
function program3(depth0,data) {
var buffer = "", stack1;
buffer += "\n ";
if (stack1 = helpers.defaultValue) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.defaultValue; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ "\n ";
return buffer;
}
buffer += "
";
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ " | \n
\n ";
stack1 = helpers['if'].call(depth0, depth0.isBody, {hash:{},inverse:self.program(3, program3, data),fn:self.program(1, program1, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n | \n
";
if (stack1 = helpers.description) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.description; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += " | \n
| \n";
return buffer;
});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['content_type'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, functionType="function", self=this;
function program1(depth0,data) {
var buffer = "", stack1;
buffer += "\n ";
stack1 = helpers.each.call(depth0, depth0.produces, {hash:{},inverse:self.noop,fn:self.program(2, program2, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n";
return buffer;
}
function program2(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n ";
return buffer;
}
function program4(depth0,data) {
return "\n
\n";
}
buffer += "
\n
\n";
return buffer;
});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['resource'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;
buffer += "
\n
\n";
return buffer;
});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['operation'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
function program1(depth0,data) {
var buffer = "", stack1;
buffer += "\n
Implementation Notes hide
\n
\n
";
if (stack1 = helpers.notes) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.notes; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "
\n
\n ";
return buffer;
}
function program3(depth0,data) {
var buffer = "", stack1;
buffer += "\n
Examples hide
\n
\n
";
if (stack1 = helpers.examples) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.examples; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "
\n
\n ";
return buffer;
}
function program5(depth0,data) {
return "\n
Response Class
\n
\n
\n
\n ";
}
function program7(depth0,data) {
return "\n
Parameters
\n
\n \n \n Parameter | \n Value | \n Description | \n Data Type | \n
\n \n \n\n \n
\n ";
}
function program9(depth0,data) {
return "\n
\n
Status Codes
\n
\n \n \n HTTP Status Code | \n Reason | \n
\n \n \n \n \n
\n ";
}
function program11(depth0,data) {
return "\n ";
}
function program13(depth0,data) {
return "\n
\n ";
}
buffer += "\n
\n - \n \n
\n ";
stack1 = helpers['if'].call(depth0, depth0.notes, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.examples, {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.responseClass, {hash:{},inverse:self.noop,fn:self.program(5, program5, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n
\n
\n
Request URL
\n
\n
Response Body
\n
\n
Response Code
\n
\n
Response Headers
\n \n
\n
\n \n
\n";
return buffer;
});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['param_list'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, stack2, self=this, functionType="function", escapeExpression=this.escapeExpression;
function program1(depth0,data) {
return "\n ";
}
function program3(depth0,data) {
var buffer = "", stack1;
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.defaultValue, {hash:{},inverse:self.program(6, program6, data),fn:self.program(4, program4, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
return buffer;
}
function program4(depth0,data) {
return "\n ";
}
function program6(depth0,data) {
return "\n
\n ";
}
function program8(depth0,data) {
var buffer = "", stack1;
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.isDefault, {hash:{},inverse:self.program(11, program11, data),fn:self.program(9, program9, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
return buffer;
}
function program9(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n ";
return buffer;
}
function program11(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n ";
return buffer;
}
buffer += "
";
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ " | \n
\n \n | \n
";
if (stack2 = helpers.description) { stack2 = stack2.call(depth0, {hash:{},data:data}); }
else { stack2 = depth0.description; stack2 = typeof stack2 === functionType ? stack2.apply(depth0) : stack2; }
if(stack2 || stack2 === 0) { buffer += stack2; }
buffer += " | \n
| \n";
return buffer;
});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['param'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
function program1(depth0,data) {
var buffer = "", stack1;
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.isFile, {hash:{},inverse:self.program(4, program4, data),fn:self.program(2, program2, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
return buffer;
}
function program2(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n ";
return buffer;
}
function program4(depth0,data) {
var buffer = "", stack1;
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.defaultValue, {hash:{},inverse:self.program(7, program7, data),fn:self.program(5, program5, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
return buffer;
}
function program5(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n ";
return buffer;
}
function program7(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n
\n
\n ";
return buffer;
}
function program9(depth0,data) {
var buffer = "", stack1;
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.defaultValue, {hash:{},inverse:self.program(12, program12, data),fn:self.program(10, program10, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
return buffer;
}
function program10(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n ";
return buffer;
}
function program12(depth0,data) {
var buffer = "", stack1;
buffer += "\n
\n ";
return buffer;
}
buffer += "
";
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ " | \n
\n\n ";
stack1 = helpers['if'].call(depth0, depth0.isBody, {hash:{},inverse:self.program(9, program9, data),fn:self.program(1, program1, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n\n | \n
";
if (stack1 = helpers.description) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.description; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += " | \n
\n \n | \n\n";
return buffer;
});
})();
//@ sourceMappingURL=_swagger-ui.map
// Generated by CoffeeScript 1.6.1
(function() {
var ContentTypeView, HeaderView, MainView, OperationView, ParameterView, ResourceView, SignatureView, StatusCodeView, SwaggerUi,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
SwaggerUi = (function(_super) {
__extends(SwaggerUi, _super);
function SwaggerUi() {
return SwaggerUi.__super__.constructor.apply(this, arguments);
}
SwaggerUi.prototype.dom_id = "swagger_ui";
SwaggerUi.prototype.options = null;
SwaggerUi.prototype.api = null;
SwaggerUi.prototype.headerView = null;
SwaggerUi.prototype.mainView = null;
SwaggerUi.prototype.initialize = function(options) {
var _this = this;
if (options == null) {
options = {};
}
if (options.dom_id != null) {
this.dom_id = options.dom_id;
delete options.dom_id;
}
if ($('#' + this.dom_id) == null) {
$('body').append('
');
}
this.options = options;
this.options.success = function() {
return _this.render();
};
this.options.progress = function(d) {
return _this.showMessage(d);
};
this.options.failure = function(d) {
return _this.onLoadFailure(d);
};
this.headerView = new HeaderView({
el: $('#header')
});
return this.headerView.on('update-swagger-ui', function(data) {
return _this.updateSwaggerUi(data);
});
};
SwaggerUi.prototype.updateSwaggerUi = function(data) {
this.options.discoveryUrl = data.discoveryUrl;
this.options.apiKey = data.apiKey;
return this.load();
};
SwaggerUi.prototype.load = function() {
var _ref;
if ((_ref = this.mainView) != null) {
_ref.clear();
}
this.headerView.update(this.options.discoveryUrl, this.options.apiKey);
return this.api = new SwaggerApi(this.options);
};
SwaggerUi.prototype.render = function() {
var _this = this;
this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...');
this.mainView = new MainView({
model: this.api,
el: $('#' + this.dom_id)
}).render();
this.showMessage();
switch (this.options.docExpansion) {
case "full":
Docs.expandOperationsForResource('');
break;
case "list":
Docs.collapseOperationsForResource('');
}
if (this.options.onComplete) {
this.options.onComplete(this.api, this);
}
return setTimeout(function() {
return Docs.shebang();
}, 400);
};
SwaggerUi.prototype.showMessage = function(data) {
if (data == null) {
data = '';
}
$('#message-bar').removeClass('message-fail');
$('#message-bar').addClass('message-success');
return $('#message-bar').html(data);
};
SwaggerUi.prototype.onLoadFailure = function(data) {
var val;
if (data == null) {
data = '';
}
$('#message-bar').removeClass('message-success');
$('#message-bar').addClass('message-fail');
val = $('#message-bar').html(data);
if (this.options.onFailure != null) {
this.options.onFailure(data);
}
return val;
};
return SwaggerUi;
})(Backbone.Router);
window.SwaggerUi = SwaggerUi;
HeaderView = (function(_super) {
__extends(HeaderView, _super);
function HeaderView() {
return HeaderView.__super__.constructor.apply(this, arguments);
}
HeaderView.prototype.events = {
'click #show-pet-store-icon': 'showPetStore',
'click #show-wordnik-dev-icon': 'showWordnikDev',
'click #explore': 'showCustom',
'keyup #input_baseUrl': 'showCustomOnKeyup',
'keyup #input_apiKey': 'showCustomOnKeyup'
};
HeaderView.prototype.initialize = function() {};
HeaderView.prototype.showPetStore = function(e) {
return this.trigger('update-swagger-ui', {
discoveryUrl: "http://petstore.swagger.wordnik.com/api/api-docs.json",
apiKey: "special-key"
});
};
HeaderView.prototype.showWordnikDev = function(e) {
return this.trigger('update-swagger-ui', {
discoveryUrl: "http://api.wordnik.com/v4/resources.json",
apiKey: ""
});
};
HeaderView.prototype.showCustomOnKeyup = function(e) {
if (e.keyCode === 13) {
return this.showCustom();
}
};
HeaderView.prototype.showCustom = function(e) {
if (e != null) {
e.preventDefault();
}
return this.trigger('update-swagger-ui', {
discoveryUrl: $('#input_baseUrl').val(),
apiKey: $('#input_apiKey').val()
});
};
HeaderView.prototype.update = function(url, apiKey, trigger) {
if (trigger == null) {
trigger = false;
}
$('#input_baseUrl').val(url);
$('#input_apiKey').val(apiKey);
if (trigger) {
return this.trigger('update-swagger-ui', {
discoveryUrl: url,
apiKey: apiKey
});
}
};
return HeaderView;
})(Backbone.View);
MainView = (function(_super) {
__extends(MainView, _super);
function MainView() {
return MainView.__super__.constructor.apply(this, arguments);
}
MainView.prototype.initialize = function() {};
MainView.prototype.render = function() {
var resource, _i, _len, _ref;
$(this.el).html(Handlebars.templates.main(this.model));
_ref = this.model.apisArray;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
resource = _ref[_i];
this.addResource(resource);
}
return this;
};
MainView.prototype.addResource = function(resource) {
var resourceView;
resourceView = new ResourceView({
model: resource,
tagName: 'li',
id: 'resource_' + resource.name,
className: 'resource'
});
return $('#resources').append(resourceView.render().el);
};
MainView.prototype.clear = function() {
return $(this.el).html('');
};
return MainView;
})(Backbone.View);
ResourceView = (function(_super) {
__extends(ResourceView, _super);
function ResourceView() {
return ResourceView.__super__.constructor.apply(this, arguments);
}
ResourceView.prototype.initialize = function() {};
ResourceView.prototype.render = function() {
var operation, _i, _len, _ref;
$(this.el).html(Handlebars.templates.resource(this.model));
this.number = 0;
_ref = this.model.operationsArray;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
operation = _ref[_i];
this.addOperation(operation);
}
return this;
};
ResourceView.prototype.addOperation = function(operation) {
var operationView;
operation.number = this.number;
operationView = new OperationView({
model: operation,
tagName: 'li',
className: 'endpoint'
});
$('.endpoints', $(this.el)).append(operationView.render().el);
return this.number++;
};
return ResourceView;
})(Backbone.View);
OperationView = (function(_super) {
__extends(OperationView, _super);
function OperationView() {
return OperationView.__super__.constructor.apply(this, arguments);
}
OperationView.prototype.events = {
'submit .sandbox': 'submitOperation',
'click .submit': 'submitOperation',
'click .response_hider': 'hideResponse',
'click .hider': 'toggleText',
'click .toggleOperation': 'toggleOperationContent'
};
OperationView.prototype.initialize = function() {};
OperationView.prototype.render = function() {
var contentTypeModel, contentTypeView, isMethodSubmissionSupported, param, responseSignatureView, signatureModel, statusCode, _i, _j, _len, _len1, _ref, _ref1;
isMethodSubmissionSupported = jQuery.inArray(this.model.httpMethod, this.model.supportedSubmitMethods()) >= 0;
if (!isMethodSubmissionSupported) {
this.model.isReadOnly = true;
}
$(this.el).html(Handlebars.templates.operation(this.model));
if (this.model.responseClassSignature && this.model.responseClassSignature !== 'string') {
signatureModel = {
sampleJSON: this.model.responseSampleJSON,
isParam: false,
signature: this.model.responseClassSignature
};
responseSignatureView = new SignatureView({
model: signatureModel,
tagName: 'div'
});
$('.model-signature', $(this.el)).append(responseSignatureView.render().el);
} else {
$('.model-signature', $(this.el)).html(this.model.responseClass);
}
contentTypeModel = {
isParam: false
};
if (this.model.supportedContentTypes) {
contentTypeModel.produces = this.model.supportedContentTypes;
}
if (this.model.produces) {
contentTypeModel.produces = this.model.produces;
}
contentTypeView = new ContentTypeView({
model: contentTypeModel
});
$('.content-type', $(this.el)).append(contentTypeView.render().el);
_ref = this.model.parameters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i];
this.addParameter(param);
}
_ref1 = this.model.errorResponses;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
statusCode = _ref1[_j];
this.addStatusCode(statusCode);
}
return this;
};
OperationView.prototype.addParameter = function(param) {
var paramView;
paramView = new ParameterView({
model: param,
tagName: 'tr',
readOnly: this.model.isReadOnly
});
return $('.operation-params', $(this.el)).append(paramView.render().el);
};
OperationView.prototype.addStatusCode = function(statusCode) {
var statusCodeView;
statusCodeView = new StatusCodeView({
model: statusCode,
tagName: 'tr'
});
return $('.operation-status', $(this.el)).append(statusCodeView.render().el);
};
OperationView.prototype.submitOperation = function(e) {
var bodyParam, consumes, error_free, form, headerParams, invocationUrl, isFileUpload, isFormPost, map, o, obj, param, paramContentTypeField, responseContentTypeField, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4,
_this = this;
if (e != null) {
e.preventDefault();
}
form = $('.sandbox', $(this.el));
error_free = true;
form.find("input.required").each(function() {
var _this = this;
$(this).removeClass("error");
if (jQuery.trim($(this).val()) === "") {
$(this).addClass("error");
$(this).wiggle({
callback: function() {
return $(_this).focus();
}
});
return error_free = false;
}
});
if (error_free) {
map = {};
_ref = form.serializeArray();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
o = _ref[_i];
if ((o.value != null) && jQuery.trim(o.value).length > 0) {
map[o.name] = o.value;
}
}
isFileUpload = form.children().find('input[type~="file"]').size() !== 0;
isFormPost = false;
consumes = "application/json";
if (this.model.consumes && this.model.consumes.length > 0) {
consumes = this.model.consumes[0];
} else {
_ref1 = this.model.parameters;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
o = _ref1[_j];
if (o.paramType === 'form') {
isFormPost = true;
consumes = false;
}
}
if (isFileUpload) {
consumes = false;
} else if (this.model.httpMethod.toLowerCase() === "post" && isFormPost === false) {
consumes = "application/json";
}
}
if (isFileUpload) {
bodyParam = new FormData();
_ref2 = this.model.parameters;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
param = _ref2[_k];
if (param.paramType === 'body' && param.name !== 'file') {
bodyParam.append(param.name, map[param.name]);
}
}
$.each(form.children().find('input[type~="file"]'), function(i, el) {
return bodyParam.append($(el).attr('name'), el.files[0]);
});
console.log(bodyParam);
} else if (isFormPost) {
bodyParam = new FormData();
_ref3 = this.model.parameters;
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
param = _ref3[_l];
bodyParam.append(param.name, map[param.name]);
}
} else {
bodyParam = null;
_ref4 = this.model.parameters;
for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {
param = _ref4[_m];
if (param.paramType === 'body') {
bodyParam = map[param.name];
}
}
}
log("bodyParam = " + bodyParam);
headerParams = null;
invocationUrl = this.model.supportHeaderParams() ? (headerParams = this.model.getHeaderParams(map), this.model.urlify(map, false)) : this.model.urlify(map, true);
log('submitting ' + invocationUrl);
$(".request_url", $(this.el)).html("
" + invocationUrl + "
");
$(".response_throbber", $(this.el)).show();
obj = {
type: this.model.httpMethod,
url: invocationUrl,
headers: headerParams,
data: bodyParam,
contentType: consumes,
dataType: 'json',
processData: false,
error: function(xhr, textStatus, error) {
return _this.showErrorStatus(xhr, textStatus, error);
},
success: function(data) {
return _this.showResponse(data);
},
complete: function(data) {
return _this.showCompleteStatus(data);
}
};
paramContentTypeField = $("td select[name=contentType]", $(this.el)).val();
if (paramContentTypeField) {
obj.contentType = paramContentTypeField;
}
responseContentTypeField = $('.content > .content-type > div > select[name=contentType]', $(this.el)).val();
if (responseContentTypeField) {
obj.headers = obj.headers != null ? obj.headers : {};
obj.headers.accept = responseContentTypeField;
}
jQuery.ajax(obj);
return false;
}
};
OperationView.prototype.hideResponse = function(e) {
if (e != null) {
e.preventDefault();
}
$(".response", $(this.el)).slideUp();
return $(".response_hider", $(this.el)).fadeOut();
};
OperationView.prototype.toggleText = function(e) {
var myel;
if (e != null) {
e.preventDefault();
}
myel = this.$(e.target);
if (myel.html() === 'show') {
myel.html('hide');
} else {
myel.html('show');
}
return myel.parent().next('div').slideToggle();
};
OperationView.prototype.showResponse = function(response) {
var prettyJson;
prettyJson = JSON.stringify(response, null, "\t").replace(/\n/g, "
");
return $(".response_body", $(this.el)).html(escape(prettyJson));
};
OperationView.prototype.showErrorStatus = function(data) {
return this.showStatus(data);
};
OperationView.prototype.showCompleteStatus = function(data) {
return this.showStatus(data);
};
OperationView.prototype.formatXml = function(xml) {
var contexp, formatted, indent, lastType, lines, ln, pad, reg, transitions, wsexp, _fn, _i, _len;
reg = /(>)(<)(\/*)/g;
wsexp = /[ ]*(.*)[ ]+\n/g;
contexp = /(<.+>)(.+\n)/g;
xml = xml.replace(reg, '$1\n$2$3').replace(wsexp, '$1\n').replace(contexp, '$1\n$2');
pad = 0;
formatted = '';
lines = xml.split('\n');
indent = 0;
lastType = 'other';
transitions = {
'single->single': 0,
'single->closing': -1,
'single->opening': 0,
'single->other': 0,
'closing->single': 0,
'closing->closing': -1,
'closing->opening': 0,
'closing->other': 0,
'opening->single': 1,
'opening->closing': 0,
'opening->opening': 1,
'opening->other': 1,
'other->single': 0,
'other->closing': -1,
'other->opening': 0,
'other->other': 0
};
_fn = function(ln) {
var fromTo, j, key, padding, type, types, value;
types = {
single: Boolean(ln.match(/<.+\/>/)),
closing: Boolean(ln.match(/<\/.+>/)),
opening: Boolean(ln.match(/<[^!?].*>/))
};
type = ((function() {
var _results;
_results = [];
for (key in types) {
value = types[key];
if (value) {
_results.push(key);
}
}
return _results;
})())[0];
type = type === void 0 ? 'other' : type;
fromTo = lastType + '->' + type;
lastType = type;
padding = '';
indent += transitions[fromTo];
padding = ((function() {
var _j, _ref, _results;
_results = [];
for (j = _j = 0, _ref = indent; 0 <= _ref ? _j < _ref : _j > _ref; j = 0 <= _ref ? ++_j : --_j) {
_results.push(' ');
}
return _results;
})()).join('');
if (fromTo === 'opening->closing') {
return formatted = formatted.substr(0, formatted.length - 1) + ln + '\n';
} else {
return formatted += padding + ln + '\n';
}
};
for (_i = 0, _len = lines.length; _i < _len; _i++) {
ln = lines[_i];
_fn(ln);
}
return formatted;
};
OperationView.prototype.showStatus = function(data) {
var code, pre, response_body;
try {
code = $('
').text(JSON.stringify(JSON.parse(data.responseText), null, 2));
pre = $('
').append(code);
} catch (error) {
code = $('
').text(this.formatXml(data.responseText));
pre = $('
').append(code);
}
response_body = pre;
$(".response_code", $(this.el)).html("
" + data.status + "
");
$(".response_body", $(this.el)).html(response_body);
$(".response_headers", $(this.el)).html("
" + data.getAllResponseHeaders() + "
");
$(".response", $(this.el)).slideDown();
$(".response_hider", $(this.el)).show();
$(".response_throbber", $(this.el)).hide();
return hljs.highlightBlock($('.response_body', $(this.el))[0]);
};
OperationView.prototype.toggleOperationContent = function() {
var elem;
elem = $('#' + Docs.escapeResourceName(this.model.resourceName) + "_" + this.model.nickname + "_" + this.model.httpMethod + "_" + this.model.number + "_content");
if (elem.is(':visible')) {
return Docs.collapseOperation(elem);
} else {
return Docs.expandOperation(elem);
}
};
return OperationView;
})(Backbone.View);
StatusCodeView = (function(_super) {
__extends(StatusCodeView, _super);
function StatusCodeView() {
return StatusCodeView.__super__.constructor.apply(this, arguments);
}
StatusCodeView.prototype.initialize = function() {};
StatusCodeView.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
return this;
};
StatusCodeView.prototype.template = function() {
return Handlebars.templates.status_code;
};
return StatusCodeView;
})(Backbone.View);
ParameterView = (function(_super) {
__extends(ParameterView, _super);
function ParameterView() {
return ParameterView.__super__.constructor.apply(this, arguments);
}
ParameterView.prototype.initialize = function() {};
ParameterView.prototype.render = function() {
var contentTypeModel, contentTypeView, signatureModel, signatureView, template;
if (this.model.paramType === 'body') {
this.model.isBody = true;
}
if (this.model.dataType === 'file') {
this.model.isFile = true;
}
template = this.template();
$(this.el).html(template(this.model));
signatureModel = {
sampleJSON: this.model.sampleJSON,
isParam: true,
signature: this.model.signature
};
if (this.model.sampleJSON) {
signatureView = new SignatureView({
model: signatureModel,
tagName: 'div'
});
$('.model-signature', $(this.el)).append(signatureView.render().el);
} else {
$('.model-signature', $(this.el)).html(this.model.signature);
}
contentTypeModel = {
isParam: false
};
if (this.model.supportedContentTypes) {
contentTypeModel.produces = this.model.supportedContentTypes;
}
if (this.model.produces) {
contentTypeModel.produces = this.model.produces;
}
contentTypeView = new ContentTypeView({
model: contentTypeModel
});
$('.content-type', $(this.el)).append(contentTypeView.render().el);
return this;
};
ParameterView.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 ParameterView;
})(Backbone.View);
SignatureView = (function(_super) {
__extends(SignatureView, _super);
function SignatureView() {
return SignatureView.__super__.constructor.apply(this, arguments);
}
SignatureView.prototype.events = {
'click a.description-link': 'switchToDescription',
'click a.snippet-link': 'switchToSnippet',
'mousedown .snippet': 'snippetToTextArea'
};
SignatureView.prototype.initialize = function() {};
SignatureView.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
this.switchToDescription();
this.isParam = this.model.isParam;
if (this.isParam) {
$('.notice', $(this.el)).text('Click to set as parameter value');
}
return this;
};
SignatureView.prototype.template = function() {
return Handlebars.templates.signature;
};
SignatureView.prototype.switchToDescription = function(e) {
if (e != null) {
e.preventDefault();
}
$(".snippet", $(this.el)).hide();
$(".description", $(this.el)).show();
$('.description-link', $(this.el)).addClass('selected');
return $('.snippet-link', $(this.el)).removeClass('selected');
};
SignatureView.prototype.switchToSnippet = function(e) {
if (e != null) {
e.preventDefault();
}
$(".description", $(this.el)).hide();
$(".snippet", $(this.el)).show();
$('.snippet-link', $(this.el)).addClass('selected');
return $('.description-link', $(this.el)).removeClass('selected');
};
SignatureView.prototype.snippetToTextArea = function(e) {
var textArea;
if (this.isParam) {
if (e != null) {
e.preventDefault();
}
textArea = $('textarea', $(this.el.parentNode.parentNode.parentNode));
if ($.trim(textArea.val()) === '') {
return textArea.val(this.model.sampleJSON);
}
}
};
return SignatureView;
})(Backbone.View);
ContentTypeView = (function(_super) {
__extends(ContentTypeView, _super);
function ContentTypeView() {
return ContentTypeView.__super__.constructor.apply(this, arguments);
}
ContentTypeView.prototype.initialize = function() {};
ContentTypeView.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
this.isParam = this.model.isParam;
if (this.isParam) {
$('label[for=contentType]', $(this.el)).text('Parameter content type:');
} else {
$('label[for=contentType]', $(this.el)).text('Response Content Type');
}
return this;
};
ContentTypeView.prototype.template = function() {
return Handlebars.templates.content_type;
};
return ContentTypeView;
})(Backbone.View);
}).call(this);