added some spine: view controllers
This commit is contained in:
@@ -1,4 +1,18 @@
|
||||
jQuery(function($) {
|
||||
|
||||
// The following heirarchy is followed by these view controllers
|
||||
// ResourceListController
|
||||
// >>> ResourceController
|
||||
// >>> ApiController
|
||||
// >>> OperationController
|
||||
|
||||
var ResourceListController = Spine.Controller.create({
|
||||
proxied: ["addAll", "addOne"],
|
||||
|
||||
ApiResource: null,
|
||||
|
||||
init: function() {
|
||||
|
||||
// create and initialize SwaggerService
|
||||
var hostUrl = "http://swagr.api.wordnik.com/v4";
|
||||
|
||||
@@ -7,55 +21,102 @@ jQuery(function($) {
|
||||
swaggerService.init();
|
||||
|
||||
// Create convenience references to Spine models
|
||||
var ApiResource = swaggerService.ApiResource();
|
||||
this.ApiResource = swaggerService.ApiResource();
|
||||
|
||||
// Register a callback for when apis are loaded
|
||||
ApiResource.bind("refresh", apisLoaded);
|
||||
this.ApiResource.bind("refresh", this.addAll);
|
||||
},
|
||||
|
||||
function apisLoaded() {
|
||||
for (var i = 0; i < ApiResource.all().length; i++) {
|
||||
var apiResource = ApiResource.all()[i];
|
||||
log("------------- apiResource : " + apiResource.name);
|
||||
addAll: function() {
|
||||
this.ApiResource.each(this.addOne);
|
||||
},
|
||||
|
||||
$("#resourceTemplate").tmpl(apiResource).appendTo("#resources");
|
||||
addOne: function(apiResource) {
|
||||
ResourceController.init({item: apiResource, container: "#resources"});
|
||||
}
|
||||
});
|
||||
|
||||
// apiResource.apiList.logAll();
|
||||
var resourceApisContainer = "#" + apiResource.name + "_endpoint_list";
|
||||
log("resourceApisContainer = " + resourceApisContainer);
|
||||
for (var j = 0; j < apiResource.apiList.all().length; j++) {
|
||||
var api = apiResource.apiList.all()[j];
|
||||
$("#apiTemplate").tmpl(api).appendTo(resourceApisContainer);
|
||||
renderOperations(api);
|
||||
var ResourceController = Spine.Controller.create({
|
||||
proxied: ["renderApi", "renderOperation"],
|
||||
|
||||
templateName: "#resourceTemplate",
|
||||
apiResource: null,
|
||||
apiList: null,
|
||||
modelList: null,
|
||||
|
||||
init: function() {
|
||||
this.render();
|
||||
|
||||
this.apiResource = this.item;
|
||||
this.apiList = this.apiResource.apiList;
|
||||
this.modelList = this.apiResource.modelList;
|
||||
|
||||
// log("------------- apiResource : " + this.apiResource.name);
|
||||
// this.apiList.logAll();
|
||||
// this.modelList.logAll();
|
||||
|
||||
this.apiList.each(this.renderApi);
|
||||
|
||||
},
|
||||
|
||||
render: function() {
|
||||
$(this.templateName).tmpl(this.item).appendTo(this.container);
|
||||
},
|
||||
|
||||
renderApi: function(api) {
|
||||
var resourceApisContainer = "#" + this.apiResource.name + "_endpoint_list";
|
||||
ApiController.init({item: api, container: resourceApisContainer});
|
||||
}
|
||||
|
||||
// apiResource.modelList.logAll();
|
||||
for (var k = 0; k < apiResource.modelList.all().length; k++) {
|
||||
var apiModel = apiResource.modelList.all()[k];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (window.console) console.log("apis loaded");
|
||||
}
|
||||
|
||||
function renderOperations(api) {
|
||||
if (api.operations && api.operations.count() > 0) {
|
||||
var operationsContainer = "#" + api.name + "_endpoint_" + api.id + "_operations";
|
||||
for (var o = 0; o < api.operations.all().length; o++) {
|
||||
var operation = api.operations.all()[o];
|
||||
$("#operationTemplate").tmpl(operation).appendTo(operationsContainer);
|
||||
renderParameters(operation, $);
|
||||
}
|
||||
}
|
||||
}
|
||||
var ApiController = Spine.Controller.create({
|
||||
proxied: ["renderOperation"],
|
||||
|
||||
function renderParameters(operation) {
|
||||
if(operation.parameters && operation.parameters.count() > 0) {
|
||||
var isGetOpetation = (operation.httpMethodLowercase == "get");
|
||||
api: null,
|
||||
templateName: "#apiTemplate",
|
||||
|
||||
var operationParamsContainer = "#" + operation.apiName + "_" + operation.nickname + "_" + operation.id + "_params";
|
||||
init: function() {
|
||||
this.render();
|
||||
|
||||
this.api = this.item;
|
||||
|
||||
this.api.operations.each(this.renderOperation);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
$(this.templateName).tmpl(this.item).appendTo(this.container);
|
||||
},
|
||||
|
||||
renderOperation: function(operation) {
|
||||
var operationsContainer = "#" + this.api.name + "_endpoint_" + this.api.id + "_operations";
|
||||
OperationController.init({item: operation, container: operationsContainer});
|
||||
}
|
||||
});
|
||||
|
||||
var OperationController = Spine.Controller.create({
|
||||
operation: null,
|
||||
templateName: "#operationTemplate",
|
||||
|
||||
init: function() {
|
||||
this.render();
|
||||
|
||||
this.operation = this.item;
|
||||
this.renderParams();
|
||||
},
|
||||
|
||||
render: function() {
|
||||
$(this.templateName).tmpl(this.item).appendTo(this.container);
|
||||
},
|
||||
|
||||
renderParams: function() {
|
||||
if (this.operation.parameters && this.operation.parameters.count() > 0) {
|
||||
var isGetOpetation = (this.operation.httpMethodLowercase == "get");
|
||||
|
||||
var operationParamsContainer = "#" + this.operation.apiName + "_" + this.operation.nickname + "_" + this.operation.id + "_params";
|
||||
log("operationParamsContainer = " + operationParamsContainer);
|
||||
for (var p = 0; p < operation.parameters.all().length; p++) {
|
||||
var param = operation.parameters.all()[p];
|
||||
for (var p = 0; p < this.operation.parameters.count(); p++) {
|
||||
var param = this.operation.parameters.all()[p];
|
||||
|
||||
var templateName = "#paramTemplate";
|
||||
if (param.required)
|
||||
@@ -65,12 +126,13 @@ jQuery(function($) {
|
||||
templateName += "ReadOnly";
|
||||
|
||||
$(templateName).tmpl(param).appendTo(operationParamsContainer);
|
||||
log("adding " + $(templateName).tmpl(param) + " TO " + operationParamsContainer);
|
||||
|
||||
if (!isGetOpetation) {
|
||||
var submitButtonId = "#" + operation.apiName + "_" + operation.nickname + "_" + operation.id + "_content_sandbox_response_button";
|
||||
var submitButtonId = "#" + this.operation.apiName + "_" + this.operation.nickname + "_" + this.operation.id + "_content_sandbox_response_button";
|
||||
$(submitButtonId).hide();
|
||||
|
||||
var valueHeader = "#" + operation.apiName + "_" + operation.nickname + "_" + operation.id + "_value_header";
|
||||
var valueHeader = "#" + this.operation.apiName + "_" + this.operation.nickname + "_" + this.operation.id + "_value_header";
|
||||
$(valueHeader).html("Default Value");
|
||||
|
||||
}
|
||||
@@ -79,6 +141,9 @@ jQuery(function($) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var resourceListController = ResourceListController.init();
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user