github.com/qubitproducts/logspray@v0.2.14/server/swagger-ui/src/main/javascript/view/ResourceView.js (about) 1 'use strict'; 2 3 SwaggerUi.Views.ResourceView = Backbone.View.extend({ 4 initialize: function(opts) { 5 opts = opts || {}; 6 this.router = opts.router; 7 this.auths = opts.auths; 8 if ('' === this.model.description) { 9 this.model.description = null; 10 } 11 if (this.model.description) { 12 this.model.summary = this.model.description; 13 } 14 this.number = 0; 15 }, 16 17 render: function(){ 18 var methods = {}; 19 20 21 $(this.el).html(Handlebars.templates.resource(this.model)); 22 23 // Render each operation 24 for (var i = 0; i < this.model.operationsArray.length; i++) { 25 var operation = this.model.operationsArray[i]; 26 var counter = 0; 27 var id = operation.nickname; 28 29 while (typeof methods[id] !== 'undefined') { 30 id = id + '_' + counter; 31 counter += 1; 32 } 33 34 methods[id] = operation; 35 36 operation.nickname = id; 37 operation.parentId = this.model.id; 38 operation.definitions = this.model.definitions; // make Json Schema available for JSonEditor in this operation 39 this.addOperation(operation); 40 } 41 42 $('.toggleEndpointList', this.el).click(this.callDocs.bind(this, 'toggleEndpointListForResource')); 43 $('.collapseResource', this.el).click(this.callDocs.bind(this, 'collapseOperationsForResource')); 44 $('.expandResource', this.el).click(this.callDocs.bind(this, 'expandOperationsForResource')); 45 46 return this; 47 }, 48 49 addOperation: function(operation) { 50 51 operation.number = this.number; 52 53 // Render an operation and add it to operations li 54 var operationView = new SwaggerUi.Views.OperationView({ 55 model: $.extend(true,{},operation), 56 router: this.router, 57 tagName: 'li', 58 className: 'endpoint', 59 swaggerOptions: this.options.swaggerOptions, 60 auths: this.auths 61 }); 62 63 $('.endpoints', $(this.el)).append(operationView.render().el); 64 65 this.number++; 66 67 }, 68 // Generic Event handler (`Docs` is global) 69 70 71 callDocs: function(fnName, e) { 72 e.preventDefault(); 73 Docs[fnName](e.currentTarget.getAttribute('data-id')); 74 } 75 });