github.com/qubitproducts/logspray@v0.2.14/server/swagger-ui/src/main/javascript/view/AuthButtonView.js (about) 1 'use strict'; 2 3 SwaggerUi.Views.AuthButtonView = Backbone.View.extend({ 4 events: { 5 'click .authorize__btn': 'authorizeBtnClick' 6 }, 7 8 tpls: { 9 popup: Handlebars.templates.popup, 10 authBtn: Handlebars.templates.auth_button, 11 authBtnOperation: Handlebars.templates.auth_button_operation 12 }, 13 14 initialize: function(opts) { 15 this.options = opts || {}; 16 this.options.data = this.options.data || {}; 17 this.isOperation = this.options.isOperation; 18 this.model = this.model || {}; 19 this.router = this.options.router; 20 this.auths = this.options.data.oauth2.concat(this.options.data.auths); 21 }, 22 23 render: function () { 24 var tplName = this.isOperation ? 'authBtnOperation' : 'authBtn'; 25 26 this.$authEl = this.renderAuths(this.auths); 27 this.$el.html(this.tpls[tplName](this.model)); 28 29 return this; 30 }, 31 32 authorizeBtnClick: function (e) { 33 var authsModel; 34 35 e.preventDefault(); 36 37 authsModel = { 38 title: 'Available authorizations', 39 content: this.$authEl 40 }; 41 42 // The content of the popup is removed and all events unbound after clicking the 'Cancel' button of the popup. 43 // We'll have to re-render the contents before creating a new popup view. 44 this.render(); 45 46 this.popup = new SwaggerUi.Views.PopupView({model: authsModel}); 47 this.popup.render(); 48 }, 49 50 renderAuths: function (auths) { 51 var $el = $('<div>'); 52 var isLogout = false; 53 54 auths.forEach(function (auth) { 55 var authView = new SwaggerUi.Views.AuthView({data: auth, router: this.router}); 56 var authEl = authView.render().el; 57 $el.append(authEl); 58 if (authView.isLogout) { 59 isLogout = true; 60 } 61 }, this); 62 63 this.model.isLogout = isLogout; 64 65 return $el; 66 } 67 68 });