github.com/qubitproducts/logspray@v0.2.14/server/swagger-ui/src/main/javascript/view/Oauth2View.js (about) 1 'use strict'; 2 3 SwaggerUi.Views.Oauth2View = Backbone.View.extend({ 4 events: { 5 'change .oauth-scope': 'scopeChange', 6 'change .oauth-username': 'setUsername', 7 'change .oauth-password': 'setPassword', 8 'change .oauth-client-authentication-type': 'setClientAuthenticationType', 9 'change .oauth-client-id': 'setClientId', 10 'change .oauth-client-secret': 'setClientSecret' 11 }, 12 13 template: Handlebars.templates.oauth2, 14 15 cls: { 16 error: 'error' 17 }, 18 19 render: function () { 20 this.$el.html(this.template(this.model.toJSON())); 21 22 return this; 23 }, 24 25 scopeChange: function (e) { 26 var val = $(e.target).prop('checked'); 27 var scope = $(e.target).data('scope'); 28 29 this.model.setScopes(scope, val); 30 }, 31 32 setUsername: function (e) { 33 var val= $(e.target).val(); 34 this.model.set('username', val); 35 if (val) { 36 $(e.target).removeClass(this.cls.error); 37 } 38 }, 39 40 setPassword: function (e) { 41 this.model.set('password', $(e.target).val()); 42 }, 43 44 setClientAuthenticationType: function (e) { 45 var type = $(e.target).val(); 46 var $el = this.$el; 47 this.model.set('clientAuthenticationType', type); 48 49 switch(type) { 50 case 'none': 51 $el.find('.oauth-client-authentication').hide(); 52 break; 53 case 'basic': 54 case 'request-body': 55 $el.find('.oauth-client-id').removeClass(this.cls.error); 56 $el.find('.oauth-client-authentication').show(); 57 break; 58 } 59 }, 60 61 setClientId: function (e) { 62 var val = $(e.target).val(); 63 this.model.set('clientId', val); 64 if (val) { 65 $(e.target).removeClass(this.cls.error); 66 } 67 }, 68 69 setClientSecret: function (e) { 70 this.model.set('clientSecret', $(e.target).val()); 71 $(e.target).removeClass('error'); 72 }, 73 74 highlightInvalid: function () { 75 if (!this.model.get('username')) { 76 this.$el.find('.oauth-username').addClass(this.cls.error); 77 } 78 79 if (!this.model.get('clientId')) { 80 this.$el.find('.oauth-client-id').addClass(this.cls.error); 81 } 82 } 83 });